Error Checking
At this point, you may ask: "What happens in the example program if the matrix A is singular?" The answer is less than satisfactory: a runtime error occurs. Fortunately, such errors are easily prevented by testing the factorization. This is done by replacing //4 with the code:
RWGenFact<float> LU(A);
if (LU.fail()) { /* Your error handler goes here*/ }
RWMathVec<float> x = solve(LU,b);
The fail() member function exists for all the factorization types. If it returns true, calling solve() will likely result in a runtime error. In this example, you could also use the member function isSingular() to test for an error condition, but some factorizations may fail even if the matrix is not singular, so calling fail() is a better method of checking.
In addition to singularity, other situations can induce runtime error; for example, attempting to construct a positive-definite factorization from a matrix which is not positive-definite.