forum.alglib.net http://forum.alglib.net/ |
|
Solver A*X = B with all numbers in the array X is positive http://forum.alglib.net/viewtopic.php?f=2&t=621 |
Page 1 of 1 |
Author: | lhha98 [ Wed Oct 03, 2012 4:52 am ] |
Post subject: | Solver A*X = B with all numbers in the array X is positive |
Hi everyone! Can anyone help me? I need to solve a problem of mixing chemicals, I use the following function to solve my problem public static void rmatrixsolvels (double [,] a,int nRows,int nCols,double [] b,double threshold,ref int info,densesolverlsreport rep, ref double [] x) But when I get results returned is array X, there are negative numbers in array X, this is not fair. I want the numbers in the array X are positive numbers. Does anyone have any ideas to help me? Thank you! |
Author: | Sergey.Bochkanov [ Wed Oct 03, 2012 7:16 am ] |
Post subject: | Re: Solver A*X = B with all numbers in the array X is positi |
You can use bound-constrained version of the LSFit for this purpose. Unfortunately, current version of the ALGLIB does not include non-negative linear least squares solver - only nonlinear one is present for the moment. |
Author: | lhha98 [ Wed Oct 03, 2012 7:40 am ] |
Post subject: | Re: Solver A*X = B with all numbers in the array X is positi |
Sergey.Bochkanov wrote: You can use bound-constrained version of the LSFit for this purpose. Unfortunately, current version of the ALGLIB does not include non-negative linear least squares solver - only nonlinear one is present for the moment. Please explain more clearly for me, I do not understand |
Author: | Sergey.Bochkanov [ Wed Oct 03, 2012 10:45 am ] |
Post subject: | Re: Solver A*X = B with all numbers in the array X is positi |
OK :) First, I've made small mistake - you should use MinLM optimizer instead of LSFit. Levenberg-Marquardt optimizer solves optimization problem of the form F(x1...xm) = f1^2(x1...xm)+...+fn^2(x1...xm). LM-optimizer can solve nonlinear problems with boundary constraints, nonnegativity constraints are just one particular case of boundary constraints. Linear problems can be solved too - they are easy special case of nonlinear problems. You can reformulate your problem from A*x=b as follows. One row of A corresponds to one of f-functions: f_i = a[i,1]*x[1] + ... + a[i,m]*x[m] - b_i. It allows you to use powerful solver with support for boundary constraints. It is slower than linear solver, but good enough for problems with dimensions up to several hundreds. Linear problem |
Author: | lhha98 [ Fri Oct 05, 2012 5:04 am ] |
Post subject: | Re: Solver A*x = b with all numbers in the array x non-negat |
Hi Sergey.Bochkanov! I fought try MinLM optimizer but still can not find a solution, Sergey.Bochkanov again you try to help me more thorough. Here is my problem: the problem of mixed pig feed. For example: To phase 300 kg of diet substances protit 19%, glucit 5%, Lysine 1%. Rate (%) by weight of the feed material in the A, B, C as follows: A: 36.3% protit; 3.4% glucit; 1.32% Lysine; B: 53.55% protit; 0.89% glucit; 3.7% Lysine C: 11.9% protit; 8.1% glucit; 0.56% Lysine Requirement: Determine the volume of feed materials of class A, B, C for the preparation of 300 kg of feed mixture as above Solution Called a, b, c is the volume of feed materials A, B, C have the following model problem: a + b + c = 300 (36.3 a + 53.55 b + 11.9 c) / 300 = 19 (3.4 a + 0.89 b + 8.1 c) / 300 = 5 (1.32 a + 3.7 b + 0.56c) / 300 = 1 a> 0; b> 0, c> 0 Here is a computer program (already shortened): Double [] matrixB = {300, 19, 5, 1} double [,] matrixA ={ {1, 1, 1} {0.121, 0.1785, 0.0396} {0.0113, 0.0029, 0.027} {0.0044, 0.0123, 0.0018}} int info = 0; Double [] matrixX; alglib.densesolverlsreport repls = new alglib.densesolverlsreport (); alglib.rmatrixsolvels (matrixA, 4, 3, matrixB, 0.001 out info, out repls, out matrixX); Results: matrixX = {213.90, -71. 965, 158.005} Inferred: a = 213.909 kg; b = -71.965 kg; c = 158.005 kg b = - 71.965 is a number that is not desired, I want all the numbers a, b, c are non-negative numbers, such as the results I would like for the above example would is matrixX = {72, 70, 158.02} or MatrixX = {197.45, 0.00, 173.54} (LINGO SOLVER) I've tried LSFit which Sergey.Bochkanov introduced but the results remained unchanged, while MinLM optimiser, installation or call the function like I did not do it. my IT are bad and my math are bad and my English too! Very desire Sergey.Bochkanov help me to solve this problem in a clear way, so I can just copy and past and the program can run well Thank Sergey.Bochkanov! Le Huu Ha |
Author: | lhha98 [ Thu Nov 15, 2012 7:37 am ] |
Post subject: | Re: Solver A*X = B with all numbers in the array X is positi |
Sergey.Bochkanov, Help me! |
Author: | lhha98 [ Thu Nov 29, 2012 6:15 am ] |
Post subject: | Re: Solver A*X = B with all numbers in the array X is positi |
Sergey.Bochkanov wrote: OK :) First, I've made small mistake - you should use MinLM optimizer instead of LSFit. Levenberg-Marquardt optimizer solves optimization problem of the form F(x1...xm) = f1^2(x1...xm)+...+fn^2(x1...xm). LM-optimizer can solve nonlinear problems with boundary constraints, nonnegativity constraints are just one particular case of boundary constraints. Linear problems can be solved too - they are easy special case of nonlinear problems. You can reformulate your problem from A*x=b as follows. One row of A corresponds to one of f-functions: f_i = a[i,1]*x[1] + ... + a[i,m]*x[m] - b_i. It allows you to use powerful solver with support for boundary constraints. It is slower than linear solver, but good enough for problems with dimensions up to several hundreds. Linear problem Thank you Sergey.Bochkanov, I have solved problem by MinLM optimizer |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |