Subtraction not calculating correctly

4 次查看(过去 30 天)
A=[2 -3; 6 3];
c=[-5; 1];
% Ax=c --> (inv(A)*A)*x = inv(A)*C --> x=inv(A)*c
X=inv(A)*c;
%Why does AX-C not equal of column vector of zeros > [0;0]?
AX=A*X
AXminusC=AX-c
hi there,
im struggling to figure out why i am getting an incorrect subtraction for my variable AXminusC.
The result of AX is a column vector [-5;1] therefore AX-c should output a matrix of [0;0]
Im struggling to understand why AXminusC outputs a matrix of 1.0e-15*[0;-0.220].
  1 个评论
James Tursa
James Tursa 2021-2-19
Because of floating point arithmetic rounding effects, you should not expect the calculation A*(inv(A)*c) - c to result in exactly 0's. You might get lucky in some cases and actually get exact 0's, but in the general case you should expect to get relatively small non-zero residuals from this calculation.

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2021-2-18
You may need to clear your workspace. When I run your code, the result is [0;0]
A=[2 -3; 6 3];
c=[-5; 1];
X=inv(A)*c;
AX=A*X;
AXminusC=AX-c
AXminusC = 2×1
0 0

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by