Q:

I need help adapting a code to work out a 3x3 matrix and displaying the identity matrix?

Hi I have already programmed on c++ to solve a 3x3 matrix. However I also need to show that multiplying a matrix by it's inverse will give the unit matrix. I have found this code that does this but it's very complicated and for a 5x5 matrix. I was hoping someone could adapt it and explain it for me, I'm new to coding and struggling. With this code it has no option for you to input your code and im unsure of how to edit it to do this and to make it for a 3x3 matrix. Any help will be appreciated thank you.
I have got the code from this link and is using it on microsoft visual studio.
https://www.sanfoundry.com/cpp-program-find-inverse-matrix/

A:

(I'll retract if the community shows it doesn't like this answer).
Computationally you don't calculate the inverse of a matrix like you were taught to at school; as the algorithm performs terribly for higher dimensions.
This is how I compute the inverse of a matrix. I use the BLAS distribution from Boost. I wrap the matrix class in my own matrixT but here's the code to demonstrate the incremental simplicity:
// Inversion operator
matrixT I() const
{
     matrixT A(*this);
     boost::numeric::ublas::permutation_matrix<std::size_t> pm(rows());
     if (boost::numeric::ublas::lu_factorize(A, pm)){
         throw "matrix is singular";
     }
     matrixT ret = identity_matrix(rows());
     boost::numeric::ublas::lu_substitute(A, pm, ret);
     return ret;
}

