使用Matlab求解方程组 [英] Solving system of equations using matlab

查看:82
本文介绍了使用Matlab求解方程组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有以下方程组

 x1 - x2 =  20
 x2 - x3 =  30
 x3 - x4 =  75
 x4 - x5 = -49
-x1 + x5 = -20

我如何使用Matlab解决系统?我有点卡住了.

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:

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];

您正在尝试查找提供Ax = bx.您不能将A取反,因为它是单数形式.要查看此检查的等级; rank(A) == 4.如果A不是奇数,则为5.

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.

因此,从左侧乘以A时,应该找到近似b的最佳x.这是一个优化问题:您希望最小化Axb之间的错误.通常,人们使用最小二乘法.也就是说,您可以最小化残差的平方和.可以通过伪逆完成,如下所示:

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

给予

x =

   31.8000
   23.0000
    4.2000
  -59.6000
    0.6000

发现最佳近似值

b2 = A*x


b2 =

    8.8000
   18.8000
   63.8000
  -60.2000
  -31.2000

发现最小二乘误差是

e = norm(b-b2)

e =

   25.0440

如果您想尝试使用最小二乘以外的其他方法来最小化Ax-b,则可以Google l1-最小化,稀疏编码等.

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

这篇关于使用Matlab求解方程组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆