Solving system of equations using matlab

試著忘記壹切 提交于 2019-12-05 19:49:50

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.

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

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