Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMatrix3S.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TRandom3.h"
6 
7 #include "JLang/JException.hh"
8 
9 #include "JMath/JMatrix3S.hh"
10 #include "JMath/JMathTestkit.hh"
11 
12 #include "Jeep/JParser.hh"
13 #include "Jeep/JMessage.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Example program to test inversion of symmetric matrix.
20  * \author mdejong
21  */
22 int main(int argc, char**argv)
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:1514
Exceptions.
int main(int argc, char *argv[])
Definition: Main.cc:15
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:1989
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
data_type v[N+1][M+1]
Definition: JPolint.hh:866
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