forum.alglib.net

ALGLIB forum
It is currently Mon Dec 23, 2024 6:52 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Solver A*X = B with all numbers in the array X is positive
PostPosted: Wed Oct 03, 2012 4:52 am 
Offline

Joined: Wed Oct 03, 2012 4:35 am
Posts: 5
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!


Top
 Profile  
 
 Post subject: Re: Solver A*X = B with all numbers in the array X is positi
PostPosted: Wed Oct 03, 2012 7:16 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
 Post subject: Re: Solver A*X = B with all numbers in the array X is positi
PostPosted: Wed Oct 03, 2012 7:40 am 
Offline

Joined: Wed Oct 03, 2012 4:35 am
Posts: 5
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


Top
 Profile  
 
 Post subject: Re: Solver A*X = B with all numbers in the array X is positi
PostPosted: Wed Oct 03, 2012 10:45 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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


Top
 Profile  
 
 Post subject: Re: Solver A*x = b with all numbers in the array x non-negat
PostPosted: Fri Oct 05, 2012 5:04 am 
Offline

Joined: Wed Oct 03, 2012 4:35 am
Posts: 5
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


Top
 Profile  
 
 Post subject: Re: Solver A*X = B with all numbers in the array X is positi
PostPosted: Thu Nov 15, 2012 7:37 am 
Offline

Joined: Wed Oct 03, 2012 4:35 am
Posts: 5
Sergey.Bochkanov, Help me!


Top
 Profile  
 
 Post subject: Re: Solver A*X = B with all numbers in the array X is positi
PostPosted: Thu Nov 29, 2012 6:15 am 
Offline

Joined: Wed Oct 03, 2012 4:35 am
Posts: 5
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group