Solving system of equations using matlab

耗尽温柔 提交于 2019-12-07 12:46:26

问题


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!


回答1:


First, convert this equation into matrix notation:

A = [ 1 -1  0  0  0
      0  1 -1  0  0
      0  0  1 -1  0
      0  0  0  1 -1
     -1  0  0  0  1];

b = [ 20
      30
      75
     -49
     -20];

You are trying to find x giving Ax = b. You can not take the inverse of A since it is singular. To see this check its rank; rank(A) == 4. It would be 5 if A were non-singular.

So, you should find best x approximating b when multiplied by A from left. This is an optimization problem: you want to minimize the error between Ax and b. 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:

x = pinv(A) * b

gives

x =

   31.8000
   23.0000
    4.2000
  -59.6000
    0.6000

Best approximation is found by

b2 = A*x


b2 =

    8.8000
   18.8000
   63.8000
  -60.2000
  -31.2000

The least squares error is found to be

e = norm(b-b2)

e =

   25.0440

If you want to try other methods alternative to least squares to minimize Ax-b, you can google l1-minimization, sparse encoding, etc.




回答2:


Just look at it and mentally add up the equations. LHS is zero, right hand side is something positive, so there is no solution!



来源:https://stackoverflow.com/questions/13484109/solving-system-of-equations-using-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!