ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
KelvinFunctions.cxx
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // The functions in this class have been imported by Jason Detwiler (jasondet@gmail.com) from
3 // CodeCogs GNU General Public License Agreement
4 // Copyright (C) 2004-2005 CodeCogs, Zyba Ltd, Broadwood, Holford, TA5 1DU,
5 // England.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under
9 // the terms of the GNU General Public License as published by CodeCogs.
10 // You must retain a copy of this licence in all copies.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY
14 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A
16 // PARTICULAR PURPOSE. See the Adapted GNU General Public License for more
17 // details.
18 //
19 // *** THIS SOFTWARE CAN NOT BE USED FOR COMMERCIAL GAIN. ***
20 // ---------------------------------------------------------------------------------
21 
22 #include "Math/KelvinFunctions.h"
23 #include <math.h>
24 
25 
26 namespace ROOT {
27 namespace Math {
28 
29 double KelvinFunctions::fgMin = 20;
30 double KelvinFunctions::fgEpsilon = 1.e-20;
31 
32 double kSqrt2 = 1.4142135623730950488016887242097;
33 double kPi = 3.14159265358979323846;
34 double kEulerGamma = 0.577215664901532860606512090082402431042;
35 
36 
37 /* Begin_Html
38 <center><h2>KelvinFunctions</h2></center>
39 
40 <p>
41 This class calculates the Kelvin functions Ber(x), Bei(x), Ker(x),
42 Kei(x), and their first derivatives.
43 </p>
44 
45 End_Html */
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Begin_Latex
49 /// Ber(x) = Ber_{0}(x) = Re#left[J_{0}#left(x e^{3#pii/4}#right)#right]
50 /// End_Latex
51 /// where x is real, and Begin_Latex J_{0}(z) End_Latex is the zeroth-order Bessel
52 /// function of the first kind.
53 ///
54 /// If x < fgMin (=20), Ber(x) is computed according to its polynomial
55 /// approximation
56 /// Begin_Latex
57 /// Ber(x) = 1 + #sum_{n #geq 1}#frac{(-1)^{n}(x/2)^{4n}}{[(2n)!]^{2}}
58 /// End_Latex
59 /// For x > fgMin, Ber(x) is computed according to its asymptotic
60 /// expansion:
61 /// Begin_Latex
62 /// Ber(x) = #frac{e^{x/#sqrt{2}}}{#sqrt{2#pix}} [F1(x) cos#alpha + G1(x) sin#alpha] - #frac{1}{#pi}Kei(x)
63 /// End_Latex
64 /// where Begin_Latex #alpha = #frac{x}{#sqrt{2}} - #frac{#pi}{8} End_Latex.
65 /// See also F1(x) and G1(x).
66 ///
67 /// Begin_Macro
68 /// {
69 /// TCanvas *c = new TCanvas("c","c",0,0,500,300);
70 /// TF1 *fBer = new TF1("fBer","ROOT::Math::KelvinFunctions::Ber(x)",-10,10);
71 /// fBer->Draw();
72 /// return c;
73 /// }
74 /// End_Macro
75 
76 double KelvinFunctions::Ber(double x)
77 {
78  if (fabs(x) < fgEpsilon) return 1;
79 
80  if (fabs(x) < fgMin) {
81  double sum, factorial = 1, n = 1;
82  double term = 1, x_factor = x * x * x * x * 0.0625;
83 
84  sum = 1;
85 
86  do {
87  factorial = 4 * n * n * (2 * n - 1) * (2 * n - 1);
88  term *= (-1) / factorial * x_factor;
89  sum += term;
90  n += 1;
91  if (n > 1000) break;
92  } while (fabs(term) > fgEpsilon * sum);
93 
94  return sum;
95  } else {
96  double alpha = x / kSqrt2 - kPi / 8;
97  double value = F1(x) * cos(alpha) + G1(x) * sin(alpha);
98  value *= exp(x / kSqrt2) / sqrt(2 * kPi * x);
99  value -= Kei(x) / kPi;
100  return value;
101  }
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Begin_Latex
106 /// Bei(x) = Bei_{0}(x) = Im#left[J_{0}#left(x e^{3#pii/4}#right)#right]
107 /// End_Latex
108 /// where x is real, and Begin_Latex J_{0}(z) End_Latex is the zeroth-order Bessel
109 /// function of the first kind.
110 ///
111 /// If x < fgMin (=20), Bei(x) is computed according to its polynomial
112 /// approximation
113 /// Begin_Latex
114 /// Bei(x) = #sum_{n #geq 0}#frac{(-1)^{n}(x/2)^{4n+2}}{[(2n+1)!]^{2}}
115 /// End_Latex
116 /// For x > fgMin, Bei(x) is computed according to its asymptotic
117 /// expansion:
118 /// Begin_Latex
119 /// Bei(x) = #frac{e^{x/#sqrt{2}}}{#sqrt{2#pix}} [F1(x) sin#alpha + G1(x) cos#alpha] - #frac{1}{#pi}Ker(x)
120 /// End_Latex
121 /// where Begin_Latex #alpha = #frac{x}{#sqrt{2}} - #frac{#pi}{8} End_Latex
122 /// See also F1(x) and G1(x).
123 ///
124 /// Begin_Macro
125 /// {
126 /// TCanvas *c = new TCanvas("c","c",0,0,500,300);
127 /// TF1 *fBei = new TF1("fBei","ROOT::Math::KelvinFunctions::Bei(x)",-10,10);
128 /// fBei->Draw();
129 /// return c;
130 /// }
131 /// End_Macro
132 
133 double KelvinFunctions::Bei(double x)
134 {
135 
136  if (fabs(x) < fgEpsilon) return 0;
137 
138  if (fabs(x) < fgMin) {
139  double sum, factorial = 1, n = 1;
140  double term = x * x * 0.25, x_factor = term * term;
141 
142  sum = term;
143 
144  do {
145  factorial = 4 * n * n * (2 * n + 1) * (2 * n + 1);
146  term *= (-1) / factorial * x_factor;
147  sum += term;
148  n += 1;
149  if (n > 1000) break;
150  } while (fabs(term) > fgEpsilon * sum);
151 
152  return sum;
153  } else {
154  double alpha = x / kSqrt2 - kPi / 8;
155  double value = F1(x) * sin(alpha) + G1(x) * cos(alpha);
156  value *= exp(x / kSqrt2) / sqrt(2 * kPi * x);
157  value += Ker(x) / kPi;
158  return value;
159  }
160 }
161 
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Begin_Latex
165 /// Ker(x) = Ker_{0}(x) = Re#left[K_{0}#left(x e^{3#pii/4}#right)#right]
166 /// End_Latex
167 /// where x is real, and Begin_Latex K_{0}(z) End_Latex is the zeroth-order modified
168 /// Bessel function of the second kind.
169 ///
170 /// If x < fgMin (=20), Ker(x) is computed according to its polynomial
171 /// approximation
172 /// Begin_Latex
173 /// Ker(x) = -#left(ln #frac{|x|}{2} + #gamma#right) Ber(x) + #left(#frac{#pi}{4} - #delta#right) Bei(x) + #sum_{n #geq 0} #frac{(-1)^{n}}{[(2n)!]^{2}} H_{2n} #left(#frac{x}{2}#right)^{4n}
174 /// End_Latex
175 /// where Begin_Latex #gamma = 0.577215664... End_Latex is the Euler-Mascheroni constant,
176 /// Begin_Latex #delta = #pi End_Latex for x < 0 and is otherwise zero, and
177 /// Begin_Latex
178 /// H_{n} = #sum_{k = 1}^{n} #frac{1}{k}
179 /// End_Latex
180 /// For x > fgMin, Ker(x) is computed according to its asymptotic
181 /// expansion:
182 /// Begin_Latex
183 /// Ker(x) = #sqrt{#frac{#pi}{2x}} e^{-x/#sqrt{2}} [F2(x) cos#beta + G2(x) sin#beta]
184 /// End_Latex
185 /// where Begin_Latex #beta = #frac{x}{#sqrt{2}} + #frac{#pi}{8} End_Latex
186 /// See also F2(x) and G2(x).
187 ///
188 /// Begin_Macro
189 /// {
190 /// TCanvas *c = new TCanvas("c","c",0,0,500,300);
191 /// TF1 *fKer = new TF1("fKer","ROOT::Math::KelvinFunctions::Ker(x)",-10,10);
192 /// fKer->Draw();
193 /// return c;
194 /// }
195 /// End_Macro
196 
197 double KelvinFunctions::Ker(double x)
198 {
199  if (fabs(x) < fgEpsilon) return 1E+100;
200 
201  if (fabs(x) < fgMin) {
202  double term = 1, x_factor = x * x * x * x * 0.0625;
203  double factorial = 1, harmonic = 0, n = 1, sum;
204  double delta = 0;
205  if(x < 0) delta = kPi;
206 
207  sum = - (log(fabs(x) * 0.5) + kEulerGamma) * Ber(x) + (kPi * 0.25 - delta) * Bei(x);
208 
209  do {
210  factorial = 4 * n * n * (2 * n - 1) * (2 * n - 1);
211  term *= (-1) / factorial * x_factor;
212  harmonic += 1 / (2 * n - 1 ) + 1 / (2 * n);
213  sum += term * harmonic;
214  n += 1;
215  if (n > 1000) break;
216  } while (fabs(term * harmonic) > fgEpsilon * sum);
217 
218  return sum;
219  } else {
220  double beta = x / kSqrt2 + kPi / 8;
221  double value = F2(x) * cos(beta) - G2(x) * sin(beta);
222  value *= sqrt(kPi / (2 * x)) * exp(- x / kSqrt2);
223  return value;
224  }
225 }
226 
227 
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Begin_Latex
231 /// Kei(x) = Kei_{0}(x) = Im#left[K_{0}#left(x e^{3#pii/4}#right)#right]
232 /// End_Latex
233 /// where x is real, and Begin_Latex K_{0}(z) End_Latex is the zeroth-order modified
234 /// Bessel function of the second kind.
235 ///
236 /// If x < fgMin (=20), Kei(x) is computed according to its polynomial
237 /// approximation
238 /// Begin_Latex
239 /// Kei(x) = -#left(ln #frac{x}{2} + #gamma#right) Bei(x) - #left(#frac{#pi}{4} - #delta#right) Ber(x) + #sum_{n #geq 0} #frac{(-1)^{n}}{[(2n)!]^{2}} H_{2n} #left(#frac{x}{2}#right)^{4n+2}
240 /// End_Latex
241 /// where Begin_Latex #gamma = 0.577215664... End_Latex is the Euler-Mascheroni constant,
242 /// Begin_Latex #delta = #pi End_Latex for x < 0 and is otherwise zero, and
243 /// Begin_Latex
244 /// H_{n} = #sum_{k = 1}^{n} #frac{1}{k}
245 /// End_Latex
246 /// For x > fgMin, Kei(x) is computed according to its asymptotic
247 /// expansion:
248 /// Begin_Latex
249 /// Kei(x) = - #sqrt{#frac{#pi}{2x}} e^{-x/#sqrt{2}} [F2(x) sin#beta + G2(x) cos#beta]
250 /// End_Latex
251 /// where Begin_Latex #beta = #frac{x}{#sqrt{2}} + #frac{#pi}{8} End_Latex
252 /// See also F2(x) and G2(x).
253 ///
254 /// Begin_Macro
255 /// {
256 /// TCanvas *c = new TCanvas("c","c",0,0,500,300);
257 /// TF1 *fKei = new TF1("fKei","ROOT::Math::KelvinFunctions::Kei(x)",-10,10);
258 /// fKei->Draw();
259 /// return c;
260 /// }
261 /// End_Macro
262 
263 double KelvinFunctions::Kei(double x)
264 {
265  if (fabs(x) < fgEpsilon) return (-0.25 * kPi);
266 
267  if (fabs(x) < fgMin) {
268  double term = x * x * 0.25, x_factor = term * term;
269  double factorial = 1, harmonic = 1, n = 1, sum;
270  double delta = 0;
271  if(x < 0) delta = kPi;
272 
273  sum = term - (log(fabs(x) * 0.5) + kEulerGamma) * Bei(x) - (kPi * 0.25 - delta) * Ber(x);
274 
275  do {
276  factorial = 4 * n * n * (2 * n + 1) * (2 * n + 1);
277  term *= (-1) / factorial * x_factor;
278  harmonic += 1 / (2 * n) + 1 / (2 * n + 1);
279  sum += term * harmonic;
280  n += 1;
281  if (n > 1000) break;
282  } while (fabs(term * harmonic) > fgEpsilon * sum);
283 
284  return sum;
285  } else {
286  double beta = x / kSqrt2 + kPi / 8;
287  double value = - F2(x) * sin(beta) - G2(x) * cos(beta);
288  value *= sqrt(kPi / (2 * x)) * exp(- x / kSqrt2);
289  return value;
290  }
291 }
292 
293 
294 
295 ////////////////////////////////////////////////////////////////////////////////
296 /// Calculates the first derivative of Ber(x).
297 ///
298 /// If x < fgMin (=20), DBer(x) is computed according to the derivative of
299 /// the polynomial approximation of Ber(x). Otherwise it is computed
300 /// according to its asymptotic expansion
301 /// Begin_Latex
302 /// #frac{d}{dx} Ber(x) = M cos#left(#theta - #frac{#pi}{4}#right)
303 /// End_Latex
304 /// See also M(x) and Theta(x).
305 ///
306 /// Begin_Macro
307 /// {
308 /// TCanvas *c = new TCanvas("c","c",0,0,500,300);
309 /// TF1 *fDBer = new TF1("fDBer","ROOT::Math::KelvinFunctions::DBer(x)",-10,10);
310 /// fDBer->Draw();
311 /// return c;
312 /// }
313 /// End_Macro
314 
315 double KelvinFunctions::DBer(double x)
316 {
317  if (fabs(x) < fgEpsilon) return 0;
318 
319  if (fabs(x) < fgMin) {
320  double sum, factorial = 1, n = 1;
321  double term = - x * x * x * 0.0625, x_factor = - term * x;
322 
323  sum = term;
324 
325  do {
326  factorial = 4 * n * (n + 1) * (2 * n + 1) * (2 * n + 1);
327  term *= (-1) / factorial * x_factor;
328  sum += term;
329  n += 1;
330  if (n > 1000) break;
331  } while (fabs(term) > fgEpsilon * sum);
332 
333  return sum;
334  }
335  else return (M(x) * sin(Theta(x) - kPi / 4));
336 }
337 
338 
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// Calculates the first derivative of Bei(x).
342 ///
343 /// If x < fgMin (=20), DBei(x) is computed according to the derivative of
344 /// the polynomial approximation of Bei(x). Otherwise it is computed
345 /// according to its asymptotic expansion
346 /// Begin_Latex
347 /// #frac{d}{dx} Bei(x) = M sin#left(#theta - #frac{#pi}{4}#right)
348 /// End_Latex
349 /// See also M(x) and Theta(x).
350 ///
351 /// Begin_Macro
352 /// {
353 /// TCanvas *c = new TCanvas("c","c",0,0,500,300);
354 /// TF1 *fDBei = new TF1("fDBei","ROOT::Math::KelvinFunctions::DBei(x)",-10,10);
355 /// fDBei->Draw();
356 /// return c;
357 /// }
358 /// End_Macro
359 
360 double KelvinFunctions::DBei(double x)
361 {
362  if (fabs(x) < fgEpsilon) return 0;
363 
364  if (fabs(x) < fgMin) {
365  double sum, factorial = 1, n = 1;
366  double term = x * 0.5, x_factor = x * x * x * x * 0.0625;
367 
368  sum = term;
369 
370  do {
371  factorial = 4 * n * n * (2 * n - 1) * (2 * n + 1);
372  term *= (-1) * x_factor / factorial;
373  sum += term;
374  n += 1;
375  if (n > 1000) break;
376  } while (fabs(term) > fgEpsilon * sum);
377 
378  return sum;
379  }
380  else return (M(x) * cos(Theta(x) - kPi / 4));
381 }
382 
383 
384 
385 ////////////////////////////////////////////////////////////////////////////////
386 /// Calculates the first derivative of Ker(x).
387 ///
388 /// If x < fgMin (=20), DKer(x) is computed according to the derivative of
389 /// the polynomial approximation of Ker(x). Otherwise it is computed
390 /// according to its asymptotic expansion
391 /// Begin_Latex
392 /// #frac{d}{dx} Ker(x) = N cos#left(#phi - #frac{#pi}{4}#right)
393 /// End_Latex
394 /// See also N(x) and Phi(x).
395 ///
396 /// Begin_Macro
397 /// {
398 /// TCanvas *c = new TCanvas("c","c",0,0,500,300);
399 /// TF1 *fDKer = new TF1("fDKer","ROOT::Math::KelvinFunctions::DKer(x)",-10,10);
400 /// fDKer->Draw();
401 /// return c;
402 /// }
403 /// End_Macro
404 
405 double KelvinFunctions::DKer(double x)
406 {
407  if (fabs(x) < fgEpsilon) return -1E+100;
408 
409  if (fabs(x) < fgMin) {
410  double term = - x * x * x * 0.0625, x_factor = - term * x;
411  double factorial = 1, harmonic = 1.5, n = 1, sum;
412  double delta = 0;
413  if(x < 0) delta = kPi;
414 
415  sum = 1.5 * term - Ber(x) / x - (log(fabs(x) * 0.5) + kEulerGamma) * DBer(x) + (0.25 * kPi - delta) * DBei(x);
416 
417  do {
418  factorial = 4 * n * (n + 1) * (2 * n + 1) * (2 * n + 1);
419  term *= (-1) / factorial * x_factor;
420  harmonic += 1 / (2 * n + 1 ) + 1 / (2 * n + 2);
421  sum += term * harmonic;
422  n += 1;
423  if (n > 1000) break;
424  } while (fabs(term * harmonic) > fgEpsilon * sum);
425 
426  return sum;
427  }
428  else return N(x) * sin(Phi(x) - kPi / 4);
429 }
430 
431 
432 
433 ////////////////////////////////////////////////////////////////////////////////
434 /// Calculates the first derivative of Kei(x).
435 ///
436 /// If x < fgMin (=20), DKei(x) is computed according to the derivative of
437 /// the polynomial approximation of Kei(x). Otherwise it is computed
438 /// according to its asymptotic expansion
439 /// Begin_Latex
440 /// #frac{d}{dx} Kei(x) = N sin#left(#phi - #frac{#pi}{4}#right)
441 /// End_Latex
442 /// See also N(x) and Phi(x).
443 ///
444 /// Begin_Macro
445 /// {
446 /// TCanvas *c = new TCanvas("c","c",0,0,500,300);
447 /// TF1 *fDKei = new TF1("fDKei","ROOT::Math::KelvinFunctions::DKei(x)",-10,10);
448 /// fDKei->Draw();
449 /// return c;
450 /// }
451 /// End_Macro
452 
453 double KelvinFunctions::DKei(double x)
454 {
455  if (fabs(x) < fgEpsilon) return 0;
456 
457  if (fabs(x) < fgMin) {
458  double term = 0.5 * x, x_factor = x * x * x * x * 0.0625;
459  double factorial = 1, harmonic = 1, n = 1, sum;
460  double delta = 0;
461  if(x < 0) delta = kPi;
462 
463  sum = term - Bei(x) / x - (log(fabs(x) * 0.5) + kEulerGamma) * DBei(x) - (kPi * 0.25 - delta) * DBer(x);
464 
465  do {
466  factorial = 4 * n * n * (2 * n - 1) * (2 * n + 1);
467  term *= (-1) / factorial * x_factor;
468  harmonic += 1 / (2 * n) + 1 / (2 * n + 1);
469  sum += term * harmonic;
470  n += 1;
471  if (n > 1000) break;
472  } while (fabs(term * harmonic) > fgEpsilon * sum);
473 
474  return sum;
475  }
476  else return N(x) * cos(Phi(x) - kPi / 4);
477 }
478 
479 
480 
481 ////////////////////////////////////////////////////////////////////////////////
482 /// Utility function appearing in the calculations of the Kelvin
483 /// functions Bei(x) and Ber(x) (and their derivatives). F1(x) is given by
484 /// Begin_Latex
485 /// F1(x) = 1 + #sum_{n #geq 1} #frac{#prod_{m=1}^{n}(2m - 1)^{2}}{n! (8x)^{n}} cos#left(#frac{n#pi}{4}#right)
486 /// End_Latex
487 
488 double KelvinFunctions::F1(double x)
489 {
490  double sum, term;
491  double prod = 1, x_factor = 8 * x, factorial = 1, n = 2;
492 
493  sum = kSqrt2 / (16 * x);
494 
495  do {
496  factorial *= n;
497  prod *= (2 * n - 1) * (2 * n - 1);
498  x_factor *= 8 * x;
499  term = prod / (factorial * x_factor) * cos(0.25 * n * kPi);
500  sum += term;
501  n += 1;
502  if (n > 1000) break;
503  } while (fabs(term) > fgEpsilon * sum);
504 
505  sum += 1;
506 
507  return sum;
508 }
509 
510 ////////////////////////////////////////////////////////////////////////////////
511 /// Utility function appearing in the calculations of the Kelvin
512 /// functions Kei(x) and Ker(x) (and their derivatives). F2(x) is given by
513 /// Begin_Latex
514 /// F2(x) = 1 + #sum_{n #geq 1} (-1)^{n} #frac{#prod_{m=1}^{n}(2m - 1)^{2}}{n! (8x)^{n}} cos#left(#frac{n#pi}{4}#right)
515 /// End_Latex
516 
517 double KelvinFunctions::F2(double x)
518 {
519  double sum, term;
520  double prod = 1, x_factor = 8 * x, factorial = 1, n = 2;
521 
522  sum = kSqrt2 / (16 * x);
523 
524  do {
525  factorial *= - n;
526  prod *= (2 * n - 1) * (2 * n - 1);
527  x_factor *= 8 * x;
528  term = (prod / (factorial * x_factor)) * cos(0.25 * n * kPi);
529  sum += term;
530  n += 1;
531  if (n > 1000) break;
532  } while (fabs(term) > fgEpsilon * sum);
533 
534  sum += 1;
535 
536  return sum;
537 }
538 
539 
540 
541 ////////////////////////////////////////////////////////////////////////////////
542 /// Utility function appearing in the calculations of the Kelvin
543 /// functions Bei(x) and Ber(x) (and their derivatives). G1(x) is given by
544 /// Begin_Latex
545 /// G1(x) = #sum_{n #geq 1} #frac{#prod_{m=1}^{n}(2m - 1)^{2}}{n! (8x)^{n}} sin#left(#frac{n#pi}{4}#right)
546 /// End_Latex
547 
548 double KelvinFunctions::G1(double x)
549 {
550  double sum, term;
551  double prod = 1, x_factor = 8 * x, factorial = 1, n = 2;
552 
553  sum = kSqrt2 / (16 * x);
554 
555  do {
556  factorial *= n;
557  prod *= (2 * n - 1) * (2 * n - 1);
558  x_factor *= 8 * x;
559  term = prod / (factorial * x_factor) * sin(0.25 * n * kPi);
560  sum += term;
561  n += 1;
562  if (n > 1000) break;
563  } while (fabs(term) > fgEpsilon * sum);
564 
565  return sum;
566 }
567 
568 ////////////////////////////////////////////////////////////////////////////////
569 /// Utility function appearing in the calculations of the Kelvin
570 /// functions Kei(x) and Ker(x) (and their derivatives). G2(x) is given by
571 /// Begin_Latex
572 /// G2(x) = #sum_{n #geq 1} (-1)^{n} #frac{#prod_{m=1}^{n}(2m - 1)^{2}}{n! (8x)^{n}} sin#left(#frac{n#pi}{4}#right)
573 /// End_Latex
574 
575 double KelvinFunctions::G2(double x)
576 {
577  double sum, term;
578  double prod = 1, x_factor = 8 * x, factorial = 1, n = 2;
579 
580  sum = kSqrt2 / (16 * x);
581 
582  do {
583  factorial *= - n;
584  prod *= (2 * n - 1) * (2 * n - 1);
585  x_factor *= 8 * x;
586  term = prod / (factorial * x_factor) * sin(0.25 * n * kPi);
587  sum += term;
588  n += 1;
589  if (n > 1000) break;
590  } while (fabs(term) > fgEpsilon * sum);
591 
592  return sum;
593 }
594 
595 
596 
597 ////////////////////////////////////////////////////////////////////////////////
598 /// Utility function appearing in the asymptotic expansions of DBer(x) and
599 /// DBei(x). M(x) is given by
600 /// Begin_Latex
601 /// M(x) = #frac{e^{x/#sqrt{2}}}{#sqrt{2#pix}}#left(1 + #frac{1}{8#sqrt{2} x} + #frac{1}{256 x^{2}} - #frac{399}{6144#sqrt{2} x^{3}} + O#left(#frac{1}{x^{4}}#right)#right)
602 /// End_Latex
603 
604 double KelvinFunctions::M(double x)
605 {
606  double value = 1 + 1 / (8 * kSqrt2 * x) + 1 / (256 * x * x) - 399 / (6144 * kSqrt2 * x * x * x);
607  value *= exp(x / kSqrt2) / sqrt(2 * kPi * x);
608  return value;
609 }
610 
611 
612 
613 ////////////////////////////////////////////////////////////////////////////////
614 /// Utility function appearing in the asymptotic expansions of DBer(x) and
615 /// DBei(x). Begin_Latex #theta(x) #End_Latex is given by
616 /// Begin_Latex
617 /// #theta(x) = #frac{x}{#sqrt{2}} - #frac{#pi}{8} - #frac{1}{8#sqrt{2} x} - #frac{1}{16 x^{2}} - #frac{25}{384#sqrt{2} x^{3}} + O#left(#frac{1}{x^{5}}#right)
618 /// End_Latex
619 
620 double KelvinFunctions::Theta(double x)
621 {
622  double value = x / kSqrt2 - kPi / 8;
623  value -= 1 / (8 * kSqrt2 * x) + 1 / (16 * x * x) + 25 / (384 * kSqrt2 * x * x * x);
624  return value;
625 }
626 
627 
628 
629 ////////////////////////////////////////////////////////////////////////////////
630 /// Utility function appearing in the asymptotic expansions of DKer(x) and
631 /// DKei(x). (x) is given by
632 /// Begin_Latex
633 /// N(x) = #sqrt{#frac{#pi}{2x}} e^{-x/#sqrt{2}} #left(1 - #frac{1}{8#sqrt{2} x} + #frac{1}{256 x^{2}} + #frac{399}{6144#sqrt{2} x^{3}} + O#left(#frac{1}{x^{4}}#right)#right)
634 /// End_Latex
635 
636 double KelvinFunctions::N(double x)
637 {
638  double value = 1 - 1 / (8 * kSqrt2 * x) + 1 / (256 * x * x) + 399 / (6144 * kSqrt2 * x * x * x);
639  value *= exp(- x / kSqrt2) * sqrt(kPi / (2 * x));
640  return value;
641 }
642 
643 
644 
645 ////////////////////////////////////////////////////////////////////////////////
646 /// Utility function appearing in the asymptotic expansions of DKer(x) and
647 /// DKei(x). Begin_Latex #phi(x) #End_Latex is given by
648 /// Begin_Latex
649 /// #phi(x) = - #frac{x}{#sqrt{2}} - #frac{#pi}{8} + #frac{1}{8#sqrt{2} x} - #frac{1}{16 x^{2}} + #frac{25}{384#sqrt{2} x^{3}} + O#left(#frac{1}{x^{5}}#right)
650 /// End_Latex
651 
652 double KelvinFunctions::Phi(double x)
653 {
654  double value = - x / kSqrt2 - kPi / 8;
655  value += 1 / (8 * kSqrt2 * x) - 1 / (16 * x * x) + 25 / (384 * kSqrt2 * x * x * x);
656  return value;
657 }
658 
659 
660 } // namespace Math
661 } // namespace ROOT
662 
663 
664 
static double Ber(double x)
Begin_Latex Ber(x) = Ber_{0}(x) = Re::left[J_{0}#left(x e^{3#pii/4}#right)#right] End_Latex where x i...
static double DBei(double x)
Calculates the first derivative of Bei(x).
static const double kSqrt2
double kEulerGamma
double cos(double)
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
double beta(double x, double y)
Calculates the beta function.
static double F1(double x)
Utility function appearing in the calculations of the Kelvin functions Bei(x) and Ber(x) (and their d...
Double_t x[n]
Definition: legend1.C:17
static double G1(double x)
Utility function appearing in the calculations of the Kelvin functions Bei(x) and Ber(x) (and their d...
double sin(double)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
static double Kei(double x)
Begin_Latex Kei(x) = Kei_{0}(x) = Im::left[K_{0}#left(x e^{3#pii/4}#right)#right] End_Latex where x i...
static double DKer(double x)
Calculates the first derivative of Ker(x).
Double_t E()
Definition: TMath.h:54
static double M(double x)
Utility function appearing in the asymptotic expansions of DBer(x) and DBei(x).
static double Bei(double x)
Begin_Latex Bei(x) = Bei_{0}(x) = Im::left[J_{0}#left(x e^{3#pii/4}#right)#right] End_Latex where x i...
static double Theta(double x)
Utility function appearing in the asymptotic expansions of DBer(x) and DBei(x).
static double G2(double x)
Utility function appearing in the calculations of the Kelvin functions Kei(x) and Ker(x) (and their d...
static double DBer(double x)
Calculates the first derivative of Ber(x).
static double Phi(double x)
Utility function appearing in the asymptotic expansions of DKer(x) and DKei(x).
static double Ker(double x)
Begin_Latex Ker(x) = Ker_{0}(x) = Re::left[K_{0}#left(x e^{3#pii/4}#right)#right] End_Latex where x i...
static double DKei(double x)
Calculates the first derivative of Kei(x).
double exp(double)
static double F2(double x)
Utility function appearing in the calculations of the Kelvin functions Kei(x) and Ker(x) (and their d...
float value
Definition: math.cpp:443
const Int_t n
Definition: legend1.C:16
double log(double)
static double N(double x)
Utility function appearing in the asymptotic expansions of DKer(x) and DKei(x).