Linear Algebra Classes
Overview
The Essential Math Module provides linear algebra classes to solve sets of simultaneous linear equations via LU factorization for any numeric field type, including double, float, and double precision complex. The requirements for a numeric type to use the linear algebra classes are detailed in
Defining a New Numeric Type. These classes use a templatized version of the Linpack algorithms.
Using these classes is very easy and can even be completely transparent to the user. For example, here is the code to invert a matrix:
#include <rw/math/genfact.h>
#include <rw/math/genmat.h>
int main()
{
RWGenMat<double> A;
std::cin >> A; // Read in a matrix
// Invert it:
RWGenMat<double> Ainv = inverse(A);
}
Here is how you would solve a set of linear equations Ax = b, assuming that A has been read in as above:
// Read in the vector b:
RWMathVec<double> b;
std::cin >> b;
// "x" will contain the solution:
RWMathVec<double> x = solve(A, b);