Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMatrix2S.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 #include "JMath/JMatrix2S.hh"
9 
10 #include "Jeep/JParser.hh"
11 #include "Jeep/JMessage.hh"
12 
13 
14 /**
15  * \file
16  *
17  * Example program to test inversion of symmetric matrix.
18  * \author mdejong
19  */
20 int main(int argc, char**argv)
21 {
22  using namespace std;
23 
24  double precision;
25  int debug;
26 
27  try {
28 
29  JParser<> zap("Example program to test inversion of symmetric matrix.");
30 
31  zap['e'] = make_field(precision) = 1.0e-6;
32  zap['d'] = make_field(debug) = 3;
33 
34  zap(argc, argv);
35  }
36  catch(const exception &error) {
37  FATAL(error.what() << endl);
38  }
39 
40  using namespace JPP;
41 
42 
43  gRandom->SetSeed(0);
44 
45  const Double_t xmin = -1.0;
46  const Double_t xmax = +1.0;
47 
48 
49  JMatrix2D A(gRandom->Uniform(xmin,xmax), 0.0,
50  gRandom->Uniform(xmin,xmax), gRandom->Uniform(xmin,xmax));
51 
52  A.a01 = A.a10;
53 
54 
55  DEBUG("Matrix A" << endl);
56  DEBUG(A << endl);
57 
58  NOTICE("Determinant A " << A.getDeterminant() << endl);
59 
60  try {
61 
62  JMatrix2S B(A);
63 
64  B.invert();
65 
66  DEBUG("Matrix A^-1" << endl);
67  DEBUG(B << endl);
68 
69  NOTICE("Determinant A^-1 = " << B.getDeterminant() << endl);
70 
71  JMatrix2D C(A * B);
72 
73  DEBUG("Matrix A x A^-1" << endl);
74  DEBUG(C << endl);
75 
76  NOTICE("Determinant (A x A^-1) = " << C.getDeterminant() << endl);
77  NOTICE("Determinant A x Determinant A^-1 = " << A.getDeterminant() * B.getDeterminant() << endl);
78  NOTICE("A x A^-1 = I ? " << C.isIdentity(precision) << endl);
79 
80  if (!C.isIdentity(precision)) {
81  ERROR("Matrix A x A^-1 /= I" << endl);
82  }
83 
84  JMatrix2D D = C - JMatrix2D::getIdentity();
85 
86  DEBUG("Matrix D = C - I" << endl);
87  DEBUG(D << endl);
88 
89  ASSERT(C.isIdentity(precision));
90  }
91  catch (const JException& error) {
92  FATAL(error << endl);
93  }
94 
95  return 0;
96 }
Utility class to parse command line options.
Definition: JParser.hh:1410
Exceptions.
#define ASSERT(A)
Assert macro.
Definition: JMessage.hh:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
#define NOTICE(A)
Definition: JMessage.hh:62
#define ERROR(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
static const double C
Speed of light in vacuum [m/ns].
Definition: JConstants.hh:22
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
int main(int argc, char *argv[])
Definition: Main.cpp:15