how to you write program that calculate the inverse of a matrix
Take it from me: nobody wants to calculate an explicit form of the invers of a
matrix for two reasons:
1) numerical instability
2) performance.
Instead use a 'LUP' decomposition of a matrix A (google for it). A sketch of
the procedure runs like this:
PA = LU where P is a row permutation matrix (and identity matrix with its rows
permuted) and L and U are lower and upper triangular matrices with the additional
property that the diagonal of L are all 1s (one). Matrix P can be stored very efficiently.
Finding L and U is easy: it's just a partial Gaussian ellimination procedure,
the same thing you had to use for an explicit form of the inverse of a matrix.
Matrix P is found on the fly when you select a suitable pivot for a row.
Solving a linear system Ax= b is equivalent to PAx= Pb (permute the rows of b)
== LU= Pb which is nothing but a so called 'forward' and 'backward' substitution
thanks to the triangularity of matrices L and U.
Google for 'LUP decomposition' for the details.
kind regards,
Jos