使用Matlab求解方程组

编程入门 行业动态 更新时间:2024-10-11 09:30:10
本文介绍了使用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 = b的x.您不能将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.这是一个优化问题:您希望最小化Ax和b之间的错误.通常,人们使用最小二乘法.也就是说,您可以最小化残差的平方和.可以通过伪逆完成,如下所示:

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求解方程组

本文发布于:2023-11-29 18:42:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647276.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方程组   Matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!