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
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
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
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!