Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
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

namespace  GAUSS_LEGENDRE
 
namespace  GAUSS_LAGUERRE
 
namespace  GAUSS_HERMITE
 

Functions

double GAUSS_LAGUERRE::f1 (const double x)
 Function.
 
double GAUSS_LAGUERRE::F1 (const double x)
 Integral.
 
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.
 
const JPolynome GAUSS_LEGENDRE::F1 = f1.getIntegral()
 Integral.
 
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.
 
const JGauss GAUSS_HERMITE::F1 (0.0, hypot(sigma[0], sigma[1]))
 Integral.
 

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
123 JGaussLegendre engine(numberOfPoints, epsilon);
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
147 JGaussLaguerre engine(numberOfPoints, a, epsilon);
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
166 JGaussHermite engine(numberOfPoints, epsilon);
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:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int numberOfPoints
Definition JResultPDF.cc:22
Utility class to parse command line options.
Definition JParser.hh:1698
container_type::const_iterator const_iterator
Numerical integrator for .
Numerical integrator for .
Numerical integrator for .
const double sigma[]
const JPolynome F1
Integral.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
const double xmax
const double xmin
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448