Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMatrixNS.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/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

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  size_t numberOfInversions;
30  UInt_t seed;
31  int debug;
32 
33  try {
34 
35  JParser<> zap("Example program to test inversion of symmetric matrix.");
36 
37  zap['N'] = make_field(N);
38  zap['e'] = make_field(precision) = 1.0e-6;
39  zap['n'] = make_field(numberOfInversions) = 1;
40  zap['S'] = make_field(seed) = 0;
41  zap['d'] = make_field(debug) = 3;
42 
43  zap(argc, argv);
44  }
45  catch(const exception &error) {
46  FATAL(error.what() << endl);
47  }
48 
49 
50  gRandom->SetSeed(seed);
51 
52  const Double_t xmin = -1.0;
53  const Double_t xmax = +1.0;
54 
55  JMatrixNS A(N);
56 
57  for (int i = 0; i != N; ++i) {
58 
59  A(i,i) = gRandom->Uniform(xmin,xmax);
60 
61  for (int j = 0; j != i; ++j) {
62  A(j,i) = A(i,j) = gRandom->Uniform(xmin,xmax);
63  }
64  }
65 
66 
67  try {
68 
69  DEBUG("Matrix A" << endl);
70  DEBUG(A << endl);
71 
72  JMatrixNS B(A);
73 
74  JTimer timer;
75 
76  timer.start();
77 
78  for (size_t i = 2*(numberOfInversions/2) + 1; i != 0; --i) {
79  B.invert();
80  }
81 
82  timer.stop();
83 
84  NOTICE("Elapsed time [us] " << setw(8) << timer.usec_wall << endl);
85  DEBUG("Matrix A^-1" << endl);
86  DEBUG(B << endl);
87 
88  JMatrixNS C(A);
89 
90  C.mul(B);
91 
92  DEBUG("Matrix A x A^-1" << endl);
93  DEBUG(C << endl);
94 
95  NOTICE("A x A^-1 = I ? " << C.isIdentity(precision) << endl);
96 
97  if (!C.isIdentity(precision)) {
98  ERROR("Matrix A x A^-1 /= I" << endl);
99  }
100 
101  ASSERT (C.isIdentity(precision));
102 
103  const double big = 1.0e5;
104 
105  for (int i = 0; i != N; ++i) {
106 
107  A(i,i) += big;
108 
109  timer.reset();
110  timer.start();
111 
112  B.update(i, big);
113 
114  timer.stop();
115 
116  NOTICE("Elapsed time [us] " << setw(8) << timer.usec_wall << endl);
117  NOTICE("Pivot " << setw(2) << i << '+' << big << ' ' << (JMatrixNS(A).mul(B).isIdentity(precision) ? "okay" : "error") << endl);
118 
119  ASSERT(JMatrixNS(A).mul(B).isIdentity(precision));
120 
121  A(i,i) -= big;
122 
123  B.update(i, -big);
124  }
125 
126  }
127  catch (const JException& error) {
128  FATAL(error << endl);
129  }
130 
131  return 0;
132 }
Utility class to parse command line options.
Definition: JParser.hh:1493
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
int j
Definition: JPolint.hh:634
static const double C
Speed of light in vacuum [m/ns].
Definition: JConstants.hh:22
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62