Clear Filters
Clear Filters

Solving large overdetermined system of equations

10 views (last 30 days)
I am trying to solve an overdetermenind system of equations (45 equations with 18 unknowns) in the form of A*X = B; where: A = [8.19 0.3; 12.39 0.86; 16.15 1.68; 17.7 2.16; 24.6 8.33]; A is 5 rows, 2 columns
B = [0.85 3.8 0.225 0.175 0.05 0.05 0 1.919 0.165; 1.5 6.825 0.45 0.4 0.175 0.125 0.025 2.907 0.315; 3 7.625 0.9 1.05 0.475 0.225 0.1 3.823 0.544; 3.05 7.9 1.1 1.8 1.225 0.25 0.45 4.153 0.881; 5.1 12.95 1.975 3.65 3.075 0.25 1.075 4.045 1.217]; B is 5 rows, 9 columns
X = [a1 b1 c1 d1 e1 f1 g1 h1 i1;a2 b2 c2 d2 e2 f2 g2 h2 i2]; X is 2 rows, 9 columns
I need to solve X with the following constraints: sum (a1 to i1) = 1 & sum (a2 to i2) = 1 & all elements in X shall be higher than or equal to zero (non negative).

Accepted Answer

John D'Errico
John D'Errico on 24 Mar 2018
Edited: John D'Errico on 24 Mar 2018
I almost always need to laugh out loud, when someone says they have a "large" system. That is not even close to large, by factors of thousands at least in the number of variables. If you said a million unknowns, yep, that is large. :)
But you seem confused even at that. First, you say 45x18. Then you say 5x2. Neither is large.
Actually, what you seem to have is a 5x2 system of equations, with 9 distinct right hand sides. So you have 9separate problems, each of which shares the same matrix A, so the same left hand side. You don't have 45 equations. Just 5 equations, solved 9 times, all essentially in one call.
And, wanting to do this?
X = [a1 b1 c1 d1 e1 f1 g1 h1 i1;a2 b2 c2 d2 e2 f2 g2 h2 i2]; X is 2 rows, 9 columns
A godawful bad idea.
Anyway, the way to solve ANY linear system of equations of the form A*X=B, large or small, is
X = A\B;
Note that this solves your problem, all 9 right hand sides at once. The result will be a 2x9 array.
  3 Comments
John D'Errico
John D'Errico on 26 Mar 2018
If you have the optimization toolbox, then use LSQLIN. Note that LSQLIN cannot solve all problems at once. So you will need to loop over the columns of B, creating one column of the result at each time through. But this is easy.
LSQLIN allows nonnegativity constraints, so you will provide LOWER bounds of [0 0] for each element.
LB = [0 0];
UB = [];
since you have no upper bounds. And of course, since there are no linear inequality constraints:
A = [];
b = [];
As well, LSQLIN allows you to specify the sum of the elements, as a linear equality constraint. So you would specify
Aeq = [1 1];
beq = 1;
to be passed in.
If you don't have the optimization toolbox (why would anyone not have that toolbox?) then this problem becomes more difficult, but not impossibly so.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!