#include #include #include #include "TRandom3.h" #include "TMatrixTSym.h" #include "JLang/JException.hh" #include "JMath/JMatrix4S.hh" #include "JMath/JMathTestkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JTimer.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 numberOfEvents; int debug; try { JParser<> zap("Example program to test inversion of symmetric matrix."); zap['e'] = make_field(precision) = 1.0e-6; zap['n'] = make_field(numberOfEvents) = 1000; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } ASSERT(numberOfEvents > 0); gRandom->SetSeed(0); JTimer t1("Jpp"); JTimer t2("ROOT"); for (int i = 0; i != numberOfEvents; ++i) { if (i%100 == 0) { STATUS(setw(8) << i << '\r'); DEBUG(endl); } JMatrix4S A = getRandom(); TMatrixTSym R(4); R(0,0) = A.a00; R(0,1) = A.a01; R(0,2) = A.a02; R(0,3) = A.a03; R(1,0) = A.a10; R(1,1) = A.a11; R(1,2) = A.a12; R(1,3) = A.a13; R(2,0) = A.a20; R(2,1) = A.a21; R(2,2) = A.a22; R(2,3) = A.a23; R(3,0) = A.a30; R(3,1) = A.a31; R(3,2) = A.a32; R(3,3) = A.a33; DEBUG("Matrix A" << endl); DEBUG(A << endl); DEBUG("Determinant A " << A.getDeterminant() << endl); try { JMatrix4S B(A); t1.start(); for (int i = 11; i != 0; --i) { B.invert(); } t1.stop(); t2.start(); for (int i = 11; i != 0; --i) { R.Invert(); } t2.stop(); DEBUG("Matrix A^-1" << endl); DEBUG(B << endl); DEBUG("Determinant A^-1 = " << B.getDeterminant() << endl); JMatrix4D C(A * B); DEBUG("Matrix A x A^-1" << endl); DEBUG(C << endl); DEBUG("Determinant (A x A^-1) = " << C.getDeterminant() << endl); DEBUG("Determinant A x Determinant A^-1 = " << A.getDeterminant() * B.getDeterminant() << endl); DEBUG("A x A^-1 = I ? " << C.isIdentity(precision) << endl); if (!C.isIdentity(precision)) { ERROR("Matrix A x A^-1 /= I" << endl); } JMatrix4D D = C - JMatrix4D::getIdentity(); DEBUG("Matrix D = C - I" << endl); DEBUG(D << endl); ASSERT(C.isIdentity(precision)); } catch (const JException& error) { FATAL(error << endl); } } STATUS(endl); if (numberOfEvents > 0) { const double factor = 1.0; // / numberOfEvents; t1.print(cout, factor, micro_t); t2.print(cout, factor, micro_t); } return 0; }