Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

MATLAB Matrix Inversion: inv(X) versus X\eye(size(X))

Writer Matthew Barrera

Based on the wonderful MATLAB documentation, it is clear that when solving systems of linear equations, it is preferable to use X\b to inv(X)*b for reasons of numerical stability. It also notes that X^(-1) is equivalent to inv(X). But it makes no mention of the relationship between X\eye(size(X)) and inv(X)! I would like to use the more succinct notation, and it makes sense that inv(X) should be the preferred form, but cannot find confirmation of this anywhere in the documentation.

The docs mention that \ uses Gaussian elimination whereas inv uses LU decomposition.

When I tested them using an example similar to that provided in the documenation, I find that the two are not equivalent:

n = 500;
Q = orth(randn(n,n));
d = logspace(0,-10,n);
A = Q*diag(d)*Q';
y = inv(A);
z = A\eye(n);
disp(['Difference: ', num2str(norm(inv(A) - A\eye(n)))]);

The results:

Difference: 2.2957e-05

Can anyone explain which of the two methods is more numerically stable?

9 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy