Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

5.2 LU Factorization

In the previous section, the actual procedure for solving the set of linear equations Ax = b uses the LU factorization technique.

If A is a square matrix, it has an LU factorization with a permutation matrix P, an upper triangular matrix U, and a lower triangular matrix L, such that A = PLU. This factorization can be used to solve linear equations Ax = b. It can also be used to compute the determinant of A from the equation det(A) = det(P)det(L)det(U), and to compute the inverse of A as A-1 = U-1L-1P-1.

Let us see how Math.h++ does this. The basic idea is that an LU factorization is actually implemented as a class in the Math.h++ class library. This is an example of the general notion in object-oriented programming that if you can think of something as an "it," you can probably make "it" into a class. The LU factorization class is called RWGenFact<T>, and it takes a matrix as an argument in its constructor:

Once constructed, this LU factorization can be used for many things. For example, there is the global function inverse():

which takes an argument of type RWGenFact<T>. Hence, one could invert a matrix as follows:

The inverse() global function is overloaded to take either RWGenMat<T> or RWGenFact<T>. When inverse() is given an RWGenMat<T>, it creates a temporary RWGenFact<T> and passes that to inverse(). In the first example above, this is what is actually happening:

Similar to inverse(), the global function solve() is also overloaded:

When called with an argument of type RWGenMat<T>, a similar type conversion occurs.

The great advantage to explicitly creating an RWGenFact<T> is that you can create an LU factorization only once and use it many times, perhaps to solve many sets of linear equations:

This approach can result in great time savings because calculating the LU factorization takes most of the time, but need be done only once. Yet its calculation becomes transparent to the user who is not interested in the factorization (or wants to remain ignorant of it!)


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.