Subtraction not calculating correctly

3 views (last 30 days)
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
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.

Sign in to comment.

Accepted Answer

Cris LaPierre
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
AXminusC = 2×1
0 0

More Answers (0)

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!