cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nmrGaussJordanInverse.h File Reference
#include <cisstCommon/cmnPortability.h>
#include <cisstVector/vctForwardDeclarations.h>
#include <cisstNumerical/nmrExport.h>

Go to the source code of this file.

Functions

Gauss Jordan Inverse for fixed size matrices

The function nmrGaussJordanInverseNxN (N = 2, 3, 4) computes the inverse of a NxN matrix using Gauss-Jordan elimination.

The function is instantiated for matrices of double and float in either storage order. When compiled in release mode, this function is at least 2.5 times faster than a parallel function in C-LAPACK based on LU decomposition (dgetrf, dgetri), with an equvalent precision. However, the speed advantage is counted here only in RELEASE mode, whereas in debug mode these functions are significantly slower.

The functions have been optimized to run for specific and typically occuring fixed-size cases, namely 2x2, 3x3 and 4x4. However, if all you need is to solve one linear equation, it is more efficient to have a direct solver than to compute the inverse first.

In terms of numerical stability, the Gauss-Jordan method should be fairly stable for the specific matrix sizes in question, but it only uses row pivoting, and therefore other methods that include also column pivoting should be more stable.

Parameters
Athe matrix whose inverse is computed, passed by value.
nonsingular(output) set to true if A is nonsingular, and to false if A is singular.
Ainv(output) set to the inverse of A if A is nonsingular
singularityTolerancea tolerance value for determining when a near-zero is encountered on the diagonal, which indicates that A is singular.
Note
For the 2x2 case, it may be more efficient and not less stable to use Kramer's rule.
template<class _elementType , bool _rowMajorIn, bool _rowMajorOut>
CISST_EXPORT void nmrGaussJordanInverse2x2 (vctFixedSizeMatrix< _elementType, 2, 2, _rowMajorIn > A, bool &nonsingular, vctFixedSizeMatrix< _elementType, 2, 2, _rowMajorOut > &Ainv, const _elementType singularityTolerance)
 
template<class _elementType , bool _rowMajorIn, bool _rowMajorOut>
CISST_EXPORT void nmrGaussJordanInverse3x3 (vctFixedSizeMatrix< _elementType, 3, 3, _rowMajorIn > A, bool &nonsingular, vctFixedSizeMatrix< _elementType, 3, 3, _rowMajorOut > &Ainv, const _elementType singularityTolerance)
 
template<class _elementType , bool _rowMajorIn, bool _rowMajorOut>
CISST_EXPORT void nmrGaussJordanInverse4x4 (vctFixedSizeMatrix< _elementType, 4, 4, _rowMajorIn > A, bool &nonsingular, vctFixedSizeMatrix< _elementType, 4, 4, _rowMajorOut > &Ainv, const _elementType singularityTolerance)
 

Function Documentation

template<class _elementType , bool _rowMajorIn, bool _rowMajorOut>
CISST_EXPORT void nmrGaussJordanInverse2x2 ( vctFixedSizeMatrix< _elementType, 2, 2, _rowMajorIn >  A,
bool &  nonsingular,
vctFixedSizeMatrix< _elementType, 2, 2, _rowMajorOut > &  Ainv,
const _elementType  singularityTolerance 
)

Gauss Jordan Inverse for a 2 by 2 matrix.

template<class _elementType , bool _rowMajorIn, bool _rowMajorOut>
CISST_EXPORT void nmrGaussJordanInverse3x3 ( vctFixedSizeMatrix< _elementType, 3, 3, _rowMajorIn >  A,
bool &  nonsingular,
vctFixedSizeMatrix< _elementType, 3, 3, _rowMajorOut > &  Ainv,
const _elementType  singularityTolerance 
)

Gauss Jordan Inverse for a 3 by 3 matrix.

template<class _elementType , bool _rowMajorIn, bool _rowMajorOut>
CISST_EXPORT void nmrGaussJordanInverse4x4 ( vctFixedSizeMatrix< _elementType, 4, 4, _rowMajorIn >  A,
bool &  nonsingular,
vctFixedSizeMatrix< _elementType, 4, 4, _rowMajorOut > &  Ainv,
const _elementType  singularityTolerance 
)

Gauss Jordan Inverse for a 4 by 4 matrix.