MATLAB: Solving large overdetermined system of equations

overdetermined system

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).

Best Answer

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.
Related Question