// -*- C++ -*- // $Id: testInversion.cc,v 1.2 2003/08/13 20:00:12 garren Exp $ // // This file is a part of CLHEP - a Class Library for High Energy Physics. // // This is a collection of parts of programs that are useful // for testing matrix inversion algorithms // 9/97, Mario Stanke #include #include #include "CLHEP/Matrix/defs.h" #include "CLHEP/Matrix/Matrix.h" #include "CLHEP/Matrix/SymMatrix.h" #include "CLHEP/Matrix/DiagMatrix.h" using std::cout; using std::endl; using namespace CLHEP; int main() { //int n , i, j, k, ierr1, ierr2; int n, j, ierr1, ierr2; time_t zeit1, zeit2; // ****compare the speed of inversion algorithms HepSymMatrix A(5,1); // for (j=1;j <= 100; j++) // for (k=1; k<=j; k++) // A(j,k)=rand()%9-5; A(1,1)=6; A(1,2)=.8545; A(1,3)=-.684651; A(1,4)=.372547; A(1,5)=.68151; //A(1,6)=.068151; A(2,2)=4; A(2,3)=.5151; A(2,4)=.5151; A(2,5)=.651651; //A(2,6)=.9651651; A(3,3)=5; A(3,4)=.3; A(3,5)=.363; //A(3,6)=.7363; A(4,4)=-3; A(4,5)=-.23753; //A(4,6)=-.23753; A(5,5)=-5; //A(5,6)=-2; //A(6,6)=-3; HepSymMatrix B(A); HepSymMatrix D(A); HepSymMatrix C(5,0); HepMatrix M(A); cout << "M inverse" << M.inverse(ierr2) << endl; C = B.inverse(ierr1); D.invert(ierr2); cout << "B " << B << endl; cout << "B inverse" << C << endl; #ifndef INSTALLATION_CHECK cout << "B * inverse" << B * C << endl; #endif cout << "ierr1: " << ierr1 << endl; cout << "D * inverse" << D * C << endl; cout << "ierr2: " << ierr2 << endl; cout << "M inverse" << M.inverse(ierr2) << endl; #ifndef INSTALLATION_CHECK cout << "M * inverse" << M * M.inverse(ierr2)<< endl; #endif cout << "ierr2: " << ierr2 << endl; #ifndef INSTALLATION_CHECK n = 100000; #else n = 10; #endif zeit1 = time(NULL); cout << "Executing " << n << " inversions ..." << endl; for (j=0; j 1e-4) { cout << "bunch failed to invert but did not indicate" << endl; cout << C << endl; cout << "B " << B << endl; cout << "B*C" << B*C << endl; cout << "M*C" << M*C << endl; cout << "determinant " << C.determinant() << endl; cout << "dist2 " << dist2 << endl; cout << "dist1 " << dist1 << endl; cout << "ierr2 " << ierr2 < 1e-4 && ierr2==0) { cout << "old failed to invert but did not indicate" << endl; cout << C << endl; cout << "B*C" << B*C << endl; cout << "M*C" << M*C << endl; cout << "determinant " << C.determinant() << endl; cout << "ierr2 " << ierr2 <