Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.ALGLIB-2.5.0/ALGLIB-2.5.0/dawson.cs @ 5190

Last change on this file since 5190 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 5.4 KB
Line 
1/*************************************************************************
2Cephes Math Library Release 2.8:  June, 2000
3Copyright by Stephen L. Moshier
4
5Contributors:
6    * Sergey Bochkanov (ALGLIB project). Translation from C to
7      pseudocode.
8
9See subroutines comments for additional copyrights.
10
11>>> SOURCE LICENSE >>>
12This program is free software; you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation (www.fsf.org); either version 2 of the
15License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20GNU General Public License for more details.
21
22A copy of the GNU General Public License is available at
23http://www.fsf.org/licensing/licenses
24
25>>> END OF LICENSE >>>
26*************************************************************************/
27
28
29namespace alglib {
30  public class dawson {
31    /*************************************************************************
32    Dawson's Integral
33
34    Approximates the integral
35
36                                x
37                                -
38                         2     | |        2
39     dawsn(x)  =  exp( -x  )   |    exp( t  ) dt
40                             | |
41                              -
42                              0
43
44    Three different rational approximations are employed, for
45    the intervals 0 to 3.25; 3.25 to 6.25; and 6.25 up.
46
47    ACCURACY:
48
49                         Relative error:
50    arithmetic   domain     # trials      peak         rms
51       IEEE      0,10        10000       6.9e-16     1.0e-16
52
53    Cephes Math Library Release 2.8:  June, 2000
54    Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
55    *************************************************************************/
56    public static double dawsonintegral(double x) {
57      double result = 0;
58      double x2 = 0;
59      double y = 0;
60      int sg = 0;
61      double an = 0;
62      double ad = 0;
63      double bn = 0;
64      double bd = 0;
65      double cn = 0;
66      double cd = 0;
67
68      sg = 1;
69      if ((double)(x) < (double)(0)) {
70        sg = -1;
71        x = -x;
72      }
73      if ((double)(x) < (double)(3.25)) {
74        x2 = x * x;
75        an = 1.13681498971755972054E-11;
76        an = an * x2 + 8.49262267667473811108E-10;
77        an = an * x2 + 1.94434204175553054283E-8;
78        an = an * x2 + 9.53151741254484363489E-7;
79        an = an * x2 + 3.07828309874913200438E-6;
80        an = an * x2 + 3.52513368520288738649E-4;
81        an = an * x2 + -8.50149846724410912031E-4;
82        an = an * x2 + 4.22618223005546594270E-2;
83        an = an * x2 + -9.17480371773452345351E-2;
84        an = an * x2 + 9.99999999999999994612E-1;
85        ad = 2.40372073066762605484E-11;
86        ad = ad * x2 + 1.48864681368493396752E-9;
87        ad = ad * x2 + 5.21265281010541664570E-8;
88        ad = ad * x2 + 1.27258478273186970203E-6;
89        ad = ad * x2 + 2.32490249820789513991E-5;
90        ad = ad * x2 + 3.25524741826057911661E-4;
91        ad = ad * x2 + 3.48805814657162590916E-3;
92        ad = ad * x2 + 2.79448531198828973716E-2;
93        ad = ad * x2 + 1.58874241960120565368E-1;
94        ad = ad * x2 + 5.74918629489320327824E-1;
95        ad = ad * x2 + 1.00000000000000000539E0;
96        y = x * an / ad;
97        result = sg * y;
98        return result;
99      }
100      x2 = 1.0 / (x * x);
101      if ((double)(x) < (double)(6.25)) {
102        bn = 5.08955156417900903354E-1;
103        bn = bn * x2 - 2.44754418142697847934E-1;
104        bn = bn * x2 + 9.41512335303534411857E-2;
105        bn = bn * x2 - 2.18711255142039025206E-2;
106        bn = bn * x2 + 3.66207612329569181322E-3;
107        bn = bn * x2 - 4.23209114460388756528E-4;
108        bn = bn * x2 + 3.59641304793896631888E-5;
109        bn = bn * x2 - 2.14640351719968974225E-6;
110        bn = bn * x2 + 9.10010780076391431042E-8;
111        bn = bn * x2 - 2.40274520828250956942E-9;
112        bn = bn * x2 + 3.59233385440928410398E-11;
113        bd = 1.00000000000000000000E0;
114        bd = bd * x2 - 6.31839869873368190192E-1;
115        bd = bd * x2 + 2.36706788228248691528E-1;
116        bd = bd * x2 - 5.31806367003223277662E-2;
117        bd = bd * x2 + 8.48041718586295374409E-3;
118        bd = bd * x2 - 9.47996768486665330168E-4;
119        bd = bd * x2 + 7.81025592944552338085E-5;
120        bd = bd * x2 - 4.55875153252442634831E-6;
121        bd = bd * x2 + 1.89100358111421846170E-7;
122        bd = bd * x2 - 4.91324691331920606875E-9;
123        bd = bd * x2 + 7.18466403235734541950E-11;
124        y = 1.0 / x + x2 * bn / (bd * x);
125        result = sg * 0.5 * y;
126        return result;
127      }
128      if ((double)(x) > (double)(1.0E9)) {
129        result = sg * 0.5 / x;
130        return result;
131      }
132      cn = -5.90592860534773254987E-1;
133      cn = cn * x2 + 6.29235242724368800674E-1;
134      cn = cn * x2 - 1.72858975380388136411E-1;
135      cn = cn * x2 + 1.64837047825189632310E-2;
136      cn = cn * x2 - 4.86827613020462700845E-4;
137      cd = 1.00000000000000000000E0;
138      cd = cd * x2 - 2.69820057197544900361E0;
139      cd = cd * x2 + 1.73270799045947845857E0;
140      cd = cd * x2 - 3.93708582281939493482E-1;
141      cd = cd * x2 + 3.44278924041233391079E-2;
142      cd = cd * x2 - 9.73655226040941223894E-4;
143      y = 1.0 / x + x2 * cn / (cd * x);
144      result = sg * 0.5 * y;
145      return result;
146    }
147  }
148}
Note: See TracBrowser for help on using the repository browser.