Jpp  17.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMatrix3S.cc File Reference

Example program to test inversion of symmetric matrix. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JLang/JException.hh"
#include "JMath/JMatrix3S.hh"
#include "JMath/JMathTestkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test inversion of symmetric matrix.

Author
mdejong

Definition in file JMatrix3S.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file JMatrix3S.cc.

23 {
24  using namespace std;
25  using namespace JPP;
26 
27  double precision;
28  int debug;
29 
30  try {
31 
32  JParser<> zap("Example program to test inversion and eigenvalue decomposition of 3D symmetric matrix.");
33 
34  zap['e'] = make_field(precision) = 1.0e-6;
35  zap['d'] = make_field(debug) = 3;
36 
37  zap(argc, argv);
38  }
39  catch(const exception &error) {
40  FATAL(error.what() << endl);
41  }
42 
43 
44  gRandom->SetSeed(0);
45 
46 
47  JMatrix3S A = getRandom<JMatrix3S>();
48 
49  DEBUG("Matrix A" << endl);
50  DEBUG(A << endl);
51 
52  NOTICE("Determinant A " << A.getDeterminant() << endl);
53 
54  try {
55 
56  JMatrix3S B(A);
57 
58  B.invert();
59 
60  DEBUG("Matrix A^-1" << endl);
61  DEBUG(B << endl);
62 
63  NOTICE("Determinant A^-1 = " << B.getDeterminant() << endl);
64 
65  JMatrix3D C(A * B);
66 
67  DEBUG("Matrix A x A^-1" << endl);
68  DEBUG(C << endl);
69 
70  NOTICE("Determinant (A x A^-1) = " << C.getDeterminant() << endl);
71  NOTICE("Determinant A x Determinant A^-1 = " << A.getDeterminant() * B.getDeterminant() << endl);
72  NOTICE("A x A^-1 = I ? " << C.isIdentity(precision) << endl);
73 
74  if (!C.isIdentity(precision)) {
75  ERROR("Matrix A x A^-1 /= I" << endl);
76  }
77 
78  JMatrix3D D = C - JMatrix3D::getIdentity();
79 
80  DEBUG("Matrix D = C - I" << endl);
81  DEBUG(D << endl);
82 
83  DEBUG("Eigenvalues v of matrix A" << endl);
84 
85  JMatrix3S::eigen_values v = A.getEigenValues();
86 
87  for (JMatrix3S::eigen_values::const_iterator i = v.cbegin(); i != v.cend(); ++i) {
88  DEBUG(SCIENTIFIC(12,3) << *i);
89  }
90 
91  DEBUG(endl);
92 
93  ASSERT(fabs(v[0]) > fabs(v[1]));
94  ASSERT(fabs(v[1]) > fabs(v[2]));
95 
96  ASSERT(JMatrix3S(A).sub(v[0] * JMatrix3D::getIdentity()).getDeterminant() < precision);
97  ASSERT(JMatrix3S(A).sub(v[1] * JMatrix3D::getIdentity()).getDeterminant() < precision);
98  ASSERT(JMatrix3S(A).sub(v[2] * JMatrix3D::getIdentity()).getDeterminant() < precision);
99 
100  ASSERT(C.isIdentity(precision));
101  }
102  catch (const JException& error) {
103  FATAL(error << endl);
104  }
105 
106  return 0;
107 }
Utility class to parse command line options.
Definition: JParser.hh:1517
static const double C
Physics constants.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
data_type v[N+1][M+1]
Definition: JPolint.hh:777
source $JPP_DIR setenv csh $JPP_DIR &dev null eval JShellParser o a A
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62