5.5. INVERSE OF A MATRIX AND THE DETERMINANT 81
Set up the matrix A and the vector w with their correct dimensions. This
determines the dimensionality of the unknown vector x.
Then LU decompose the matrix A through a call to the function
C: void ludcmp(double
a, int n, int indx, double d)
Fortran: CALL lu_decompose(a, n, indx, d)
This functions returns the LU decomposed matrix A, its determinant and the
vector indx which keeps track of the number of interchanges of rows. If the
determinant is zero, the solution is malconditioned.
Thereafter you call the function
C: lubksb(double
a, int n, int indx, double w
Fortran: CALL lu_linear_equation(a, n, indx, w)
which uses the LU decomposed matrix A and the vector w and returns x in
the same place as w. Upon exit the original content in w is destroyed. If you
wish to keep this information, you should make a backup of it in your calling
function.
The codes are listed in the program libraries:
lib.c
,
f90lib.f
.
5.5 Inverse of a matrix and the determinant
The basic definition of the determinant of A is
where the sum runs over all permutations of the indices , altogether terms. Also
to calculate the inverse of A is a formidable task. Here we have to calculate
the complementary
cofactor
of each element which is the determinant obtained by striking out the
row
and column in which the element appears. The inverse of A is the constructed as the
transpose a matrix with the elements . This involves a calculation of determinants
using the formula above. Thus a simplified method is highly needed.
With the LU decomposed matrix A in eq. (5.2) it is rather easy to find the determinant
(5.17)