Function.
Integral.
Function.
Integral.
Function.
Integral.
25{
28
29 double precision;
31
32 try {
33
34 JParser<> zap(
"Example program to test JTOOLS::JQuadrature.");
35
38
39 zap(argc, argv);
40 }
41 catch(const exception &error) {
42 FATAL(error.what() << endl);
43 }
44
45 {
47 const double epsilon = 1.0e-12;
48
49 const double xmin = -5.0;
50 const double xmax = +3.0;
51
52
53
54
56
57
58
59
61
62 double V = F1(xmax) - F1(xmin);
63
65
66 const double x0 = 0.5 * (xmax + xmin);
67 const double x1 = 0.5 * (xmax - xmin);
68
69 double W = 0.0;
70
72
73 const double x = x0 + i->getX() * x1;
74
75 W += f1(x) * i->getY() * x1;
76 }
77
78 DEBUG(
"integral analytical " <<
FIXED(9,5) << V << endl);
79 DEBUG(
"integral numerical " <<
FIXED(9,5) << W << endl);
80
81 ASSERT(fabs(V - W) <= precision,
"Test Gauss-Legendre integration.");
82 }
83 {
85 const double a = 1.0;
86 const double epsilon = 1.0e-12;
87
88 const double xmin = 0.0;
89 const double xmax = +1.0e10;
90
91
92
93
94 const struct {
95 inline double operator()(const double x) const
96 {
97 return sin(x);
98 }
99 } f1;
100
101
102
103
104 const struct {
105 inline double operator()(const double x) const
106 {
107
108
109 return -0.5 * exp(-x) * (
x*sin(x) + (
x + 1.0)*cos(x));
110 }
111 } F1;
112
113 const double V = F1(xmax) - F1(xmin);
114
116
117 double W = 0.0;
118
120
121 const double x = i->getX();
122
123 W += f1(x) * i->getY();
124 }
125
126 DEBUG(
"integral analytical " <<
FIXED(9,5) << V << endl);
127 DEBUG(
"integral numerical " <<
FIXED(9,5) << W << endl);
128
129 ASSERT(fabs(V - W) <= precision,
"Test Gauss-Laguerre integration.");
130 }
131 {
133 const double epsilon = 1.0e-12;
134
135 const double sigma[] = { 4.0, 0.5 };
136
137 const double xmin = -3.0 * sigma[0];
138 const double xmax = +3.0 * sigma[0];
139
140
141
142
143 const JGauss f1(0.0, sigma[0]);
144
145
146
147
148 const JGauss F1(0.0, hypot(sigma[0], sigma[1]));
149
151
152 for (
double x = xmin;
x <= xmax;
x += 0.05*(xmax - xmin)) {
153
154 const double V = F1(x);
155
156 double W = 0.0;
157
159
160 const double u = i->getX() * sigma[1] * sqrt(2.0);
161 const double v = i->getY() / sqrt(PI);
162
163 W += f1(x + u) * v;
164 }
165
167
168 ASSERT(fabs(V - W) <= precision * V,
"Test Gauss-Hermite integration.");
169 }
170 }
171 {
173
174 const double a = -1.5;
175 const double g = 0.924;
176
177 const double V = 1.0;
178
180
181 double W = 0.0;
182
184
185 const double x = i->getX();
186
188 }
189
190 DEBUG(
"integral analytical " <<
FIXED(9,5) << V << endl);
191 DEBUG(
"integral numerical " <<
FIXED(9,5) << W << endl);
192
193 ASSERT(fabs(V - W) <= precision,
"Test Henyey-Greenstein integration.");
194 }
195 {
197
198 const double a = 0.835;
199
200 const double V = 1.0;
201
203
204 double W = 0.0;
205
207
208 const double x = i->getX();
209
210 W +=
rayleigh(a,x) * i->getY() * 2*PI;
211 }
212
213 DEBUG(
"integral analytical " <<
FIXED(9,5) << V << endl);
214 DEBUG(
"integral numerical " <<
FIXED(9,5) << W << endl);
215
216 ASSERT(fabs(V - W) <= precision,
"Test Rayleigh integration.");
217 }
218
219 return 0;
220}
#define DEBUG(A)
Message macros.
#define ASSERT(A,...)
Assert macro.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Utility class to parse command line options.
double henyey_greenstein(const double g, const double x)
Auxiliary method to describe light scattering in water (Henyey-Greenstein).
double rayleigh(const double a, const double x)
Auxiliary method to describe light scattering in water (Rayleigh).
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Recursive template class for polynomial function.
double getIntegral(const double x) const
Integral value.