If you’re doing a lot of simulations, optimizations or other muckity-muck, it’s easy to start writing down equations with matrices like inside of them. And, depending on the application, it might be a really good idea to precompute this matrix. But there’s that pesky inverse operation, and generally inverting a matrix is a no-no since it can easily land you in trouble when that matrix isn’t really very stable.

So, here’s a trick you can use in these situations to avoid explicitly inverting the matrix A. It turns out that instead we can just solve the system a bunch of times in order to explicitly compute the product matrix .

It’s pretty straightforward. If we want to extract the th column from , we need to solve the equation , where is the indicator vector with s everywhere except the th entry, which is . If we just massage this equation a bit, we get where is the th column of . Sweet! If we have a good way to pre-factor or otherwise prepare it for repeated solves, we can also keep this solution method pretty efficient.

Note that X = inv(A)*B is the solution to AX = B, which can be solved columnwise for X and B. Just another way of saying the same thing.

Of course all is lost if you then solve Ax = b by taking the inverse. MATLAB’s backslash operator is your friend here, assuming MATLAB is your friend. 🙂