When computing the inverse for some square matrix A in MATLAB, using
Ai = inv(A)
% should be the same as:
Ai = A^-1
MATLAB usually notifies me that this is not the most efficient way of inverting. So what's more efficient? If I have an equation system, using the /,\ operators probably is. But sometimes I need the inverse for other computations.
What's the most efficient way to invert?
If there isn't a clever way to do all your calculations without explicitly forming the inverse then you have to use the "inv" function. You could of course solve a linear system with your matrix and the identity matrix, but there is nothing to be gained by doing that.
I think LU decomposition is more efficient than than inversion (and potentially more stable if you use pivoting). It works especially well if you need to solve for more than one right hand side vector, because once you have the LU decomposition you can do the forward back substitutions for each one as you need it.
I would recommend LU decomposition over a full inverse. I agree if that's what MATLAB is saying.
UPDATE: 3x3 matrix? You can invert that by hand in closed form if you need it. Just check the determinant first to make sure that it's not singular or nearly singular.
I would recommend to use
svd
(unless you are really absolute sure that your matrix is not ill-conditioned). Then, based on singular values you make your decisions on further actions to take. This may sound like a 'overkill' approach, but in long run it will pay back.Now if your matrix
A
is actually invertible, then thepseudo inverse
ofA
coincidence withinv(A)
, however if you are close to 'singularity' you'll easily make appropriate decision how to proceed to actually make thepseudo inverse
. Naturally these decisions will depend on your application.Added a straightforward example:
If you only need the inverse then just do, it will be numerically more stable than inv(A):