alglib 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/Manifest.txt +253 -0
- data/README.txt +33 -0
- data/Rakefile +27 -0
- data/ext/Rakefile +24 -0
- data/ext/alglib.i +24 -0
- data/ext/alglib/Makefile +157 -0
- data/ext/alglib/airyf.cpp +372 -0
- data/ext/alglib/airyf.h +81 -0
- data/ext/alglib/alglib.cpp +8558 -0
- data/ext/alglib/alglib_util.cpp +19 -0
- data/ext/alglib/alglib_util.h +14 -0
- data/ext/alglib/ap.cpp +877 -0
- data/ext/alglib/ap.english.html +364 -0
- data/ext/alglib/ap.h +666 -0
- data/ext/alglib/ap.russian.html +442 -0
- data/ext/alglib/apvt.h +754 -0
- data/ext/alglib/bdss.cpp +1500 -0
- data/ext/alglib/bdss.h +251 -0
- data/ext/alglib/bdsvd.cpp +1339 -0
- data/ext/alglib/bdsvd.h +164 -0
- data/ext/alglib/bessel.cpp +1226 -0
- data/ext/alglib/bessel.h +331 -0
- data/ext/alglib/betaf.cpp +105 -0
- data/ext/alglib/betaf.h +74 -0
- data/ext/alglib/bidiagonal.cpp +1328 -0
- data/ext/alglib/bidiagonal.h +350 -0
- data/ext/alglib/binomialdistr.cpp +247 -0
- data/ext/alglib/binomialdistr.h +153 -0
- data/ext/alglib/blas.cpp +576 -0
- data/ext/alglib/blas.h +132 -0
- data/ext/alglib/cblas.cpp +226 -0
- data/ext/alglib/cblas.h +57 -0
- data/ext/alglib/cdet.cpp +138 -0
- data/ext/alglib/cdet.h +92 -0
- data/ext/alglib/chebyshev.cpp +216 -0
- data/ext/alglib/chebyshev.h +76 -0
- data/ext/alglib/chisquaredistr.cpp +157 -0
- data/ext/alglib/chisquaredistr.h +144 -0
- data/ext/alglib/cholesky.cpp +285 -0
- data/ext/alglib/cholesky.h +86 -0
- data/ext/alglib/cinverse.cpp +298 -0
- data/ext/alglib/cinverse.h +111 -0
- data/ext/alglib/clu.cpp +337 -0
- data/ext/alglib/clu.h +120 -0
- data/ext/alglib/correlation.cpp +280 -0
- data/ext/alglib/correlation.h +77 -0
- data/ext/alglib/correlationtests.cpp +726 -0
- data/ext/alglib/correlationtests.h +134 -0
- data/ext/alglib/crcond.cpp +826 -0
- data/ext/alglib/crcond.h +148 -0
- data/ext/alglib/creflections.cpp +310 -0
- data/ext/alglib/creflections.h +165 -0
- data/ext/alglib/csolve.cpp +312 -0
- data/ext/alglib/csolve.h +99 -0
- data/ext/alglib/ctrinverse.cpp +387 -0
- data/ext/alglib/ctrinverse.h +98 -0
- data/ext/alglib/ctrlinsolve.cpp +297 -0
- data/ext/alglib/ctrlinsolve.h +81 -0
- data/ext/alglib/dawson.cpp +234 -0
- data/ext/alglib/dawson.h +74 -0
- data/ext/alglib/descriptivestatistics.cpp +436 -0
- data/ext/alglib/descriptivestatistics.h +112 -0
- data/ext/alglib/det.cpp +140 -0
- data/ext/alglib/det.h +94 -0
- data/ext/alglib/dforest.cpp +1819 -0
- data/ext/alglib/dforest.h +316 -0
- data/ext/alglib/elliptic.cpp +497 -0
- data/ext/alglib/elliptic.h +217 -0
- data/ext/alglib/estnorm.cpp +429 -0
- data/ext/alglib/estnorm.h +107 -0
- data/ext/alglib/expintegrals.cpp +422 -0
- data/ext/alglib/expintegrals.h +108 -0
- data/ext/alglib/faq.english.html +258 -0
- data/ext/alglib/faq.russian.html +272 -0
- data/ext/alglib/fdistr.cpp +202 -0
- data/ext/alglib/fdistr.h +163 -0
- data/ext/alglib/fresnel.cpp +211 -0
- data/ext/alglib/fresnel.h +91 -0
- data/ext/alglib/gammaf.cpp +338 -0
- data/ext/alglib/gammaf.h +104 -0
- data/ext/alglib/gqgengauss.cpp +235 -0
- data/ext/alglib/gqgengauss.h +92 -0
- data/ext/alglib/gqgenhermite.cpp +268 -0
- data/ext/alglib/gqgenhermite.h +63 -0
- data/ext/alglib/gqgenjacobi.cpp +297 -0
- data/ext/alglib/gqgenjacobi.h +72 -0
- data/ext/alglib/gqgenlaguerre.cpp +265 -0
- data/ext/alglib/gqgenlaguerre.h +69 -0
- data/ext/alglib/gqgenlegendre.cpp +300 -0
- data/ext/alglib/gqgenlegendre.h +62 -0
- data/ext/alglib/gqgenlobatto.cpp +305 -0
- data/ext/alglib/gqgenlobatto.h +97 -0
- data/ext/alglib/gqgenradau.cpp +232 -0
- data/ext/alglib/gqgenradau.h +95 -0
- data/ext/alglib/hbisinv.cpp +480 -0
- data/ext/alglib/hbisinv.h +183 -0
- data/ext/alglib/hblas.cpp +228 -0
- data/ext/alglib/hblas.h +64 -0
- data/ext/alglib/hcholesky.cpp +339 -0
- data/ext/alglib/hcholesky.h +91 -0
- data/ext/alglib/hermite.cpp +114 -0
- data/ext/alglib/hermite.h +49 -0
- data/ext/alglib/hessenberg.cpp +370 -0
- data/ext/alglib/hessenberg.h +152 -0
- data/ext/alglib/hevd.cpp +247 -0
- data/ext/alglib/hevd.h +107 -0
- data/ext/alglib/hsschur.cpp +1316 -0
- data/ext/alglib/hsschur.h +108 -0
- data/ext/alglib/htridiagonal.cpp +734 -0
- data/ext/alglib/htridiagonal.h +180 -0
- data/ext/alglib/ialglib.cpp +6 -0
- data/ext/alglib/ialglib.h +9 -0
- data/ext/alglib/ibetaf.cpp +960 -0
- data/ext/alglib/ibetaf.h +125 -0
- data/ext/alglib/igammaf.cpp +430 -0
- data/ext/alglib/igammaf.h +157 -0
- data/ext/alglib/inv.cpp +274 -0
- data/ext/alglib/inv.h +115 -0
- data/ext/alglib/inverseupdate.cpp +480 -0
- data/ext/alglib/inverseupdate.h +185 -0
- data/ext/alglib/jacobianelliptic.cpp +164 -0
- data/ext/alglib/jacobianelliptic.h +94 -0
- data/ext/alglib/jarquebera.cpp +2271 -0
- data/ext/alglib/jarquebera.h +80 -0
- data/ext/alglib/kmeans.cpp +356 -0
- data/ext/alglib/kmeans.h +76 -0
- data/ext/alglib/laguerre.cpp +94 -0
- data/ext/alglib/laguerre.h +48 -0
- data/ext/alglib/lbfgs.cpp +1167 -0
- data/ext/alglib/lbfgs.h +218 -0
- data/ext/alglib/lda.cpp +434 -0
- data/ext/alglib/lda.h +133 -0
- data/ext/alglib/ldlt.cpp +1130 -0
- data/ext/alglib/ldlt.h +124 -0
- data/ext/alglib/leastsquares.cpp +1252 -0
- data/ext/alglib/leastsquares.h +290 -0
- data/ext/alglib/legendre.cpp +107 -0
- data/ext/alglib/legendre.h +49 -0
- data/ext/alglib/linreg.cpp +1185 -0
- data/ext/alglib/linreg.h +380 -0
- data/ext/alglib/logit.cpp +1523 -0
- data/ext/alglib/logit.h +333 -0
- data/ext/alglib/lq.cpp +399 -0
- data/ext/alglib/lq.h +160 -0
- data/ext/alglib/lu.cpp +462 -0
- data/ext/alglib/lu.h +119 -0
- data/ext/alglib/mannwhitneyu.cpp +4490 -0
- data/ext/alglib/mannwhitneyu.h +115 -0
- data/ext/alglib/minlm.cpp +918 -0
- data/ext/alglib/minlm.h +312 -0
- data/ext/alglib/mlpbase.cpp +3375 -0
- data/ext/alglib/mlpbase.h +589 -0
- data/ext/alglib/mlpe.cpp +1369 -0
- data/ext/alglib/mlpe.h +552 -0
- data/ext/alglib/mlptrain.cpp +1056 -0
- data/ext/alglib/mlptrain.h +283 -0
- data/ext/alglib/nearunityunit.cpp +91 -0
- data/ext/alglib/nearunityunit.h +17 -0
- data/ext/alglib/normaldistr.cpp +377 -0
- data/ext/alglib/normaldistr.h +175 -0
- data/ext/alglib/nsevd.cpp +1869 -0
- data/ext/alglib/nsevd.h +140 -0
- data/ext/alglib/pca.cpp +168 -0
- data/ext/alglib/pca.h +87 -0
- data/ext/alglib/poissondistr.cpp +143 -0
- data/ext/alglib/poissondistr.h +130 -0
- data/ext/alglib/polinterpolation.cpp +685 -0
- data/ext/alglib/polinterpolation.h +206 -0
- data/ext/alglib/psif.cpp +173 -0
- data/ext/alglib/psif.h +88 -0
- data/ext/alglib/qr.cpp +414 -0
- data/ext/alglib/qr.h +168 -0
- data/ext/alglib/ratinterpolation.cpp +134 -0
- data/ext/alglib/ratinterpolation.h +72 -0
- data/ext/alglib/rcond.cpp +705 -0
- data/ext/alglib/rcond.h +140 -0
- data/ext/alglib/reflections.cpp +504 -0
- data/ext/alglib/reflections.h +165 -0
- data/ext/alglib/rotations.cpp +473 -0
- data/ext/alglib/rotations.h +128 -0
- data/ext/alglib/rsolve.cpp +221 -0
- data/ext/alglib/rsolve.h +99 -0
- data/ext/alglib/sbisinv.cpp +217 -0
- data/ext/alglib/sbisinv.h +171 -0
- data/ext/alglib/sblas.cpp +185 -0
- data/ext/alglib/sblas.h +64 -0
- data/ext/alglib/schur.cpp +156 -0
- data/ext/alglib/schur.h +102 -0
- data/ext/alglib/sdet.cpp +193 -0
- data/ext/alglib/sdet.h +101 -0
- data/ext/alglib/sevd.cpp +116 -0
- data/ext/alglib/sevd.h +99 -0
- data/ext/alglib/sinverse.cpp +672 -0
- data/ext/alglib/sinverse.h +138 -0
- data/ext/alglib/spddet.cpp +138 -0
- data/ext/alglib/spddet.h +96 -0
- data/ext/alglib/spdgevd.cpp +842 -0
- data/ext/alglib/spdgevd.h +200 -0
- data/ext/alglib/spdinverse.cpp +509 -0
- data/ext/alglib/spdinverse.h +122 -0
- data/ext/alglib/spdrcond.cpp +421 -0
- data/ext/alglib/spdrcond.h +118 -0
- data/ext/alglib/spdsolve.cpp +275 -0
- data/ext/alglib/spdsolve.h +105 -0
- data/ext/alglib/spline2d.cpp +1192 -0
- data/ext/alglib/spline2d.h +301 -0
- data/ext/alglib/spline3.cpp +1264 -0
- data/ext/alglib/spline3.h +290 -0
- data/ext/alglib/srcond.cpp +595 -0
- data/ext/alglib/srcond.h +127 -0
- data/ext/alglib/ssolve.cpp +895 -0
- data/ext/alglib/ssolve.h +139 -0
- data/ext/alglib/stdafx.h +0 -0
- data/ext/alglib/stest.cpp +131 -0
- data/ext/alglib/stest.h +94 -0
- data/ext/alglib/studenttdistr.cpp +222 -0
- data/ext/alglib/studenttdistr.h +115 -0
- data/ext/alglib/studentttests.cpp +377 -0
- data/ext/alglib/studentttests.h +178 -0
- data/ext/alglib/svd.cpp +620 -0
- data/ext/alglib/svd.h +126 -0
- data/ext/alglib/tdbisinv.cpp +2608 -0
- data/ext/alglib/tdbisinv.h +228 -0
- data/ext/alglib/tdevd.cpp +1229 -0
- data/ext/alglib/tdevd.h +115 -0
- data/ext/alglib/tridiagonal.cpp +594 -0
- data/ext/alglib/tridiagonal.h +171 -0
- data/ext/alglib/trigintegrals.cpp +490 -0
- data/ext/alglib/trigintegrals.h +131 -0
- data/ext/alglib/trinverse.cpp +345 -0
- data/ext/alglib/trinverse.h +98 -0
- data/ext/alglib/trlinsolve.cpp +926 -0
- data/ext/alglib/trlinsolve.h +73 -0
- data/ext/alglib/tsort.cpp +405 -0
- data/ext/alglib/tsort.h +54 -0
- data/ext/alglib/variancetests.cpp +245 -0
- data/ext/alglib/variancetests.h +134 -0
- data/ext/alglib/wsr.cpp +6285 -0
- data/ext/alglib/wsr.h +96 -0
- data/ext/ap.i +97 -0
- data/ext/correlation.i +24 -0
- data/ext/extconf.rb +6 -0
- data/ext/logit.i +89 -0
- data/lib/alglib.rb +71 -0
- data/lib/alglib/correlation.rb +26 -0
- data/lib/alglib/linearregression.rb +63 -0
- data/lib/alglib/logit.rb +42 -0
- data/test/test_alglib.rb +52 -0
- data/test/test_correlation.rb +44 -0
- data/test/test_correlationtest.rb +45 -0
- data/test/test_linreg.rb +35 -0
- data/test/test_logit.rb +43 -0
- data/test/test_pca.rb +27 -0
- metadata +326 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
/*************************************************************************
|
2
|
+
Copyright (c) 1992-2007 The University of Tennessee. All rights reserved.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Sergey Bochkanov (ALGLIB project). Translation from FORTRAN to
|
6
|
+
pseudocode.
|
7
|
+
|
8
|
+
See subroutines comments for additional copyrights.
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions are
|
12
|
+
met:
|
13
|
+
|
14
|
+
- Redistributions of source code must retain the above copyright
|
15
|
+
notice, this list of conditions and the following disclaimer.
|
16
|
+
|
17
|
+
- Redistributions in binary form must reproduce the above copyright
|
18
|
+
notice, this list of conditions and the following disclaimer listed
|
19
|
+
in this license in the documentation and/or other materials
|
20
|
+
provided with the distribution.
|
21
|
+
|
22
|
+
- Neither the name of the copyright holders nor the names of its
|
23
|
+
contributors may be used to endorse or promote products derived from
|
24
|
+
this software without specific prior written permission.
|
25
|
+
|
26
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
27
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
28
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
29
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
30
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
31
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
32
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
33
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
34
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
35
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
36
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
37
|
+
*************************************************************************/
|
38
|
+
|
39
|
+
#ifndef _estnorm_h
|
40
|
+
#define _estnorm_h
|
41
|
+
|
42
|
+
#include "ap.h"
|
43
|
+
#include "ialglib.h"
|
44
|
+
|
45
|
+
/*************************************************************************
|
46
|
+
Matrix norm estimation
|
47
|
+
|
48
|
+
The algorithm estimates the 1-norm of square matrix A on the assumption
|
49
|
+
that the multiplication of matrix A by the vector is available (the
|
50
|
+
iterative method is used). It is recommended to use this algorithm if it
|
51
|
+
is hard to calculate matrix elements explicitly (for example, when
|
52
|
+
estimating the inverse matrix norm).
|
53
|
+
|
54
|
+
The algorithm uses back communication for multiplying the vector by the
|
55
|
+
matrix. If KASE=0 after returning from a subroutine, its execution was
|
56
|
+
completed successfully, otherwise it is required to multiply the returned
|
57
|
+
vector by matrix A and call the subroutine again.
|
58
|
+
|
59
|
+
The DemoIterativeEstimateNorm subroutine shows a simple example.
|
60
|
+
|
61
|
+
Parameters:
|
62
|
+
N - size of matrix A.
|
63
|
+
V - vector. It is initialized by the subroutine on the first
|
64
|
+
call. It is then passed into it on repeated calls.
|
65
|
+
X - if KASE<>0, it contains the vector to be replaced by:
|
66
|
+
A * X, if KASE=1
|
67
|
+
A^T * X, if KASE=2
|
68
|
+
Array whose index ranges within [1..N].
|
69
|
+
ISGN - vector. It is initialized by the subroutine on the first
|
70
|
+
call. It is then passed into it on repeated calls.
|
71
|
+
EST - if KASE=0, it contains the lower boundary of the matrix
|
72
|
+
norm estimate.
|
73
|
+
KASE - on the first call, it should be equal to 0. After the last
|
74
|
+
return, it is equal to 0 (EST contains the matrix norm),
|
75
|
+
on intermediate returns it can be equal to 1 or 2 depending
|
76
|
+
on the operation to be performed on vector X.
|
77
|
+
|
78
|
+
-- LAPACK auxiliary routine (version 3.0) --
|
79
|
+
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
|
80
|
+
Courant Institute, Argonne National Lab, and Rice University
|
81
|
+
February 29, 1992
|
82
|
+
*************************************************************************/
|
83
|
+
void iterativeestimate1norm(int n,
|
84
|
+
ap::real_1d_array& v,
|
85
|
+
ap::real_1d_array& x,
|
86
|
+
ap::integer_1d_array& isgn,
|
87
|
+
double& est,
|
88
|
+
int& kase);
|
89
|
+
|
90
|
+
|
91
|
+
/*************************************************************************
|
92
|
+
Example of usage of an IterativeEstimateNorm subroutine
|
93
|
+
|
94
|
+
Input parameters:
|
95
|
+
A - matrix.
|
96
|
+
Array whose indexes range within [1..N, 1..N].
|
97
|
+
|
98
|
+
Return:
|
99
|
+
Matrix norm estimated by the subroutine.
|
100
|
+
|
101
|
+
-- ALGLIB --
|
102
|
+
Copyright 2005 by Bochkanov Sergey
|
103
|
+
*************************************************************************/
|
104
|
+
double demoiterativeestimate1norm(const ap::real_2d_array& a, int n);
|
105
|
+
|
106
|
+
|
107
|
+
#endif
|
@@ -0,0 +1,422 @@
|
|
1
|
+
/*************************************************************************
|
2
|
+
Cephes Math Library Release 2.8: June, 2000
|
3
|
+
Copyright by Stephen L. Moshier
|
4
|
+
|
5
|
+
Contributors:
|
6
|
+
* Sergey Bochkanov (ALGLIB project). Translation from C to
|
7
|
+
pseudocode.
|
8
|
+
|
9
|
+
See subroutines comments for additional copyrights.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are
|
13
|
+
met:
|
14
|
+
|
15
|
+
- Redistributions of source code must retain the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer.
|
17
|
+
|
18
|
+
- Redistributions in binary form must reproduce the above copyright
|
19
|
+
notice, this list of conditions and the following disclaimer listed
|
20
|
+
in this license in the documentation and/or other materials
|
21
|
+
provided with the distribution.
|
22
|
+
|
23
|
+
- Neither the name of the copyright holders nor the names of its
|
24
|
+
contributors may be used to endorse or promote products derived from
|
25
|
+
this software without specific prior written permission.
|
26
|
+
|
27
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
28
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
29
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
30
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
31
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
32
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
33
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
34
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
35
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
36
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
37
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
38
|
+
*************************************************************************/
|
39
|
+
|
40
|
+
#include <stdafx.h>
|
41
|
+
#include "expintegrals.h"
|
42
|
+
|
43
|
+
/*************************************************************************
|
44
|
+
Exponential integral Ei(x)
|
45
|
+
|
46
|
+
x
|
47
|
+
- t
|
48
|
+
| | e
|
49
|
+
Ei(x) = -|- --- dt .
|
50
|
+
| | t
|
51
|
+
-
|
52
|
+
-inf
|
53
|
+
|
54
|
+
Not defined for x <= 0.
|
55
|
+
See also expn.c.
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
ACCURACY:
|
60
|
+
|
61
|
+
Relative error:
|
62
|
+
arithmetic domain # trials peak rms
|
63
|
+
IEEE 0,100 50000 8.6e-16 1.3e-16
|
64
|
+
|
65
|
+
Cephes Math Library Release 2.8: May, 1999
|
66
|
+
Copyright 1999 by Stephen L. Moshier
|
67
|
+
*************************************************************************/
|
68
|
+
double exponentialintegralei(double x)
|
69
|
+
{
|
70
|
+
double result;
|
71
|
+
double eul;
|
72
|
+
double f;
|
73
|
+
double f1;
|
74
|
+
double f2;
|
75
|
+
double w;
|
76
|
+
|
77
|
+
eul = 0.5772156649015328606065;
|
78
|
+
if( x<=0 )
|
79
|
+
{
|
80
|
+
result = 0;
|
81
|
+
return result;
|
82
|
+
}
|
83
|
+
if( x<2 )
|
84
|
+
{
|
85
|
+
f1 = -5.350447357812542947283;
|
86
|
+
f1 = f1*x+218.5049168816613393830;
|
87
|
+
f1 = f1*x-4176.572384826693777058;
|
88
|
+
f1 = f1*x+55411.76756393557601232;
|
89
|
+
f1 = f1*x-331338.1331178144034309;
|
90
|
+
f1 = f1*x+1592627.163384945414220;
|
91
|
+
f2 = 1.000000000000000000000;
|
92
|
+
f2 = f2*x-52.50547959112862969197;
|
93
|
+
f2 = f2*x+1259.616186786790571525;
|
94
|
+
f2 = f2*x-17565.49581973534652631;
|
95
|
+
f2 = f2*x+149306.2117002725991967;
|
96
|
+
f2 = f2*x-729494.9239640527645655;
|
97
|
+
f2 = f2*x+1592627.163384945429726;
|
98
|
+
f = f1/f2;
|
99
|
+
result = eul+log(x)+x*f;
|
100
|
+
return result;
|
101
|
+
}
|
102
|
+
if( x<4 )
|
103
|
+
{
|
104
|
+
w = 1/x;
|
105
|
+
f1 = 1.981808503259689673238E-2;
|
106
|
+
f1 = f1*w-1.271645625984917501326;
|
107
|
+
f1 = f1*w-2.088160335681228318920;
|
108
|
+
f1 = f1*w+2.755544509187936721172;
|
109
|
+
f1 = f1*w-4.409507048701600257171E-1;
|
110
|
+
f1 = f1*w+4.665623805935891391017E-2;
|
111
|
+
f1 = f1*w-1.545042679673485262580E-3;
|
112
|
+
f1 = f1*w+7.059980605299617478514E-5;
|
113
|
+
f2 = 1.000000000000000000000;
|
114
|
+
f2 = f2*w+1.476498670914921440652;
|
115
|
+
f2 = f2*w+5.629177174822436244827E-1;
|
116
|
+
f2 = f2*w+1.699017897879307263248E-1;
|
117
|
+
f2 = f2*w+2.291647179034212017463E-2;
|
118
|
+
f2 = f2*w+4.450150439728752875043E-3;
|
119
|
+
f2 = f2*w+1.727439612206521482874E-4;
|
120
|
+
f2 = f2*w+3.953167195549672482304E-5;
|
121
|
+
f = f1/f2;
|
122
|
+
result = exp(x)*w*(1+w*f);
|
123
|
+
return result;
|
124
|
+
}
|
125
|
+
if( x<8 )
|
126
|
+
{
|
127
|
+
w = 1/x;
|
128
|
+
f1 = -1.373215375871208729803;
|
129
|
+
f1 = f1*w-7.084559133740838761406E-1;
|
130
|
+
f1 = f1*w+1.580806855547941010501;
|
131
|
+
f1 = f1*w-2.601500427425622944234E-1;
|
132
|
+
f1 = f1*w+2.994674694113713763365E-2;
|
133
|
+
f1 = f1*w-1.038086040188744005513E-3;
|
134
|
+
f1 = f1*w+4.371064420753005429514E-5;
|
135
|
+
f1 = f1*w+2.141783679522602903795E-6;
|
136
|
+
f2 = 1.000000000000000000000;
|
137
|
+
f2 = f2*w+8.585231423622028380768E-1;
|
138
|
+
f2 = f2*w+4.483285822873995129957E-1;
|
139
|
+
f2 = f2*w+7.687932158124475434091E-2;
|
140
|
+
f2 = f2*w+2.449868241021887685904E-2;
|
141
|
+
f2 = f2*w+8.832165941927796567926E-4;
|
142
|
+
f2 = f2*w+4.590952299511353531215E-4;
|
143
|
+
f2 = f2*w+(-4.729848351866523044863E-6);
|
144
|
+
f2 = f2*w+2.665195537390710170105E-6;
|
145
|
+
f = f1/f2;
|
146
|
+
result = exp(x)*w*(1+w*f);
|
147
|
+
return result;
|
148
|
+
}
|
149
|
+
if( x<16 )
|
150
|
+
{
|
151
|
+
w = 1/x;
|
152
|
+
f1 = -2.106934601691916512584;
|
153
|
+
f1 = f1*w+1.732733869664688041885;
|
154
|
+
f1 = f1*w-2.423619178935841904839E-1;
|
155
|
+
f1 = f1*w+2.322724180937565842585E-2;
|
156
|
+
f1 = f1*w+2.372880440493179832059E-4;
|
157
|
+
f1 = f1*w-8.343219561192552752335E-5;
|
158
|
+
f1 = f1*w+1.363408795605250394881E-5;
|
159
|
+
f1 = f1*w-3.655412321999253963714E-7;
|
160
|
+
f1 = f1*w+1.464941733975961318456E-8;
|
161
|
+
f1 = f1*w+6.176407863710360207074E-10;
|
162
|
+
f2 = 1.000000000000000000000;
|
163
|
+
f2 = f2*w-2.298062239901678075778E-1;
|
164
|
+
f2 = f2*w+1.105077041474037862347E-1;
|
165
|
+
f2 = f2*w-1.566542966630792353556E-2;
|
166
|
+
f2 = f2*w+2.761106850817352773874E-3;
|
167
|
+
f2 = f2*w-2.089148012284048449115E-4;
|
168
|
+
f2 = f2*w+1.708528938807675304186E-5;
|
169
|
+
f2 = f2*w-4.459311796356686423199E-7;
|
170
|
+
f2 = f2*w+1.394634930353847498145E-8;
|
171
|
+
f2 = f2*w+6.150865933977338354138E-10;
|
172
|
+
f = f1/f2;
|
173
|
+
result = exp(x)*w*(1+w*f);
|
174
|
+
return result;
|
175
|
+
}
|
176
|
+
if( x<32 )
|
177
|
+
{
|
178
|
+
w = 1/x;
|
179
|
+
f1 = -2.458119367674020323359E-1;
|
180
|
+
f1 = f1*w-1.483382253322077687183E-1;
|
181
|
+
f1 = f1*w+7.248291795735551591813E-2;
|
182
|
+
f1 = f1*w-1.348315687380940523823E-2;
|
183
|
+
f1 = f1*w+1.342775069788636972294E-3;
|
184
|
+
f1 = f1*w-7.942465637159712264564E-5;
|
185
|
+
f1 = f1*w+2.644179518984235952241E-6;
|
186
|
+
f1 = f1*w-4.239473659313765177195E-8;
|
187
|
+
f2 = 1.000000000000000000000;
|
188
|
+
f2 = f2*w-1.044225908443871106315E-1;
|
189
|
+
f2 = f2*w-2.676453128101402655055E-1;
|
190
|
+
f2 = f2*w+9.695000254621984627876E-2;
|
191
|
+
f2 = f2*w-1.601745692712991078208E-2;
|
192
|
+
f2 = f2*w+1.496414899205908021882E-3;
|
193
|
+
f2 = f2*w-8.462452563778485013756E-5;
|
194
|
+
f2 = f2*w+2.728938403476726394024E-6;
|
195
|
+
f2 = f2*w-4.239462431819542051337E-8;
|
196
|
+
f = f1/f2;
|
197
|
+
result = exp(x)*w*(1+w*f);
|
198
|
+
return result;
|
199
|
+
}
|
200
|
+
if( x<64 )
|
201
|
+
{
|
202
|
+
w = 1/x;
|
203
|
+
f1 = 1.212561118105456670844E-1;
|
204
|
+
f1 = f1*w-5.823133179043894485122E-1;
|
205
|
+
f1 = f1*w+2.348887314557016779211E-1;
|
206
|
+
f1 = f1*w-3.040034318113248237280E-2;
|
207
|
+
f1 = f1*w+1.510082146865190661777E-3;
|
208
|
+
f1 = f1*w-2.523137095499571377122E-5;
|
209
|
+
f2 = 1.000000000000000000000;
|
210
|
+
f2 = f2*w-1.002252150365854016662;
|
211
|
+
f2 = f2*w+2.928709694872224144953E-1;
|
212
|
+
f2 = f2*w-3.337004338674007801307E-2;
|
213
|
+
f2 = f2*w+1.560544881127388842819E-3;
|
214
|
+
f2 = f2*w-2.523137093603234562648E-5;
|
215
|
+
f = f1/f2;
|
216
|
+
result = exp(x)*w*(1+w*f);
|
217
|
+
return result;
|
218
|
+
}
|
219
|
+
w = 1/x;
|
220
|
+
f1 = -7.657847078286127362028E-1;
|
221
|
+
f1 = f1*w+6.886192415566705051750E-1;
|
222
|
+
f1 = f1*w-2.132598113545206124553E-1;
|
223
|
+
f1 = f1*w+3.346107552384193813594E-2;
|
224
|
+
f1 = f1*w-3.076541477344756050249E-3;
|
225
|
+
f1 = f1*w+1.747119316454907477380E-4;
|
226
|
+
f1 = f1*w-6.103711682274170530369E-6;
|
227
|
+
f1 = f1*w+1.218032765428652199087E-7;
|
228
|
+
f1 = f1*w-1.086076102793290233007E-9;
|
229
|
+
f2 = 1.000000000000000000000;
|
230
|
+
f2 = f2*w-1.888802868662308731041;
|
231
|
+
f2 = f2*w+1.066691687211408896850;
|
232
|
+
f2 = f2*w-2.751915982306380647738E-1;
|
233
|
+
f2 = f2*w+3.930852688233823569726E-2;
|
234
|
+
f2 = f2*w-3.414684558602365085394E-3;
|
235
|
+
f2 = f2*w+1.866844370703555398195E-4;
|
236
|
+
f2 = f2*w-6.345146083130515357861E-6;
|
237
|
+
f2 = f2*w+1.239754287483206878024E-7;
|
238
|
+
f2 = f2*w-1.086076102793126632978E-9;
|
239
|
+
f = f1/f2;
|
240
|
+
result = exp(x)*w*(1+w*f);
|
241
|
+
return result;
|
242
|
+
}
|
243
|
+
|
244
|
+
|
245
|
+
/*************************************************************************
|
246
|
+
Exponential integral En(x)
|
247
|
+
|
248
|
+
Evaluates the exponential integral
|
249
|
+
|
250
|
+
inf.
|
251
|
+
-
|
252
|
+
| | -xt
|
253
|
+
| e
|
254
|
+
E (x) = | ---- dt.
|
255
|
+
n | n
|
256
|
+
| | t
|
257
|
+
-
|
258
|
+
1
|
259
|
+
|
260
|
+
|
261
|
+
Both n and x must be nonnegative.
|
262
|
+
|
263
|
+
The routine employs either a power series, a continued
|
264
|
+
fraction, or an asymptotic formula depending on the
|
265
|
+
relative values of n and x.
|
266
|
+
|
267
|
+
ACCURACY:
|
268
|
+
|
269
|
+
Relative error:
|
270
|
+
arithmetic domain # trials peak rms
|
271
|
+
IEEE 0, 30 10000 1.7e-15 3.6e-16
|
272
|
+
|
273
|
+
Cephes Math Library Release 2.8: June, 2000
|
274
|
+
Copyright 1985, 2000 by Stephen L. Moshier
|
275
|
+
*************************************************************************/
|
276
|
+
double exponentialintegralen(double x, int n)
|
277
|
+
{
|
278
|
+
double result;
|
279
|
+
double r;
|
280
|
+
double t;
|
281
|
+
double yk;
|
282
|
+
double xk;
|
283
|
+
double pk;
|
284
|
+
double pkm1;
|
285
|
+
double pkm2;
|
286
|
+
double qk;
|
287
|
+
double qkm1;
|
288
|
+
double qkm2;
|
289
|
+
double psi;
|
290
|
+
double z;
|
291
|
+
int i;
|
292
|
+
int k;
|
293
|
+
double big;
|
294
|
+
double eul;
|
295
|
+
|
296
|
+
eul = 0.57721566490153286060;
|
297
|
+
big = 1.44115188075855872*pow(double(10), double(17));
|
298
|
+
if( n<0||x<0||x>170||x==0&&n<2 )
|
299
|
+
{
|
300
|
+
result = -1;
|
301
|
+
return result;
|
302
|
+
}
|
303
|
+
if( x==0 )
|
304
|
+
{
|
305
|
+
result = double(1)/double(n-1);
|
306
|
+
return result;
|
307
|
+
}
|
308
|
+
if( n==0 )
|
309
|
+
{
|
310
|
+
result = exp(-x)/x;
|
311
|
+
return result;
|
312
|
+
}
|
313
|
+
if( n>5000 )
|
314
|
+
{
|
315
|
+
xk = x+n;
|
316
|
+
yk = 1/(xk*xk);
|
317
|
+
t = n;
|
318
|
+
result = yk*t*(6*x*x-8*t*x+t*t);
|
319
|
+
result = yk*(result+t*(t-2.0*x));
|
320
|
+
result = yk*(result+t);
|
321
|
+
result = (result+1)*exp(-x)/xk;
|
322
|
+
return result;
|
323
|
+
}
|
324
|
+
if( x<=1 )
|
325
|
+
{
|
326
|
+
psi = -eul-log(x);
|
327
|
+
for(i = 1; i <= n-1; i++)
|
328
|
+
{
|
329
|
+
psi = psi+double(1)/double(i);
|
330
|
+
}
|
331
|
+
z = -x;
|
332
|
+
xk = 0;
|
333
|
+
yk = 1;
|
334
|
+
pk = 1-n;
|
335
|
+
if( n==1 )
|
336
|
+
{
|
337
|
+
result = 0.0;
|
338
|
+
}
|
339
|
+
else
|
340
|
+
{
|
341
|
+
result = 1.0/pk;
|
342
|
+
}
|
343
|
+
do
|
344
|
+
{
|
345
|
+
xk = xk+1;
|
346
|
+
yk = yk*z/xk;
|
347
|
+
pk = pk+1;
|
348
|
+
if( pk!=0 )
|
349
|
+
{
|
350
|
+
result = result+yk/pk;
|
351
|
+
}
|
352
|
+
if( result!=0 )
|
353
|
+
{
|
354
|
+
t = fabs(yk/result);
|
355
|
+
}
|
356
|
+
else
|
357
|
+
{
|
358
|
+
t = 1;
|
359
|
+
}
|
360
|
+
}
|
361
|
+
while(t>=ap::machineepsilon);
|
362
|
+
t = 1;
|
363
|
+
for(i = 1; i <= n-1; i++)
|
364
|
+
{
|
365
|
+
t = t*z/i;
|
366
|
+
}
|
367
|
+
result = psi*t-result;
|
368
|
+
return result;
|
369
|
+
}
|
370
|
+
else
|
371
|
+
{
|
372
|
+
k = 1;
|
373
|
+
pkm2 = 1;
|
374
|
+
qkm2 = x;
|
375
|
+
pkm1 = 1.0;
|
376
|
+
qkm1 = x+n;
|
377
|
+
result = pkm1/qkm1;
|
378
|
+
do
|
379
|
+
{
|
380
|
+
k = k+1;
|
381
|
+
if( k%2==1 )
|
382
|
+
{
|
383
|
+
yk = 1;
|
384
|
+
xk = n+double(k-1)/double(2);
|
385
|
+
}
|
386
|
+
else
|
387
|
+
{
|
388
|
+
yk = x;
|
389
|
+
xk = double(k)/double(2);
|
390
|
+
}
|
391
|
+
pk = pkm1*yk+pkm2*xk;
|
392
|
+
qk = qkm1*yk+qkm2*xk;
|
393
|
+
if( qk!=0 )
|
394
|
+
{
|
395
|
+
r = pk/qk;
|
396
|
+
t = fabs((result-r)/r);
|
397
|
+
result = r;
|
398
|
+
}
|
399
|
+
else
|
400
|
+
{
|
401
|
+
t = 1;
|
402
|
+
}
|
403
|
+
pkm2 = pkm1;
|
404
|
+
pkm1 = pk;
|
405
|
+
qkm2 = qkm1;
|
406
|
+
qkm1 = qk;
|
407
|
+
if( fabs(pk)>big )
|
408
|
+
{
|
409
|
+
pkm2 = pkm2/big;
|
410
|
+
pkm1 = pkm1/big;
|
411
|
+
qkm2 = qkm2/big;
|
412
|
+
qkm1 = qkm1/big;
|
413
|
+
}
|
414
|
+
}
|
415
|
+
while(t>=ap::machineepsilon);
|
416
|
+
result = result*exp(-x);
|
417
|
+
}
|
418
|
+
return result;
|
419
|
+
}
|
420
|
+
|
421
|
+
|
422
|
+
|