By Evan Lauer
The basic code (matrix_inverse_web.cpp, inverse_closed_form.cpp, and inverse_real_valued.cpp) is written in C++. The web interface uses Emscripten to compile C++ to Javascript, which is then leveraged by matrix_inverse_calculator.html to create the web view.
This project is an online calculator which achieves two objectives: [1] Calculate the closed-form inverse equation for a general matrix of a given size and [2] Calculate the actual inverse of a real-valued matrix.
To see the code in-action in a web calculator, visit my blog (currently under construction). This interface currently only allows for [2].
Finding the inverse of a matrix can be a useful operation in linear algebra.
To achieve objective [2] requires basic arithmetic:
- For each entry (i, j) in matrix A, find the (i, j) minor matrix, and calculate its determinant.
- Populate a new matrix with entries representing the minor matrix determinant of the given entry.
- Transpose the new matrix. This is the inverse.
To achieve objective [1] is a more computationally intense task. Closed-form equations for matrix inverses tend to be very long, and to find them by hand requires a long process of row reduction of a general matrix, with a placeholder variable for each matrix entry. For a larger matrix, (5 x 5 or greater), the equations will have 25 or more variables.
This computational effort is the fundamental reason for this calculator. I've found it hard to find closed-form equations for matrix inverses. The largest one easily available online is 4 x 4. With my calculator, you can find the equation of a matrix of any size!
To achieve this requires a more intense operation. In summary, my code recursively solves for the determinants of minor matrices.
Once the recursion reaches a small, 2 x 2 matrix, the equation (ad - bc) is returned (this is the determinant equation for a 2 x 2 matrix).
This formula is then altered by each higher-order stack according to the rules of minor matrix determinants, until the top level.
Once the determinant formula for each matrix entry is found, a new matrix is populated with these entries and transposed. To find the (i, j) entry of the inverse matrix, you divide the formula in the new matrix by the determinant formula for the larger matrix. Whew.
- Use a better algorithm -- row reduction instead of Laplace expansion
- Add a web interface for operation [1]---IN PROGRESS
- Cache formulas below a certain size for operation [1].
- Finish integration with my personal site (currently under construction).
- Use git version control with cPanel hosting
- Split operations [1] and [2] into separate functions, files, and front-end interfaces for faster computing time.
- Compile to WASM instead of JS