Subtraction not calculating correctly
3 views (last 30 days)
Show older comments
Michael Cottell
on 18 Feb 2021
Commented: James Tursa
on 19 Feb 2021
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 Comment
James Tursa
on 19 Feb 2021
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.
Accepted Answer
Cris LaPierre
on 18 Feb 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Elementary Math in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!