2020-05-17

invert, solve, and least-squares

One of the things I throw into seminars and papers these days is about numerical linear-algebra operators. My advice is: Never use the invert() function to invert a matrix! Why not? Because you almost never want the inverse, you want the inverse applied to a vector. So when you are tempted to do dot( inv(A), x ) you should instead do solve( A, x ). The first gets a machine-precision (if you are lucky) inverse of A and applies it to x. The latter gets a machine-precision (if you are lucky) estimate of A-inverse applied to x. You see the difference?

Well, all of that got complexified today when I learned (from Soledad Villar NYU) about lstsq(). This does the same as solve() (and more) but it is zero-safe. Meaning: It gives good answers even when the A matrix has zero eigenvalues. I think my advice may be evolving.

No comments:

Post a Comment