Subtraction not calculating correctly
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Michael Cottell
el 18 de Feb. de 2021
Comentada: James Tursa
el 19 de Feb. de 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 comentario
James Tursa
el 19 de Feb. de 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.
Respuesta aceptada
Cris LaPierre
el 18 de Feb. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Elementary Math en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!