[英]Wrong solution of a linear equation, or why does A*(A\B) not equal B?
How is it possible that the result of A*(A\\D)
below is not equal to D
? 下面的A*(A\\D)
的结果怎么可能不等于D
?
It should yield D
- here is an extract of the Octave documentation : 它应该产生D
- 这是Octave文档的摘录:
Systems of linear equations are ubiquitous in numerical analysis. 线性方程组在数值分析中普遍存在。 To solve the set of linear equations Ax = b, use the left division operator, '\\': x = A \\ b 要求解线性方程组Ax = b,请使用左除法运算符'\\':x = A \\ b
Below is the code for those who want to try it: 以下是想要尝试的人的代码:
A = [1,1,1;0,0,0;2,1,2;2,1,2;3,5,6]
D = [1;2;3;4;5]
% A is of rank 3:
rank(A)
% therefore the system Ax=D has a unique solution
x = A\D
% but Octave has not given the good solution:
A*x
Somebody says me that Matlab yields exactly the same result. 有人说我Matlab产生完全相同的结果。
EDIT 10/10/2012: After having read the answers, let me point where I did a serious mistake: the claim "A is of rank 3 therefore the system Ax=D has a unique solution" is absolutely wrong ! 编辑10/10/2012:在阅读了答案之后,让我指出我犯了一个严重错误的地方:声明“A是等级3因此系统Ax = D有一个独特的解决方案”是绝对错误的! By the way the piece of documentation shown above is quite disconcerting. 顺便说一句,上面显示的文档非常令人不安。
A
has 5 rows, and so is D
. A
有5行, D
。 Both of them have 3 columns. 它们都有3列。 Therefore, you have an overdetermined system of 5 equations with 3 variables. 因此,您有一个包含3个变量的5个方程的超定系统。 In most of the cases, it means that you cannot solve the equations exactly, because you have too many constraints. 在大多数情况下,这意味着你无法准确地求解方程,因为你有太多的约束。
Once you do 一旦你这样做了
x = A\D;
you get the least squares solution. 你得到最小二乘解决方案。
0.8333
-1.5000
1.6667
What is this solution? 这个解决方案是什么? It is a solution that minimizes the sum of squares of errors. 这是一种最小化误差平方和的解决方案。 Let's calculate the error: 我们来计算错误:
r = A*x-D;
totalError = sum( r.^2);
It means that you will not be able to find any x
such that sum(sqr(A*xD))
has smaller error. 这意味着您将无法找到任何x
,使得sum(sqr(A*xD))
具有较小的误差。
Small remark : In your case, you also have a row of zeroes - which causes the actual number of equations to become 4 小注:在你的情况下,你还有一行零 - 这导致实际的方程数变为4
Let's take a look again at A*(A\\D)
: 让我们再来看看A*(A\\D)
:
>> A* (A\D)
ans =
1.0000
0
3.5000
3.5000
5.0000
That looks familiar! 看起来很熟悉! Very close to [1;2;3;4;5]. 非常接近[1; 2; 3; 4; 5]。 The first and the last rows are the same. 第一行和最后一行是相同的。 The second is zero, because you put a line of zeros. 第二个是零,因为你放了一行零。 In the 3rd and 4th rows, you had exactly the same lines in A, but different value in B, that corresponds to 在第3行和第4行中,A中的行具有完全相同的行,但B中的值不同,对应于
2*x+ 1*y + 2*z = 3;
2*x+ 1*y + 2*z = 4;
And you've got their average! 而且你的平均水平! It makes sense, because the average is the value that minimizes the sum of distances to 3 and 4. 这是有道理的,因为平均值是最小化到3和4的距离之和的值。
Here is a simpler example, suppose you want to solve the following system of equations: 这是一个更简单的例子,假设您想要求解以下方程组:
x = 1;
x = 2;
Obviously, x
cannot be 1
and 2
at the same time. 显然, x
不能同时为1
和2
。 The solution that minimizes the sum of squares of errors is 1.5
最小化误差平方和的解决方案是1.5
A = [1;1];
b = [1;2];
A\b
ans =
1.5000
Your system A
is overdetermined (A is rectangular), hence you do not solve your system exactly : 您的系统A
超定(A为矩形),因此您无法准确解决系统问题 :
Rectangular Matrices If A is rectangular, mldivide returns a least-squares solution. 矩形矩阵如果A是矩形,则mldivide返回最小二乘解。 MATLAB solves overdetermined systems with QR factorization (see qr). MATLAB通过QR分解求解超定系统(参见qr)。 For an underdetermined system, MATLAB returns the solution with the maximum number of zero elements. 对于欠定系统,MATLAB返回具有最大零元素数的解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.