Jpp  debug
the software that should make you happy
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

◆ main()

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 
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 }
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define ERROR(A)
Definition: JMessage.hh:66
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
General exception.
Definition: JException.hh:24
double getDeterminant() const
Get determinant of matrix.
3 x 3 symmetric matrix
Definition: JMatrix3S.hh:31
eigen_values getEigenValues(const double epsilon=1e-6) const
Get eigen values.
Definition: JMatrix3S.hh:227
Utility class to parse command line options.
Definition: JParser.hh:1714
static const double C
Physics constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
data_type v[N+1][M+1]
Definition: JPolint.hh:866
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:488