This macro shows several ways to invert a matrix .
Each method is a trade-off between accuracy of the inversion and speed. Which method to chose depends on "how well-behaved" the matrix is. This is best checked through a call to Condition(), available in each decomposition class. A second possibility (less preferred) would be to check the determinant
USAGE
This macro can be executed with Cling or ACLIC
- via the interpretor, do
double invertMatrix(const Matrix &matrix, Matrix &inverse)
- via ACLIC
R__EXTERN TSystem * gSystem
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
--------------------------------------------------------
Inversion results for a (6,6) matrix
For each inversion procedure we check the maximum size
of the off-diagonal elements of Inv(A) * A
--------------------------------------------------------
1. Use .InvertFast(&det)
Maximum off-diagonal = 8.31175e-05
Determinant = 5.3673e-18
2. Use .Invert(&det)
Maximum off-diagonal = 1.74623e-10
Determinant = 5.3673e-18
3. Use TDecompLU
Maximum off-diagonal = 1.74623e-10
Determinant = 5.3673e-18
4. Use TDecompSVD on non-square matrix
Maximum off-diagonal = 5.45697e-12
Determinant = 1.34646e-11
#include <iostream>
{
std::cout << "2 <= msize <= 10" <<std::endl;
return;
}
std::cout << "--------------------------------------------------------" <<std::endl;
std::cout <<
"Inversion results for a ("<<
msize<<
","<<
msize<<
") matrix" <<std::endl;
std::cout << "For each inversion procedure we check the maximum size " <<std::endl;
std::cout << "of the off-diagonal elements of Inv(A) * A " <<std::endl;
std::cout << "--------------------------------------------------------" <<std::endl;
std::cout << "1. Use .InvertFast(&det)" <<std::endl;
std::cout <<
" for ("<<
msize<<
","<<
msize<<
") this is identical to .Invert(&det)" <<std::endl;
std::cout <<
" Maximum off-diagonal = " <<
U1_max_offdiag << std::endl;
std::cout <<
" Determinant = " <<
det1 << std::endl;
std::cout << "2. Use .Invert(&det)" << std::endl;
std::cout <<
" Maximum off-diagonal = " <<
U2_max_offdiag << std::endl;
std::cout <<
" Determinant = " <<
det2 << std::endl;
std::cout << "3. Use TDecompLU" << std::endl;
std::cout <<
" Maximum off-diagonal = " <<
U3_max_offdiag << std::endl;
std::cout <<
" Determinant = " <<
det3 << std::endl;
std::cout << "4. Use TDecompSVD on non-square matrix" << std::endl;
std::cout <<
" Maximum off-diagonal = " <<
U4_max_offdiag << std::endl;
std::cout <<
" Determinant = " <<
det4 << std::endl;
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
THilbertMatrixT< Double_t > THilbertMatrixD
Single Value Decomposition class.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
- Author
- Eddy Offermann
Definition in file invertMatrix.C.