Jpp  19.1.0-rc.1
the software that should make you happy
Namespaces | Functions | Variables
JQuadrature.cc File Reference

Example program to test JTOOLS::JQuadrature. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include "JTools/JQuadrature.hh"
#include "JMath/JPolynome.hh"
#include "JMath/JGauss.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Namespaces

 GAUSS_LEGENDRE
 
 GAUSS_LAGUERRE
 
 GAUSS_HERMITE
 

Functions

double GAUSS_LAGUERRE::f1 (const double x)
 Function. More...
 
double GAUSS_LAGUERRE::F1 (const double x)
 Integral. More...
 
int main (int argc, char **argv)
 

Variables

const int GAUSS_LEGENDRE::numberOfPoints = 10
 
const double GAUSS_LEGENDRE::epsilon = 1.0e-12
 
const double GAUSS_LEGENDRE::xmin = -5.0
 
const double GAUSS_LEGENDRE::xmax = +3.0
 
const JPolynome GAUSS_LEGENDRE::f1 (1.0, 2.0, 3.0)
 Function. More...
 
const JPolynome GAUSS_LEGENDRE::F1 = f1.getIntegral()
 Integral. More...
 
const int GAUSS_LAGUERRE::numberOfPoints = 10
 
const double GAUSS_LAGUERRE::a = 1.0
 
const double GAUSS_LAGUERRE::epsilon = 1.0e-12
 
const double GAUSS_LAGUERRE::xmin = 0.0
 
const double GAUSS_LAGUERRE::xmax = +1.0e10
 
const int GAUSS_HERMITE::numberOfPoints = 10
 
const double GAUSS_HERMITE::epsilon = 1.0e-12
 
const double GAUSS_HERMITE::sigma [] = { 4.0, 0.5 }
 
const double GAUSS_HERMITE::xmin = -3.0 * sigma[0]
 
const double GAUSS_HERMITE::xmax = +3.0 * sigma[0]
 
const JGauss GAUSS_HERMITE::f1 (0.0, sigma[0])
 Function. More...
 
const JGauss GAUSS_HERMITE::F1 (0.0, hypot(sigma[0], sigma[1]))
 Integral. More...
 

Detailed Description

Example program to test JTOOLS::JQuadrature.

Author
mdejong

Definition in file JQuadrature.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 97 of file JQuadrature.cc.

98 {
99  using namespace std;
100  using namespace JPP;
101 
102  double precision;
103  int debug;
104 
105  try {
106 
107  JParser<> zap("Example program to test JTOOLS::JQuadrature.");
108 
109  zap['e'] = make_field(precision) = 1.0e-4;
110  zap['d'] = make_field(debug) = 3;
111 
112  zap(argc, argv);
113  }
114  catch(const exception &error) {
115  FATAL(error.what() << endl);
116  }
117 
118  {
119  using namespace GAUSS_LEGENDRE;
120 
121  double V = F1(xmax) - F1(xmin);
122 
124 
125  const double x0 = 0.5 * (xmax + xmin);
126  const double x1 = 0.5 * (xmax - xmin);
127 
128  double W = 0.0;
129 
130  for (JGaussLegendre::const_iterator i = engine.begin(); i != engine.end(); ++i) {
131 
132  const double x = x0 + i->getX() * x1;
133 
134  W += f1(x) * i->getY() * x1;
135  }
136 
137  DEBUG("integral analytical " << FIXED(9,5) << V << endl);
138  DEBUG("integral numerical " << FIXED(9,5) << W << endl);
139 
140  ASSERT(fabs(V - W) <= precision, "Test Gauss-Legendre integration.");
141  }
142  {
143  using namespace GAUSS_LAGUERRE;
144 
145  const double V = F1(xmax) - F1(xmin);
146 
148 
149  double W = 0.0;
150 
151  for (JGaussLaguerre::const_iterator i = engine.begin(); i != engine.end(); ++i) {
152 
153  const double x = i->getX();
154 
155  W += f1(x) * i->getY();
156  }
157 
158  DEBUG("integral analytical " << FIXED(9,5) << V << endl);
159  DEBUG("integral numerical " << FIXED(9,5) << W << endl);
160 
161  ASSERT(fabs(V - W) <= precision, "Test Gauss-Laguerre integration.");
162  }
163  {
164  using namespace GAUSS_HERMITE;
165 
167 
168  for (double x = xmin; x <= xmax; x += 0.05*(xmax - xmin)) {
169 
170  const double V = F1(x);
171 
172  double W = 0.0;
173 
174  for (JGaussHermite::const_iterator i = engine.begin(); i != engine.end(); ++i) {
175 
176  const double u = i->getX() * sigma[1] * sqrt(2.0);
177  const double v = i->getY() / sqrt(PI);
178 
179  W += f1(x + u) * v;
180  }
181 
182  DEBUG(FIXED(7,3) << x << ' ' << FIXED(9,5) << V << ' ' << FIXED(9,5) << W << endl);
183 
184  ASSERT(fabs(V - W) <= precision * V, "Test Gauss-Hermite integration.");
185  }
186  }
187 
188  return 0;
189 }
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
int numberOfPoints
Definition: JResultPDF.cc:22
Utility class to parse command line options.
Definition: JParser.hh:1714
Numerical integrator for .
Definition: JQuadrature.hh:251
Numerical integrator for .
Definition: JQuadrature.hh:174
Numerical integrator for .
Definition: JQuadrature.hh:113
const double xmin
Definition: JQuadrature.cc:76
const double epsilon
Definition: JQuadrature.cc:72
const double sigma[]
Definition: JQuadrature.cc:74
const double xmax
Definition: JQuadrature.cc:77
const double a
Definition: JQuadrature.cc:42
double f1(const double x)
Function.
Definition: JQuadrature.cc:51
double F1(const double x)
Integral.
Definition: JQuadrature.cc:59
static const double PI
Mathematical constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
double u[N+1]
Definition: JPolint.hh:865
data_type v[N+1][M+1]
Definition: JPolint.hh:866
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448