Jpp
Functions
JMatrix1S.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JLang/JException.hh"
#include "JMath/JMatrix1S.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 JMatrix1S.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file JMatrix1S.cc.

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  JMatrix1D A(gRandom->Uniform(xmin,xmax));
50 
51 
52  DEBUG("Matrix A" << endl);
53  DEBUG(A << endl);
54 
55  NOTICE("Determinant A " << A.getDeterminant() << endl);
56 
57  try {
58 
59  JMatrix1S B(A);
60 
61  B.invert();
62 
63  DEBUG("Matrix A^-1" << endl);
64  DEBUG(B << endl);
65 
66  NOTICE("Determinant A^-1 = " << B.getDeterminant() << endl);
67 
68  JMatrix1D C(A * B);
69 
70  DEBUG("Matrix A x A^-1" << endl);
71  DEBUG(C << endl);
72 
73  NOTICE("Determinant (A x A^-1) = " << C.getDeterminant() << endl);
74  NOTICE("Determinant A x Determinant A^-1 = " << A.getDeterminant() * B.getDeterminant() << endl);
75  NOTICE("A x A^-1 = I ? " << C.isIdentity(precision) << endl);
76 
77  if (!C.isIdentity(precision)) {
78  ERROR("Matrix A x A^-1 /= I" << endl);
79  }
80 
81  JMatrix1D D = C - JMatrix1D::getIdentity();
82 
83  DEBUG("Matrix D = C - I" << endl);
84  DEBUG(D << endl);
85 
86  ASSERT(C.isIdentity(precision));
87  }
88  catch (const JException& error) {
89  FATAL(error << endl);
90  }
91 
92  return 0;
93 }
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JTOOLS::C
static const double C
Speed of light in vacuum [m/ns].
Definition: JConstants.hh:22
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
ERROR
#define ERROR(A)
Definition: JMessage.hh:66
debug
int debug
debug level
Definition: JSirene.cc:59
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67