How to find the inverse of an upper triangular matrix

I want to find the inverse of an upper triangular matrix in an efficient way. I googled a lot, but all the articles discussed about a lower triangular matrix.

Is it possible to edit the matlab code in this answer so that its suitable for an upper triangular matrix? https://stackoverflow.com/a/12240951/919177

• The transpose of an upper triangular matrix is lower triangular. This should help you. – J.R. Oct 12 '15 at 9:45
• I think matlab's backslash operator will automatically make use of the upper triangular structure. Why not just use backslash? But note that if you want to write your own solver, you can use back substitution to solve an upper triangular system. You know the last component of $x$ immediately, and that's a good start. – littleO Oct 12 '15 at 9:51
• I guess I will just use the transpose on the forward substitution code given in the link. Thanks everyone. – vipin Oct 12 '15 at 10:32

If you really want to find the inverse $M$ of an invertible upper triangular matrix $U$, note that $U M = I \implies M^T U^T = I$, which shows that $M^T$ is the inverse of the lower triangular matrix $U^T$.
So, you can find $M^T$ using the code you already have to invert a lower triangular matrix. This gives you $M$.
However, a rule of thumb is that you rarely want to compute the inverse of a matrix explicitly. If you ever need to solve $Ux = b$, you can just use back substitution.