#include #include #include #include "TRandom3.h" #include "JLang/JException.hh" #include "JMath/JMatrix1S.hh" #include "JMath/JMathTestkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to test inversion of symmetric matrix. * \author mdejong */ int main(int argc, char**argv) { using namespace std; using namespace JPP; double precision; int debug; try { JParser<> zap("Example program to test inversion of symmetric matrix."); zap['e'] = make_field(precision) = 1.0e-6; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } gRandom->SetSeed(0); JMatrix1S A = getRandom(); DEBUG("Matrix A" << endl); DEBUG(A << endl); NOTICE("Determinant A " << A.getDeterminant() << endl); try { JMatrix1S B(A); B.invert(); DEBUG("Matrix A^-1" << endl); DEBUG(B << endl); NOTICE("Determinant A^-1 = " << B.getDeterminant() << endl); JMatrix1D C(A * B); DEBUG("Matrix A x A^-1" << endl); DEBUG(C << endl); NOTICE("Determinant (A x A^-1) = " << C.getDeterminant() << endl); NOTICE("Determinant A x Determinant A^-1 = " << A.getDeterminant() * B.getDeterminant() << endl); NOTICE("A x A^-1 = I ? " << C.isIdentity(precision) << endl); if (!C.isIdentity(precision)) { ERROR("Matrix A x A^-1 /= I" << endl); } JMatrix1D D = C - JMatrix1D::getIdentity(); DEBUG("Matrix D = C - I" << endl); DEBUG(D << endl); ASSERT(C.isIdentity(precision)); } catch (const JException& error) { FATAL(error << endl); } return 0; }