MATLAB 矩阵问题
我有一个方程组(总共 5 个),有 5 个未知数。我已将它们放入矩阵中以尝试解决,但我不确定结果是否正确。基本上设置是 AX = B
,其中 A
、X
和 B
是矩阵。 A
是 5x5,X
是 1x5,B
是 5x1。
当我使用 MATLAB 使用公式 X = A\B
求解 X
时,它会向我发出警告:
Matrix is singular to working precision.
并为所有 5 个 X 未知数给出 0,但如果我说 X = B\A
事实并非如此,并给出了 5 个 X
未知数的值。
有人知道我做错了什么吗?如果这很重要,这就是我的 X
矩阵的样子:
X= [1/C3; 1/P1; 1/P2; 1/P3; 1/P4]
其中 C3
、P1
、P2
、 P3
、P4
是我的未知数。
I have a system of equations (5 in total) with 5 unknowns. I've set these out into matrices to try solve, but I'm not sure if this comes out right. Basically the setup is AX = B
, where A
,X
, and B
are matrices. A
is a 5x5, X
is a 1x5 and B
is a 5x1.
When I use MATLAB to solve for X
using the formula X = A\B
, it gives me a warning:
Matrix is singular to working precision.
and gives me 0 for all 5 X unknowns, but if I say X = B\A
it doesnt, and gives me values for the 5 X
unknowns.
Anyone know what I'm doing wrong? In case this is important, this is what my X
matrix looks like:
X= [1/C3; 1/P1; 1/P2; 1/P3; 1/P4]
Where C3
, P1
, P2
, P3
, P4
are my unknowns.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的矩阵是奇异,这意味着它的行列式为 0。这样的方程组无法为您提供足够的信息来找到唯一的解决方案。我在你的问题中看到的一件奇怪的事情是 X 是 1x5,而 B 是 5x1。这不是提出问题的正确方式。 X 和 B 都必须为 5x1。如果您想知道,这不是 Matlab 的东西 - 这是线性代数的东西。此
[5x5]*[1x5]
是非法的。此[5x5]*[5x1]
生成[5x1]
结果。此[1x5]*[5x5]
生成[1x5]
结果。首先检查代数,然后检查行列式(Matlab 中的det
函数)是否为 0。Your matrix is singular, which means its determinant is 0. Such system of equations does not give you enough information to find a unique solution. One odd thing I see in your question is that X is 1x5 while B is 5x1. This is not a correct way of posing the problem. Both X and B must be 5x1. In case you're wondering, this is not a Matlab thing - this is a linear algebra thing. This
[5x5]*[1x5]
is illegal. This[5x5]*[5x1]
produces a[5x1]
result. This[1x5]*[5x5]
produces a[1x5]
result. Check you algebra first, and then check whether the determinant (det
function in Matlab) is 0.所以,接下来的事情就是弄清楚为什么
A
是单数。 (请注意,在具有平方和单数A
的情况下,您可能想要求解A x = b
,但仅在
b
在A
的范围空间内。)也许你可以写出你的矩阵
A
和向量b
(因为它只是5x5)?或者解释一下你是如何创建它的。这可能会提供一些线索,说明为什么A
未满秩,或者为什么b
不在A
的范围空间中。So, the next thing is to figure out why
A
is singular. (Note that it's possible that you'd want to solveA x = b
in cases with square and singular
A
, but they'd only be in cases whereb
is in the range space ofA
.)Maybe you can write your matrix
A
and vectorb
out (since it's only 5x5)? Or explain how you create it. That might give a clue as to whyA
isn't full rank or as to whyb
isn't in the range space ofA
.