Are there any function calculating matrix inverse with hints?

2 views (last 30 days)
Is it possible to give hint to a function which try to calculate the inverse of a matrix?

Answers (1)

John D'Errico
John D'Errico on 20 May 2015
The answer is a definite no, or a reluctant maybe. The latter is that you can do anything you want if you understand what is a matrix inverse. Of course, in that case you won't bother to do so.
Ok, so the no first. Why not? A matrix inverse is unique as long as the matrix is not singular. So no hint would make any sense at all. And if the matrix was singular? Then NO inverse exists. PERIOD. An inverse matrix is defined as the matrix such that for a square, nxn, nonsingular matrix A, we must have these relations be true:
A*Ainv == eye(n)
Ainv*A == eye(n)
Now, suppose that A was singular? Then it has rank less than n. There exists no matrix with which that you can multiply a matrix with rank LESS than n, and get a result that has rank n.
So no hint can possibly help. You CANNOT give any kind of hint, because NO hint would be meaningful.
Having said all of that, there are various forms of pseudo-inverse. The best one is of course pinv. And as long as the matrix A is non-singular, then pinv will return the same result as does inv. When the matrix is singular, so it has less than full rank, then pinv will survive, and will return a matrix with less than full rank that behaves as much like an inverse as is possible.
Now, you talk about "hints". This is a bit more difficult to do, and it probably will be not too successful. There are infinitely many pseudo-inverses, some of which MAY perform slightly better than others in the context of whatever "hint" you had in mind. I'd still just use what pinv gives you. In fact, pinv is arguably better than inv, since pinv will (sort of) survive when inv fails.
Finally, the fact is, you should not be using a matrix inverse in general. A matrix inverse is one of those things they teach you to do early in your mathematical career, but then don't teach you why you should avoid it, why it is often a problem. This is something you don't really learn until you start learning something about numerical methods. And the fact is, it is nice and easy to write inv(A) when in fact, you really needed to solve a linear system of equations. So authors of papers write A^-1 all over the place. Most of those authors probably don't really understand why this is a problem if that matrix happens to be singular. And even for those who do understand the issues, hopefully they also understand that even when they write it as A^-1*B, they are better off performing this operation as A\B or as pinv(A)*B.
So if you are using the matrix inverse to solve a linear system of equations, so inv(A)*B, then you should not be doing so. Instead, use the better forms in MATLAB:
A\B
or
pinv(A)*B

Categories

Find more on Creating and Concatenating Matrices 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!