The inverse of a matrix A is the matrix that undoes it: multiply the two together and you get the identity back. It's the closest thing matrices have to division, and it's the engine behind the normal equation that fits a linear regression.
The standard way to find it by hand is Gauss-Jordan elimination: write A next to the identity matrix, then row-reduce the left half into the identity. Whatever the right half turns into is the inverse.
Task: write inverse(matrix) returning the inverse, every entry rounded to 4 decimal places.
The procedure, column by column:
A, giving n rows of 2n numbers.c, pick the row at or below c with the largest absolute value in that column, and swap it up into position c. (This is called partial pivoting. Even when any non-zero row would do algebraically, picking the biggest keeps the division from amplifying rounding error.)c, making the pivot exactly 1.c becomes 0.When you're done, the left half is the identity and the right half is your answer.
matrix is square and always invertible, so you never hit a column of zeros.n rows of n numbers.