So I have the following system of equations
x1 - x2 = 20
x2 - x3 = 30
x3 - x4 = 75
x4 - x5 = -49
-x1 + x5 = -20
how would I solve the system using Matlab? I I'm a little stuck.
There's a good chance there's no solution but if someone could let me know how to do it that would be great!
First, convert this equation into matrix notation:
You are trying to find
x
givingAx = b
. You can not take the inverse ofA
since it is singular. To see this check its rank;rank(A) == 4
. It would be 5 ifA
were non-singular.So, you should find best
x
approximatingb
when multiplied byA
from left. This is an optimization problem: you want to minimize the error betweenAx
andb
. Usually, people use least squares method. That is, you minimize the sum of squares of the residuals. This can be done by pseudo inverse as follows:gives
Best approximation is found by
The least squares error is found to be
If you want to try other methods alternative to least squares to minimize
Ax-b
, you can google l1-minimization, sparse encoding, etc.Just look at it and mentally add up the equations. LHS is zero, right hand side is something positive, so there is no solution!