Solve 100 equations, each with a different amount of unknowns in matlab

2 views (last 30 days)
Hi folks,
I have 100 equations which I want to solve simultaneously. There are 9 unknowns (A, B, C, D, E, F, G, H, J). Not each equation has 9 unknowns.
Below are a couple of the equations which I am trying to solve simultaneously (I'm aware there may be limitations considering not each equation has the same unknowns, but considering there is so many equations I'm hoping the computational capabilities of matlab could bypass this issue?).
PGASiteCorrectedIntraResidual(21)= 0.8965*B
PGASiteCorrectedIntraResidual(22)= 1.4350*F + 0.2272*B
PGASiteCorrectedIntraResidual(23)= 0.1902*K + 1.5069*L
PGASiteCorrectedIntraResidual(24)= 1.3683*F
PGASiteCorrectedIntraResidual(25)= 1.3260*L
PGASiteCorrectedIntraResidual(26)= 1.4388*L
PGASiteCorrectedIntraResidual(27)= 0.1428*A + 1.3456*E + 0.1208*F
PGASiteCorrectedIntraResidual(28)= 1.7080*F
PGASiteCorrectedIntraResidual(29)= 0.9675*B + 0.4395*F
PGASiteCorrectedIntraResidual(30)= 1.1125*F
PGASiteCorrectedIntraResidual(31)= 0.3608*A + 1.1628*E + 0.2967*F
PGASiteCorrectedIntraResidual(32)= 1.1762*C
PGASiteCorrectedIntraResidual(33)= 1.2025*F + 0.0642*B
PGASiteCorrectedIntraResidual(34)= 1.2082*F + 0.0638*B
PGASiteCorrectedIntraResidual(35)= 1.5749*F
PGASiteCorrectedIntraResidual(36)= 0.2690*A + 0.8727*B + 0.7128*F
PGASiteCorrectedIntraResidual(37)= 1.3713*L
PGASiteCorrectedIntraResidual(38)= 0.7236*B + 0.7163*F
PGASiteCorrectedIntraResidual(39)= 0.7961*B + 0.7752*F
PGASiteCorrectedIntraResidual(40)= 1.8229*E + 0.2857*F + 0.4807*B
PGASiteCorrectedIntraResidual(41)= 1.9081*A + 0.7745*B
PGASiteCorrectedIntraResidual(42)= 0.3616*K + 1.7008*L
PGASiteCorrectedIntraResidual(43)= 0.7649*B + 0.8394*F
PGASiteCorrectedIntraResidual(44)= 1.8750*A + 1.0423*B
PGASiteCorrectedIntraResidual(45)= 2.2159*B + 0.5612*C
PGASiteCorrectedIntraResidual(46)= 2.2250*E + 0.4393*D
Is there a function in matlab which could solve for these unknowns easily?
Thanks for any help

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 13 Jun 2019
What you have (shown) is a linear system of equations, with 100 equations and only 9 unknowns. This is exactly what matlab is designed to solve. Since the system is rather overdetermined, 91 more equations than unknowns, it is likely that all equations cannot be solved exactly at the same time, but you should be able to get a least-square solution without problems. What you should do is to create a matrix, M, with the coefficients for each equation row-by-row. After you've done that you have a simple matrix equation:
PGAS_vector = M*ABCDEFGHI;
Where the ABCDEFGHI array is an array with your 9 unknowns, and the PGAS_vector is the column-vector with all your PGASiteCorrectedIntraResidual components. Matlab is expertly designed to solve this type of overdetermined equations:
ABCDEFGHI = M\PGAS_vector;
That way you get a least-square solution for all your 9 unknowns.
Now, if the equations you've not shown contains non-linear terms in the unknowns this is not a solution.
HTH
  4 Comments
BOB
BOB on 13 Jun 2019
Ok great. One last thing. The PGAS_vector dimensions should be 100 x 1? If so I'm currently getting the matrix dimensions do not match issue. I'm assuming there should only be one column in this vector though?
Bjorn Gustavsson
Bjorn Gustavsson on 13 Jun 2019
Yes, it should have as many rows as you have in M - the number of equations. You should get somewtinh like this from whos:
>> whos
Name Size Bytes Class Attributes
M 100x9 168 double
PGAS_vector 100x1 56 double

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!