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

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file JMatrixNS.cc.

23 {
24  using namespace std;
25  using namespace JPP;
26 
27  int N;
28  double precision;
29  UInt_t seed;
30  int debug;
31 
32  try {
33 
34  JParser<> zap("Example program to test inversion of symmetric matrix.");
35 
36  zap['N'] = make_field(N);
37  zap['e'] = make_field(precision) = 1.0e-6;
38  zap['S'] = make_field(seed) = 0;
39  zap['d'] = make_field(debug) = 3;
40 
41  zap(argc, argv);
42  }
43  catch(const exception &error) {
44  FATAL(error.what() << endl);
45  }
46 
47 
48  gRandom->SetSeed(seed);
49 
50  const Double_t xmin = -1.0;
51  const Double_t xmax = +1.0;
52 
53  JMatrixNS A(N);
54 
55  for (int i = 0; i != N; ++i) {
56 
57  A(i,i) = gRandom->Uniform(xmin,xmax);
58 
59  for (int j = 0; j != i; ++j) {
60  A(j,i) = A(i,j) = gRandom->Uniform(xmin,xmax);
61  }
62  }
63 
64 
65  try {
66 
67  DEBUG("Matrix A" << endl);
68  DEBUG(A << endl);
69 
70  JMatrixNS B(A);
71 
72  JTimer timer;
73 
74  timer.start();
75 
76  B.invert();
77 
78  timer.stop();
79 
80  NOTICE("Elapsed time [us] " << setw(8) << timer.usec_wall << endl);
81  DEBUG("Matrix A^-1" << endl);
82  DEBUG(B << endl);
83 
84  JMatrixNS C(A);
85 
86  C.mul(B);
87 
88  DEBUG("Matrix A x A^-1" << endl);
89  DEBUG(C << endl);
90 
91  NOTICE("A x A^-1 = I ? " << C.isIdentity(precision) << endl);
92 
93  if (!C.isIdentity(precision)) {
94  ERROR("Matrix A x A^-1 /= I" << endl);
95  }
96 
97  ASSERT (C.isIdentity(precision));
98 
99  const double big = 1.0e5;
100 
101  for (int i = 0; i != N; ++i) {
102 
103  A(i,i) += big;
104 
105  timer.reset();
106  timer.start();
107 
108  B.update(i, big);
109 
110  timer.stop();
111 
112  NOTICE("Elapsed time [us] " << setw(8) << timer.usec_wall << endl);
113  NOTICE("Pivot " << setw(2) << i << '+' << big << ' ' << (JMatrixNS(A).mul(B).isIdentity(precision) ? "okay" : "error") << endl);
114 
115  ASSERT(JMatrixNS(A).mul(B).isIdentity(precision));
116 
117  A(i,i) -= big;
118 
119  B.update(i, -big);
120  }
121 
122  }
123  catch (const JException& error) {
124  FATAL(error << endl);
125  }
126 
127  return 0;
128 }
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
JTOOLS::j
int j
Definition: JPolint.hh:634
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