alglib 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. data/History.txt +7 -0
  2. data/Manifest.txt +253 -0
  3. data/README.txt +33 -0
  4. data/Rakefile +27 -0
  5. data/ext/Rakefile +24 -0
  6. data/ext/alglib.i +24 -0
  7. data/ext/alglib/Makefile +157 -0
  8. data/ext/alglib/airyf.cpp +372 -0
  9. data/ext/alglib/airyf.h +81 -0
  10. data/ext/alglib/alglib.cpp +8558 -0
  11. data/ext/alglib/alglib_util.cpp +19 -0
  12. data/ext/alglib/alglib_util.h +14 -0
  13. data/ext/alglib/ap.cpp +877 -0
  14. data/ext/alglib/ap.english.html +364 -0
  15. data/ext/alglib/ap.h +666 -0
  16. data/ext/alglib/ap.russian.html +442 -0
  17. data/ext/alglib/apvt.h +754 -0
  18. data/ext/alglib/bdss.cpp +1500 -0
  19. data/ext/alglib/bdss.h +251 -0
  20. data/ext/alglib/bdsvd.cpp +1339 -0
  21. data/ext/alglib/bdsvd.h +164 -0
  22. data/ext/alglib/bessel.cpp +1226 -0
  23. data/ext/alglib/bessel.h +331 -0
  24. data/ext/alglib/betaf.cpp +105 -0
  25. data/ext/alglib/betaf.h +74 -0
  26. data/ext/alglib/bidiagonal.cpp +1328 -0
  27. data/ext/alglib/bidiagonal.h +350 -0
  28. data/ext/alglib/binomialdistr.cpp +247 -0
  29. data/ext/alglib/binomialdistr.h +153 -0
  30. data/ext/alglib/blas.cpp +576 -0
  31. data/ext/alglib/blas.h +132 -0
  32. data/ext/alglib/cblas.cpp +226 -0
  33. data/ext/alglib/cblas.h +57 -0
  34. data/ext/alglib/cdet.cpp +138 -0
  35. data/ext/alglib/cdet.h +92 -0
  36. data/ext/alglib/chebyshev.cpp +216 -0
  37. data/ext/alglib/chebyshev.h +76 -0
  38. data/ext/alglib/chisquaredistr.cpp +157 -0
  39. data/ext/alglib/chisquaredistr.h +144 -0
  40. data/ext/alglib/cholesky.cpp +285 -0
  41. data/ext/alglib/cholesky.h +86 -0
  42. data/ext/alglib/cinverse.cpp +298 -0
  43. data/ext/alglib/cinverse.h +111 -0
  44. data/ext/alglib/clu.cpp +337 -0
  45. data/ext/alglib/clu.h +120 -0
  46. data/ext/alglib/correlation.cpp +280 -0
  47. data/ext/alglib/correlation.h +77 -0
  48. data/ext/alglib/correlationtests.cpp +726 -0
  49. data/ext/alglib/correlationtests.h +134 -0
  50. data/ext/alglib/crcond.cpp +826 -0
  51. data/ext/alglib/crcond.h +148 -0
  52. data/ext/alglib/creflections.cpp +310 -0
  53. data/ext/alglib/creflections.h +165 -0
  54. data/ext/alglib/csolve.cpp +312 -0
  55. data/ext/alglib/csolve.h +99 -0
  56. data/ext/alglib/ctrinverse.cpp +387 -0
  57. data/ext/alglib/ctrinverse.h +98 -0
  58. data/ext/alglib/ctrlinsolve.cpp +297 -0
  59. data/ext/alglib/ctrlinsolve.h +81 -0
  60. data/ext/alglib/dawson.cpp +234 -0
  61. data/ext/alglib/dawson.h +74 -0
  62. data/ext/alglib/descriptivestatistics.cpp +436 -0
  63. data/ext/alglib/descriptivestatistics.h +112 -0
  64. data/ext/alglib/det.cpp +140 -0
  65. data/ext/alglib/det.h +94 -0
  66. data/ext/alglib/dforest.cpp +1819 -0
  67. data/ext/alglib/dforest.h +316 -0
  68. data/ext/alglib/elliptic.cpp +497 -0
  69. data/ext/alglib/elliptic.h +217 -0
  70. data/ext/alglib/estnorm.cpp +429 -0
  71. data/ext/alglib/estnorm.h +107 -0
  72. data/ext/alglib/expintegrals.cpp +422 -0
  73. data/ext/alglib/expintegrals.h +108 -0
  74. data/ext/alglib/faq.english.html +258 -0
  75. data/ext/alglib/faq.russian.html +272 -0
  76. data/ext/alglib/fdistr.cpp +202 -0
  77. data/ext/alglib/fdistr.h +163 -0
  78. data/ext/alglib/fresnel.cpp +211 -0
  79. data/ext/alglib/fresnel.h +91 -0
  80. data/ext/alglib/gammaf.cpp +338 -0
  81. data/ext/alglib/gammaf.h +104 -0
  82. data/ext/alglib/gqgengauss.cpp +235 -0
  83. data/ext/alglib/gqgengauss.h +92 -0
  84. data/ext/alglib/gqgenhermite.cpp +268 -0
  85. data/ext/alglib/gqgenhermite.h +63 -0
  86. data/ext/alglib/gqgenjacobi.cpp +297 -0
  87. data/ext/alglib/gqgenjacobi.h +72 -0
  88. data/ext/alglib/gqgenlaguerre.cpp +265 -0
  89. data/ext/alglib/gqgenlaguerre.h +69 -0
  90. data/ext/alglib/gqgenlegendre.cpp +300 -0
  91. data/ext/alglib/gqgenlegendre.h +62 -0
  92. data/ext/alglib/gqgenlobatto.cpp +305 -0
  93. data/ext/alglib/gqgenlobatto.h +97 -0
  94. data/ext/alglib/gqgenradau.cpp +232 -0
  95. data/ext/alglib/gqgenradau.h +95 -0
  96. data/ext/alglib/hbisinv.cpp +480 -0
  97. data/ext/alglib/hbisinv.h +183 -0
  98. data/ext/alglib/hblas.cpp +228 -0
  99. data/ext/alglib/hblas.h +64 -0
  100. data/ext/alglib/hcholesky.cpp +339 -0
  101. data/ext/alglib/hcholesky.h +91 -0
  102. data/ext/alglib/hermite.cpp +114 -0
  103. data/ext/alglib/hermite.h +49 -0
  104. data/ext/alglib/hessenberg.cpp +370 -0
  105. data/ext/alglib/hessenberg.h +152 -0
  106. data/ext/alglib/hevd.cpp +247 -0
  107. data/ext/alglib/hevd.h +107 -0
  108. data/ext/alglib/hsschur.cpp +1316 -0
  109. data/ext/alglib/hsschur.h +108 -0
  110. data/ext/alglib/htridiagonal.cpp +734 -0
  111. data/ext/alglib/htridiagonal.h +180 -0
  112. data/ext/alglib/ialglib.cpp +6 -0
  113. data/ext/alglib/ialglib.h +9 -0
  114. data/ext/alglib/ibetaf.cpp +960 -0
  115. data/ext/alglib/ibetaf.h +125 -0
  116. data/ext/alglib/igammaf.cpp +430 -0
  117. data/ext/alglib/igammaf.h +157 -0
  118. data/ext/alglib/inv.cpp +274 -0
  119. data/ext/alglib/inv.h +115 -0
  120. data/ext/alglib/inverseupdate.cpp +480 -0
  121. data/ext/alglib/inverseupdate.h +185 -0
  122. data/ext/alglib/jacobianelliptic.cpp +164 -0
  123. data/ext/alglib/jacobianelliptic.h +94 -0
  124. data/ext/alglib/jarquebera.cpp +2271 -0
  125. data/ext/alglib/jarquebera.h +80 -0
  126. data/ext/alglib/kmeans.cpp +356 -0
  127. data/ext/alglib/kmeans.h +76 -0
  128. data/ext/alglib/laguerre.cpp +94 -0
  129. data/ext/alglib/laguerre.h +48 -0
  130. data/ext/alglib/lbfgs.cpp +1167 -0
  131. data/ext/alglib/lbfgs.h +218 -0
  132. data/ext/alglib/lda.cpp +434 -0
  133. data/ext/alglib/lda.h +133 -0
  134. data/ext/alglib/ldlt.cpp +1130 -0
  135. data/ext/alglib/ldlt.h +124 -0
  136. data/ext/alglib/leastsquares.cpp +1252 -0
  137. data/ext/alglib/leastsquares.h +290 -0
  138. data/ext/alglib/legendre.cpp +107 -0
  139. data/ext/alglib/legendre.h +49 -0
  140. data/ext/alglib/linreg.cpp +1185 -0
  141. data/ext/alglib/linreg.h +380 -0
  142. data/ext/alglib/logit.cpp +1523 -0
  143. data/ext/alglib/logit.h +333 -0
  144. data/ext/alglib/lq.cpp +399 -0
  145. data/ext/alglib/lq.h +160 -0
  146. data/ext/alglib/lu.cpp +462 -0
  147. data/ext/alglib/lu.h +119 -0
  148. data/ext/alglib/mannwhitneyu.cpp +4490 -0
  149. data/ext/alglib/mannwhitneyu.h +115 -0
  150. data/ext/alglib/minlm.cpp +918 -0
  151. data/ext/alglib/minlm.h +312 -0
  152. data/ext/alglib/mlpbase.cpp +3375 -0
  153. data/ext/alglib/mlpbase.h +589 -0
  154. data/ext/alglib/mlpe.cpp +1369 -0
  155. data/ext/alglib/mlpe.h +552 -0
  156. data/ext/alglib/mlptrain.cpp +1056 -0
  157. data/ext/alglib/mlptrain.h +283 -0
  158. data/ext/alglib/nearunityunit.cpp +91 -0
  159. data/ext/alglib/nearunityunit.h +17 -0
  160. data/ext/alglib/normaldistr.cpp +377 -0
  161. data/ext/alglib/normaldistr.h +175 -0
  162. data/ext/alglib/nsevd.cpp +1869 -0
  163. data/ext/alglib/nsevd.h +140 -0
  164. data/ext/alglib/pca.cpp +168 -0
  165. data/ext/alglib/pca.h +87 -0
  166. data/ext/alglib/poissondistr.cpp +143 -0
  167. data/ext/alglib/poissondistr.h +130 -0
  168. data/ext/alglib/polinterpolation.cpp +685 -0
  169. data/ext/alglib/polinterpolation.h +206 -0
  170. data/ext/alglib/psif.cpp +173 -0
  171. data/ext/alglib/psif.h +88 -0
  172. data/ext/alglib/qr.cpp +414 -0
  173. data/ext/alglib/qr.h +168 -0
  174. data/ext/alglib/ratinterpolation.cpp +134 -0
  175. data/ext/alglib/ratinterpolation.h +72 -0
  176. data/ext/alglib/rcond.cpp +705 -0
  177. data/ext/alglib/rcond.h +140 -0
  178. data/ext/alglib/reflections.cpp +504 -0
  179. data/ext/alglib/reflections.h +165 -0
  180. data/ext/alglib/rotations.cpp +473 -0
  181. data/ext/alglib/rotations.h +128 -0
  182. data/ext/alglib/rsolve.cpp +221 -0
  183. data/ext/alglib/rsolve.h +99 -0
  184. data/ext/alglib/sbisinv.cpp +217 -0
  185. data/ext/alglib/sbisinv.h +171 -0
  186. data/ext/alglib/sblas.cpp +185 -0
  187. data/ext/alglib/sblas.h +64 -0
  188. data/ext/alglib/schur.cpp +156 -0
  189. data/ext/alglib/schur.h +102 -0
  190. data/ext/alglib/sdet.cpp +193 -0
  191. data/ext/alglib/sdet.h +101 -0
  192. data/ext/alglib/sevd.cpp +116 -0
  193. data/ext/alglib/sevd.h +99 -0
  194. data/ext/alglib/sinverse.cpp +672 -0
  195. data/ext/alglib/sinverse.h +138 -0
  196. data/ext/alglib/spddet.cpp +138 -0
  197. data/ext/alglib/spddet.h +96 -0
  198. data/ext/alglib/spdgevd.cpp +842 -0
  199. data/ext/alglib/spdgevd.h +200 -0
  200. data/ext/alglib/spdinverse.cpp +509 -0
  201. data/ext/alglib/spdinverse.h +122 -0
  202. data/ext/alglib/spdrcond.cpp +421 -0
  203. data/ext/alglib/spdrcond.h +118 -0
  204. data/ext/alglib/spdsolve.cpp +275 -0
  205. data/ext/alglib/spdsolve.h +105 -0
  206. data/ext/alglib/spline2d.cpp +1192 -0
  207. data/ext/alglib/spline2d.h +301 -0
  208. data/ext/alglib/spline3.cpp +1264 -0
  209. data/ext/alglib/spline3.h +290 -0
  210. data/ext/alglib/srcond.cpp +595 -0
  211. data/ext/alglib/srcond.h +127 -0
  212. data/ext/alglib/ssolve.cpp +895 -0
  213. data/ext/alglib/ssolve.h +139 -0
  214. data/ext/alglib/stdafx.h +0 -0
  215. data/ext/alglib/stest.cpp +131 -0
  216. data/ext/alglib/stest.h +94 -0
  217. data/ext/alglib/studenttdistr.cpp +222 -0
  218. data/ext/alglib/studenttdistr.h +115 -0
  219. data/ext/alglib/studentttests.cpp +377 -0
  220. data/ext/alglib/studentttests.h +178 -0
  221. data/ext/alglib/svd.cpp +620 -0
  222. data/ext/alglib/svd.h +126 -0
  223. data/ext/alglib/tdbisinv.cpp +2608 -0
  224. data/ext/alglib/tdbisinv.h +228 -0
  225. data/ext/alglib/tdevd.cpp +1229 -0
  226. data/ext/alglib/tdevd.h +115 -0
  227. data/ext/alglib/tridiagonal.cpp +594 -0
  228. data/ext/alglib/tridiagonal.h +171 -0
  229. data/ext/alglib/trigintegrals.cpp +490 -0
  230. data/ext/alglib/trigintegrals.h +131 -0
  231. data/ext/alglib/trinverse.cpp +345 -0
  232. data/ext/alglib/trinverse.h +98 -0
  233. data/ext/alglib/trlinsolve.cpp +926 -0
  234. data/ext/alglib/trlinsolve.h +73 -0
  235. data/ext/alglib/tsort.cpp +405 -0
  236. data/ext/alglib/tsort.h +54 -0
  237. data/ext/alglib/variancetests.cpp +245 -0
  238. data/ext/alglib/variancetests.h +134 -0
  239. data/ext/alglib/wsr.cpp +6285 -0
  240. data/ext/alglib/wsr.h +96 -0
  241. data/ext/ap.i +97 -0
  242. data/ext/correlation.i +24 -0
  243. data/ext/extconf.rb +6 -0
  244. data/ext/logit.i +89 -0
  245. data/lib/alglib.rb +71 -0
  246. data/lib/alglib/correlation.rb +26 -0
  247. data/lib/alglib/linearregression.rb +63 -0
  248. data/lib/alglib/logit.rb +42 -0
  249. data/test/test_alglib.rb +52 -0
  250. data/test/test_correlation.rb +44 -0
  251. data/test/test_correlationtest.rb +45 -0
  252. data/test/test_linreg.rb +35 -0
  253. data/test/test_logit.rb +43 -0
  254. data/test/test_pca.rb +27 -0
  255. metadata +326 -0
@@ -0,0 +1,164 @@
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 _bdsvd_h
40
+ #define _bdsvd_h
41
+
42
+ #include "ap.h"
43
+ #include "ialglib.h"
44
+
45
+ #include "rotations.h"
46
+
47
+
48
+ /*************************************************************************
49
+ Singular value decomposition of a bidiagonal matrix (extended algorithm)
50
+
51
+ The algorithm performs the singular value decomposition of a bidiagonal
52
+ matrix B (upper or lower) representing it as B = Q*S*P^T, where Q and P -
53
+ orthogonal matrices, S - diagonal matrix with non-negative elements on the
54
+ main diagonal, in descending order.
55
+
56
+ The algorithm finds singular values. In addition, the algorithm can
57
+ calculate matrices Q and P (more precisely, not the matrices, but their
58
+ product with given matrices U and VT - U*Q and (P^T)*VT)). Of course,
59
+ matrices U and VT can be of any type, including identity. Furthermore, the
60
+ algorithm can calculate Q'*C (this product is calculated more effectively
61
+ than U*Q, because this calculation operates with rows instead of matrix
62
+ columns).
63
+
64
+ The feature of the algorithm is its ability to find all singular values
65
+ including those which are arbitrarily close to 0 with relative accuracy
66
+ close to machine precision. If the parameter IsFractionalAccuracyRequired
67
+ is set to True, all singular values will have high relative accuracy close
68
+ to machine precision. If the parameter is set to False, only the biggest
69
+ singular value will have relative accuracy close to machine precision.
70
+ The absolute error of other singular values is equal to the absolute error
71
+ of the biggest singular value.
72
+
73
+ Input parameters:
74
+ D - main diagonal of matrix B.
75
+ Array whose index ranges within [0..N-1].
76
+ E - superdiagonal (or subdiagonal) of matrix B.
77
+ Array whose index ranges within [0..N-2].
78
+ N - size of matrix B.
79
+ IsUpper - True, if the matrix is upper bidiagonal.
80
+ IsFractionalAccuracyRequired -
81
+ accuracy to search singular values with.
82
+ U - matrix to be multiplied by Q.
83
+ Array whose indexes range within [0..NRU-1, 0..N-1].
84
+ The matrix can be bigger, in that case only the submatrix
85
+ [0..NRU-1, 0..N-1] will be multiplied by Q.
86
+ NRU - number of rows in matrix U.
87
+ C - matrix to be multiplied by Q'.
88
+ Array whose indexes range within [0..N-1, 0..NCC-1].
89
+ The matrix can be bigger, in that case only the submatrix
90
+ [0..N-1, 0..NCC-1] will be multiplied by Q'.
91
+ NCC - number of columns in matrix C.
92
+ VT - matrix to be multiplied by P^T.
93
+ Array whose indexes range within [0..N-1, 0..NCVT-1].
94
+ The matrix can be bigger, in that case only the submatrix
95
+ [0..N-1, 0..NCVT-1] will be multiplied by P^T.
96
+ NCVT - number of columns in matrix VT.
97
+
98
+ Output parameters:
99
+ D - singular values of matrix B in descending order.
100
+ U - if NRU>0, contains matrix U*Q.
101
+ VT - if NCVT>0, contains matrix (P^T)*VT.
102
+ C - if NCC>0, contains matrix Q'*C.
103
+
104
+ Result:
105
+ True, if the algorithm has converged.
106
+ False, if the algorithm hasn't converged (rare case).
107
+
108
+ Additional information:
109
+ The type of convergence is controlled by the internal parameter TOL.
110
+ If the parameter is greater than 0, the singular values will have
111
+ relative accuracy TOL. If TOL<0, the singular values will have
112
+ absolute accuracy ABS(TOL)*norm(B).
113
+ By default, |TOL| falls within the range of 10*Epsilon and 100*Epsilon,
114
+ where Epsilon is the machine precision. It is not recommended to use
115
+ TOL less than 10*Epsilon since this will considerably slow down the
116
+ algorithm and may not lead to error decreasing.
117
+ History:
118
+ * 31 March, 2007.
119
+ changed MAXITR from 6 to 12.
120
+
121
+ -- LAPACK routine (version 3.0) --
122
+ Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
123
+ Courant Institute, Argonne National Lab, and Rice University
124
+ October 31, 1999.
125
+ *************************************************************************/
126
+ bool rmatrixbdsvd(ap::real_1d_array& d,
127
+ ap::real_1d_array e,
128
+ int n,
129
+ bool isupper,
130
+ bool isfractionalaccuracyrequired,
131
+ ap::real_2d_array& u,
132
+ int nru,
133
+ ap::real_2d_array& c,
134
+ int ncc,
135
+ ap::real_2d_array& vt,
136
+ int ncvt);
137
+
138
+
139
+ /*************************************************************************
140
+ Obsolete 1-based subroutine. See RMatrixBDSVD for 0-based replacement.
141
+
142
+ History:
143
+ * 31 March, 2007.
144
+ changed MAXITR from 6 to 12.
145
+
146
+ -- LAPACK routine (version 3.0) --
147
+ Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
148
+ Courant Institute, Argonne National Lab, and Rice University
149
+ October 31, 1999.
150
+ *************************************************************************/
151
+ bool bidiagonalsvddecomposition(ap::real_1d_array& d,
152
+ ap::real_1d_array e,
153
+ int n,
154
+ bool isupper,
155
+ bool isfractionalaccuracyrequired,
156
+ ap::real_2d_array& u,
157
+ int nru,
158
+ ap::real_2d_array& c,
159
+ int ncc,
160
+ ap::real_2d_array& vt,
161
+ int ncvt);
162
+
163
+
164
+ #endif
@@ -0,0 +1,1226 @@
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 "bessel.h"
42
+
43
+ static void besselmfirstcheb(double c, double& b0, double& b1, double& b2);
44
+ static void besselmnextcheb(double x,
45
+ double c,
46
+ double& b0,
47
+ double& b1,
48
+ double& b2);
49
+ static void besselm1firstcheb(double c, double& b0, double& b1, double& b2);
50
+ static void besselm1nextcheb(double x,
51
+ double c,
52
+ double& b0,
53
+ double& b1,
54
+ double& b2);
55
+ static void besselasympt0(double x, double& pzero, double& qzero);
56
+ static void besselasympt1(double x, double& pzero, double& qzero);
57
+
58
+ /*************************************************************************
59
+ Bessel function of order zero
60
+
61
+ Returns Bessel function of order zero of the argument.
62
+
63
+ The domain is divided into the intervals [0, 5] and
64
+ (5, infinity). In the first interval the following rational
65
+ approximation is used:
66
+
67
+
68
+ 2 2
69
+ (w - r ) (w - r ) P (w) / Q (w)
70
+ 1 2 3 8
71
+
72
+ 2
73
+ where w = x and the two r's are zeros of the function.
74
+
75
+ In the second interval, the Hankel asymptotic expansion
76
+ is employed with two rational functions of degree 6/6
77
+ and 7/7.
78
+
79
+ ACCURACY:
80
+
81
+ Absolute error:
82
+ arithmetic domain # trials peak rms
83
+ IEEE 0, 30 60000 4.2e-16 1.1e-16
84
+
85
+ Cephes Math Library Release 2.8: June, 2000
86
+ Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
87
+ *************************************************************************/
88
+ double besselj0(double x)
89
+ {
90
+ double result;
91
+ double xsq;
92
+ double nn;
93
+ double pzero;
94
+ double qzero;
95
+ double p1;
96
+ double q1;
97
+
98
+ if( x<0 )
99
+ {
100
+ x = -x;
101
+ }
102
+ if( x>8.0 )
103
+ {
104
+ besselasympt0(x, pzero, qzero);
105
+ nn = x-ap::pi()/4;
106
+ result = sqrt(2/ap::pi()/x)*(pzero*cos(nn)-qzero*sin(nn));
107
+ return result;
108
+ }
109
+ xsq = ap::sqr(x);
110
+ p1 = 26857.86856980014981415848441;
111
+ p1 = -40504123.71833132706360663322+xsq*p1;
112
+ p1 = 25071582855.36881945555156435+xsq*p1;
113
+ p1 = -8085222034853.793871199468171+xsq*p1;
114
+ p1 = 1434354939140344.111664316553+xsq*p1;
115
+ p1 = -136762035308817138.6865416609+xsq*p1;
116
+ p1 = 6382059341072356562.289432465+xsq*p1;
117
+ p1 = -117915762910761053603.8440800+xsq*p1;
118
+ p1 = 493378725179413356181.6813446+xsq*p1;
119
+ q1 = 1.0;
120
+ q1 = 1363.063652328970604442810507+xsq*q1;
121
+ q1 = 1114636.098462985378182402543+xsq*q1;
122
+ q1 = 669998767.2982239671814028660+xsq*q1;
123
+ q1 = 312304311494.1213172572469442+xsq*q1;
124
+ q1 = 112775673967979.8507056031594+xsq*q1;
125
+ q1 = 30246356167094626.98627330784+xsq*q1;
126
+ q1 = 5428918384092285160.200195092+xsq*q1;
127
+ q1 = 493378725179413356211.3278438+xsq*q1;
128
+ result = p1/q1;
129
+ return result;
130
+ }
131
+
132
+
133
+ /*************************************************************************
134
+ Bessel function of order one
135
+
136
+ Returns Bessel function of order one of the argument.
137
+
138
+ The domain is divided into the intervals [0, 8] and
139
+ (8, infinity). In the first interval a 24 term Chebyshev
140
+ expansion is used. In the second, the asymptotic
141
+ trigonometric representation is employed using two
142
+ rational functions of degree 5/5.
143
+
144
+ ACCURACY:
145
+
146
+ Absolute error:
147
+ arithmetic domain # trials peak rms
148
+ IEEE 0, 30 30000 2.6e-16 1.1e-16
149
+
150
+ Cephes Math Library Release 2.8: June, 2000
151
+ Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
152
+ *************************************************************************/
153
+ double besselj1(double x)
154
+ {
155
+ double result;
156
+ double s;
157
+ double xsq;
158
+ double nn;
159
+ double pzero;
160
+ double qzero;
161
+ double p1;
162
+ double q1;
163
+
164
+ s = ap::sign(x);
165
+ if( x<0 )
166
+ {
167
+ x = -x;
168
+ }
169
+ if( x>8.0 )
170
+ {
171
+ besselasympt1(x, pzero, qzero);
172
+ nn = x-3*ap::pi()/4;
173
+ result = sqrt(2/ap::pi()/x)*(pzero*cos(nn)-qzero*sin(nn));
174
+ if( s<0 )
175
+ {
176
+ result = -result;
177
+ }
178
+ return result;
179
+ }
180
+ xsq = ap::sqr(x);
181
+ p1 = 2701.122710892323414856790990;
182
+ p1 = -4695753.530642995859767162166+xsq*p1;
183
+ p1 = 3413234182.301700539091292655+xsq*p1;
184
+ p1 = -1322983480332.126453125473247+xsq*p1;
185
+ p1 = 290879526383477.5409737601689+xsq*p1;
186
+ p1 = -35888175699101060.50743641413+xsq*p1;
187
+ p1 = 2316433580634002297.931815435+xsq*p1;
188
+ p1 = -66721065689249162980.20941484+xsq*p1;
189
+ p1 = 581199354001606143928.050809+xsq*p1;
190
+ q1 = 1.0;
191
+ q1 = 1606.931573481487801970916749+xsq*q1;
192
+ q1 = 1501793.594998585505921097578+xsq*q1;
193
+ q1 = 1013863514.358673989967045588+xsq*q1;
194
+ q1 = 524371026216.7649715406728642+xsq*q1;
195
+ q1 = 208166122130760.7351240184229+xsq*q1;
196
+ q1 = 60920613989175217.46105196863+xsq*q1;
197
+ q1 = 11857707121903209998.37113348+xsq*q1;
198
+ q1 = 1162398708003212287858.529400+xsq*q1;
199
+ result = s*x*p1/q1;
200
+ return result;
201
+ }
202
+
203
+
204
+ /*************************************************************************
205
+ Bessel function of integer order
206
+
207
+ Returns Bessel function of order n, where n is a
208
+ (possibly negative) integer.
209
+
210
+ The ratio of jn(x) to j0(x) is computed by backward
211
+ recurrence. First the ratio jn/jn-1 is found by a
212
+ continued fraction expansion. Then the recurrence
213
+ relating successive orders is applied until j0 or j1 is
214
+ reached.
215
+
216
+ If n = 0 or 1 the routine for j0 or j1 is called
217
+ directly.
218
+
219
+ ACCURACY:
220
+
221
+ Absolute error:
222
+ arithmetic range # trials peak rms
223
+ IEEE 0, 30 5000 4.4e-16 7.9e-17
224
+
225
+
226
+ Not suitable for large n or x. Use jv() (fractional order) instead.
227
+
228
+ Cephes Math Library Release 2.8: June, 2000
229
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
230
+ *************************************************************************/
231
+ double besseljn(int n, double x)
232
+ {
233
+ double result;
234
+ double pkm2;
235
+ double pkm1;
236
+ double pk;
237
+ double xk;
238
+ double r;
239
+ double ans;
240
+ int k;
241
+ int sg;
242
+
243
+ if( n<0 )
244
+ {
245
+ n = -n;
246
+ if( n%2==0 )
247
+ {
248
+ sg = 1;
249
+ }
250
+ else
251
+ {
252
+ sg = -1;
253
+ }
254
+ }
255
+ else
256
+ {
257
+ sg = 1;
258
+ }
259
+ if( x<0 )
260
+ {
261
+ if( n%2!=0 )
262
+ {
263
+ sg = -sg;
264
+ }
265
+ x = -x;
266
+ }
267
+ if( n==0 )
268
+ {
269
+ result = sg*besselj0(x);
270
+ return result;
271
+ }
272
+ if( n==1 )
273
+ {
274
+ result = sg*besselj1(x);
275
+ return result;
276
+ }
277
+ if( n==2 )
278
+ {
279
+ if( x==0 )
280
+ {
281
+ result = 0;
282
+ }
283
+ else
284
+ {
285
+ result = sg*(2.0*besselj1(x)/x-besselj0(x));
286
+ }
287
+ return result;
288
+ }
289
+ if( x<ap::machineepsilon )
290
+ {
291
+ result = 0;
292
+ return result;
293
+ }
294
+ k = 53;
295
+ pk = 2*(n+k);
296
+ ans = pk;
297
+ xk = x*x;
298
+ do
299
+ {
300
+ pk = pk-2.0;
301
+ ans = pk-xk/ans;
302
+ k = k-1;
303
+ }
304
+ while(k!=0);
305
+ ans = x/ans;
306
+ pk = 1.0;
307
+ pkm1 = 1.0/ans;
308
+ k = n-1;
309
+ r = 2*k;
310
+ do
311
+ {
312
+ pkm2 = (pkm1*r-pk*x)/x;
313
+ pk = pkm1;
314
+ pkm1 = pkm2;
315
+ r = r-2.0;
316
+ k = k-1;
317
+ }
318
+ while(k!=0);
319
+ if( fabs(pk)>fabs(pkm1) )
320
+ {
321
+ ans = besselj1(x)/pk;
322
+ }
323
+ else
324
+ {
325
+ ans = besselj0(x)/pkm1;
326
+ }
327
+ result = sg*ans;
328
+ return result;
329
+ }
330
+
331
+
332
+ /*************************************************************************
333
+ Bessel function of the second kind, order zero
334
+
335
+ Returns Bessel function of the second kind, of order
336
+ zero, of the argument.
337
+
338
+ The domain is divided into the intervals [0, 5] and
339
+ (5, infinity). In the first interval a rational approximation
340
+ R(x) is employed to compute
341
+ y0(x) = R(x) + 2 * log(x) * j0(x) / PI.
342
+ Thus a call to j0() is required.
343
+
344
+ In the second interval, the Hankel asymptotic expansion
345
+ is employed with two rational functions of degree 6/6
346
+ and 7/7.
347
+
348
+
349
+
350
+ ACCURACY:
351
+
352
+ Absolute error, when y0(x) < 1; else relative error:
353
+
354
+ arithmetic domain # trials peak rms
355
+ IEEE 0, 30 30000 1.3e-15 1.6e-16
356
+
357
+ Cephes Math Library Release 2.8: June, 2000
358
+ Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
359
+ *************************************************************************/
360
+ double bessely0(double x)
361
+ {
362
+ double result;
363
+ double nn;
364
+ double xsq;
365
+ double pzero;
366
+ double qzero;
367
+ double p4;
368
+ double q4;
369
+
370
+ if( x>8.0 )
371
+ {
372
+ besselasympt0(x, pzero, qzero);
373
+ nn = x-ap::pi()/4;
374
+ result = sqrt(2/ap::pi()/x)*(pzero*sin(nn)+qzero*cos(nn));
375
+ return result;
376
+ }
377
+ xsq = ap::sqr(x);
378
+ p4 = -41370.35497933148554125235152;
379
+ p4 = 59152134.65686889654273830069+xsq*p4;
380
+ p4 = -34363712229.79040378171030138+xsq*p4;
381
+ p4 = 10255208596863.94284509167421+xsq*p4;
382
+ p4 = -1648605817185729.473122082537+xsq*p4;
383
+ p4 = 137562431639934407.8571335453+xsq*p4;
384
+ p4 = -5247065581112764941.297350814+xsq*p4;
385
+ p4 = 65874732757195549259.99402049+xsq*p4;
386
+ p4 = -27502866786291095837.01933175+xsq*p4;
387
+ q4 = 1.0;
388
+ q4 = 1282.452772478993804176329391+xsq*q4;
389
+ q4 = 1001702.641288906265666651753+xsq*q4;
390
+ q4 = 579512264.0700729537480087915+xsq*q4;
391
+ q4 = 261306575504.1081249568482092+xsq*q4;
392
+ q4 = 91620380340751.85262489147968+xsq*q4;
393
+ q4 = 23928830434997818.57439356652+xsq*q4;
394
+ q4 = 4192417043410839973.904769661+xsq*q4;
395
+ q4 = 372645883898616588198.9980+xsq*q4;
396
+ result = p4/q4+2/ap::pi()*besselj0(x)*log(x);
397
+ return result;
398
+ }
399
+
400
+
401
+ /*************************************************************************
402
+ Bessel function of second kind of order one
403
+
404
+ Returns Bessel function of the second kind of order one
405
+ of the argument.
406
+
407
+ The domain is divided into the intervals [0, 8] and
408
+ (8, infinity). In the first interval a 25 term Chebyshev
409
+ expansion is used, and a call to j1() is required.
410
+ In the second, the asymptotic trigonometric representation
411
+ is employed using two rational functions of degree 5/5.
412
+
413
+ ACCURACY:
414
+
415
+ Absolute error:
416
+ arithmetic domain # trials peak rms
417
+ IEEE 0, 30 30000 1.0e-15 1.3e-16
418
+
419
+ Cephes Math Library Release 2.8: June, 2000
420
+ Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier
421
+ *************************************************************************/
422
+ double bessely1(double x)
423
+ {
424
+ double result;
425
+ double nn;
426
+ double xsq;
427
+ double pzero;
428
+ double qzero;
429
+ double p4;
430
+ double q4;
431
+
432
+ if( x>8.0 )
433
+ {
434
+ besselasympt1(x, pzero, qzero);
435
+ nn = x-3*ap::pi()/4;
436
+ result = sqrt(2/ap::pi()/x)*(pzero*sin(nn)+qzero*cos(nn));
437
+ return result;
438
+ }
439
+ xsq = ap::sqr(x);
440
+ p4 = -2108847.540133123652824139923;
441
+ p4 = 3639488548.124002058278999428+xsq*p4;
442
+ p4 = -2580681702194.450950541426399+xsq*p4;
443
+ p4 = 956993023992168.3481121552788+xsq*p4;
444
+ p4 = -196588746272214065.8820322248+xsq*p4;
445
+ p4 = 21931073399177975921.11427556+xsq*p4;
446
+ p4 = -1212297555414509577913.561535+xsq*p4;
447
+ p4 = 26554738314348543268942.48968+xsq*p4;
448
+ p4 = -99637534243069222259967.44354+xsq*p4;
449
+ q4 = 1.0;
450
+ q4 = 1612.361029677000859332072312+xsq*q4;
451
+ q4 = 1563282.754899580604737366452+xsq*q4;
452
+ q4 = 1128686837.169442121732366891+xsq*q4;
453
+ q4 = 646534088126.5275571961681500+xsq*q4;
454
+ q4 = 297663212564727.6729292742282+xsq*q4;
455
+ q4 = 108225825940881955.2553850180+xsq*q4;
456
+ q4 = 29549879358971486742.90758119+xsq*q4;
457
+ q4 = 5435310377188854170800.653097+xsq*q4;
458
+ q4 = 508206736694124324531442.4152+xsq*q4;
459
+ result = x*p4/q4+2/ap::pi()*(besselj1(x)*log(x)-1/x);
460
+ return result;
461
+ }
462
+
463
+
464
+ /*************************************************************************
465
+ Bessel function of second kind of integer order
466
+
467
+ Returns Bessel function of order n, where n is a
468
+ (possibly negative) integer.
469
+
470
+ The function is evaluated by forward recurrence on
471
+ n, starting with values computed by the routines
472
+ y0() and y1().
473
+
474
+ If n = 0 or 1 the routine for y0 or y1 is called
475
+ directly.
476
+
477
+ ACCURACY:
478
+ Absolute error, except relative
479
+ when y > 1:
480
+ arithmetic domain # trials peak rms
481
+ IEEE 0, 30 30000 3.4e-15 4.3e-16
482
+
483
+ Cephes Math Library Release 2.8: June, 2000
484
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
485
+ *************************************************************************/
486
+ double besselyn(int n, double x)
487
+ {
488
+ double result;
489
+ int i;
490
+ double a;
491
+ double b;
492
+ double tmp;
493
+ double s;
494
+
495
+ s = 1;
496
+ if( n<0 )
497
+ {
498
+ n = -n;
499
+ if( n%2!=0 )
500
+ {
501
+ s = -1;
502
+ }
503
+ }
504
+ if( n==0 )
505
+ {
506
+ result = bessely0(x);
507
+ return result;
508
+ }
509
+ if( n==1 )
510
+ {
511
+ result = s*bessely1(x);
512
+ return result;
513
+ }
514
+ a = bessely0(x);
515
+ b = bessely1(x);
516
+ for(i = 1; i <= n-1; i++)
517
+ {
518
+ tmp = b;
519
+ b = 2*i/x*b-a;
520
+ a = tmp;
521
+ }
522
+ result = s*b;
523
+ return result;
524
+ }
525
+
526
+
527
+ /*************************************************************************
528
+ Modified Bessel function of order zero
529
+
530
+ Returns modified Bessel function of order zero of the
531
+ argument.
532
+
533
+ The function is defined as i0(x) = j0( ix ).
534
+
535
+ The range is partitioned into the two intervals [0,8] and
536
+ (8, infinity). Chebyshev polynomial expansions are employed
537
+ in each interval.
538
+
539
+ ACCURACY:
540
+
541
+ Relative error:
542
+ arithmetic domain # trials peak rms
543
+ IEEE 0,30 30000 5.8e-16 1.4e-16
544
+
545
+ Cephes Math Library Release 2.8: June, 2000
546
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
547
+ *************************************************************************/
548
+ double besseli0(double x)
549
+ {
550
+ double result;
551
+ double y;
552
+ double v;
553
+ double z;
554
+ double b0;
555
+ double b1;
556
+ double b2;
557
+
558
+ if( x<0 )
559
+ {
560
+ x = -x;
561
+ }
562
+ if( x<=8.0 )
563
+ {
564
+ y = x/2.0-2.0;
565
+ besselmfirstcheb(-4.41534164647933937950E-18, b0, b1, b2);
566
+ besselmnextcheb(y, 3.33079451882223809783E-17, b0, b1, b2);
567
+ besselmnextcheb(y, -2.43127984654795469359E-16, b0, b1, b2);
568
+ besselmnextcheb(y, 1.71539128555513303061E-15, b0, b1, b2);
569
+ besselmnextcheb(y, -1.16853328779934516808E-14, b0, b1, b2);
570
+ besselmnextcheb(y, 7.67618549860493561688E-14, b0, b1, b2);
571
+ besselmnextcheb(y, -4.85644678311192946090E-13, b0, b1, b2);
572
+ besselmnextcheb(y, 2.95505266312963983461E-12, b0, b1, b2);
573
+ besselmnextcheb(y, -1.72682629144155570723E-11, b0, b1, b2);
574
+ besselmnextcheb(y, 9.67580903537323691224E-11, b0, b1, b2);
575
+ besselmnextcheb(y, -5.18979560163526290666E-10, b0, b1, b2);
576
+ besselmnextcheb(y, 2.65982372468238665035E-9, b0, b1, b2);
577
+ besselmnextcheb(y, -1.30002500998624804212E-8, b0, b1, b2);
578
+ besselmnextcheb(y, 6.04699502254191894932E-8, b0, b1, b2);
579
+ besselmnextcheb(y, -2.67079385394061173391E-7, b0, b1, b2);
580
+ besselmnextcheb(y, 1.11738753912010371815E-6, b0, b1, b2);
581
+ besselmnextcheb(y, -4.41673835845875056359E-6, b0, b1, b2);
582
+ besselmnextcheb(y, 1.64484480707288970893E-5, b0, b1, b2);
583
+ besselmnextcheb(y, -5.75419501008210370398E-5, b0, b1, b2);
584
+ besselmnextcheb(y, 1.88502885095841655729E-4, b0, b1, b2);
585
+ besselmnextcheb(y, -5.76375574538582365885E-4, b0, b1, b2);
586
+ besselmnextcheb(y, 1.63947561694133579842E-3, b0, b1, b2);
587
+ besselmnextcheb(y, -4.32430999505057594430E-3, b0, b1, b2);
588
+ besselmnextcheb(y, 1.05464603945949983183E-2, b0, b1, b2);
589
+ besselmnextcheb(y, -2.37374148058994688156E-2, b0, b1, b2);
590
+ besselmnextcheb(y, 4.93052842396707084878E-2, b0, b1, b2);
591
+ besselmnextcheb(y, -9.49010970480476444210E-2, b0, b1, b2);
592
+ besselmnextcheb(y, 1.71620901522208775349E-1, b0, b1, b2);
593
+ besselmnextcheb(y, -3.04682672343198398683E-1, b0, b1, b2);
594
+ besselmnextcheb(y, 6.76795274409476084995E-1, b0, b1, b2);
595
+ v = 0.5*(b0-b2);
596
+ result = exp(x)*v;
597
+ return result;
598
+ }
599
+ z = 32.0/x-2.0;
600
+ besselmfirstcheb(-7.23318048787475395456E-18, b0, b1, b2);
601
+ besselmnextcheb(z, -4.83050448594418207126E-18, b0, b1, b2);
602
+ besselmnextcheb(z, 4.46562142029675999901E-17, b0, b1, b2);
603
+ besselmnextcheb(z, 3.46122286769746109310E-17, b0, b1, b2);
604
+ besselmnextcheb(z, -2.82762398051658348494E-16, b0, b1, b2);
605
+ besselmnextcheb(z, -3.42548561967721913462E-16, b0, b1, b2);
606
+ besselmnextcheb(z, 1.77256013305652638360E-15, b0, b1, b2);
607
+ besselmnextcheb(z, 3.81168066935262242075E-15, b0, b1, b2);
608
+ besselmnextcheb(z, -9.55484669882830764870E-15, b0, b1, b2);
609
+ besselmnextcheb(z, -4.15056934728722208663E-14, b0, b1, b2);
610
+ besselmnextcheb(z, 1.54008621752140982691E-14, b0, b1, b2);
611
+ besselmnextcheb(z, 3.85277838274214270114E-13, b0, b1, b2);
612
+ besselmnextcheb(z, 7.18012445138366623367E-13, b0, b1, b2);
613
+ besselmnextcheb(z, -1.79417853150680611778E-12, b0, b1, b2);
614
+ besselmnextcheb(z, -1.32158118404477131188E-11, b0, b1, b2);
615
+ besselmnextcheb(z, -3.14991652796324136454E-11, b0, b1, b2);
616
+ besselmnextcheb(z, 1.18891471078464383424E-11, b0, b1, b2);
617
+ besselmnextcheb(z, 4.94060238822496958910E-10, b0, b1, b2);
618
+ besselmnextcheb(z, 3.39623202570838634515E-9, b0, b1, b2);
619
+ besselmnextcheb(z, 2.26666899049817806459E-8, b0, b1, b2);
620
+ besselmnextcheb(z, 2.04891858946906374183E-7, b0, b1, b2);
621
+ besselmnextcheb(z, 2.89137052083475648297E-6, b0, b1, b2);
622
+ besselmnextcheb(z, 6.88975834691682398426E-5, b0, b1, b2);
623
+ besselmnextcheb(z, 3.36911647825569408990E-3, b0, b1, b2);
624
+ besselmnextcheb(z, 8.04490411014108831608E-1, b0, b1, b2);
625
+ v = 0.5*(b0-b2);
626
+ result = exp(x)*v/sqrt(x);
627
+ return result;
628
+ }
629
+
630
+
631
+ /*************************************************************************
632
+ Modified Bessel function of order one
633
+
634
+ Returns modified Bessel function of order one of the
635
+ argument.
636
+
637
+ The function is defined as i1(x) = -i j1( ix ).
638
+
639
+ The range is partitioned into the two intervals [0,8] and
640
+ (8, infinity). Chebyshev polynomial expansions are employed
641
+ in each interval.
642
+
643
+ ACCURACY:
644
+
645
+ Relative error:
646
+ arithmetic domain # trials peak rms
647
+ IEEE 0, 30 30000 1.9e-15 2.1e-16
648
+
649
+ Cephes Math Library Release 2.8: June, 2000
650
+ Copyright 1985, 1987, 2000 by Stephen L. Moshier
651
+ *************************************************************************/
652
+ double besseli1(double x)
653
+ {
654
+ double result;
655
+ double y;
656
+ double z;
657
+ double v;
658
+ double b0;
659
+ double b1;
660
+ double b2;
661
+
662
+ z = fabs(x);
663
+ if( z<=8.0 )
664
+ {
665
+ y = z/2.0-2.0;
666
+ besselm1firstcheb(2.77791411276104639959E-18, b0, b1, b2);
667
+ besselm1nextcheb(y, -2.11142121435816608115E-17, b0, b1, b2);
668
+ besselm1nextcheb(y, 1.55363195773620046921E-16, b0, b1, b2);
669
+ besselm1nextcheb(y, -1.10559694773538630805E-15, b0, b1, b2);
670
+ besselm1nextcheb(y, 7.60068429473540693410E-15, b0, b1, b2);
671
+ besselm1nextcheb(y, -5.04218550472791168711E-14, b0, b1, b2);
672
+ besselm1nextcheb(y, 3.22379336594557470981E-13, b0, b1, b2);
673
+ besselm1nextcheb(y, -1.98397439776494371520E-12, b0, b1, b2);
674
+ besselm1nextcheb(y, 1.17361862988909016308E-11, b0, b1, b2);
675
+ besselm1nextcheb(y, -6.66348972350202774223E-11, b0, b1, b2);
676
+ besselm1nextcheb(y, 3.62559028155211703701E-10, b0, b1, b2);
677
+ besselm1nextcheb(y, -1.88724975172282928790E-9, b0, b1, b2);
678
+ besselm1nextcheb(y, 9.38153738649577178388E-9, b0, b1, b2);
679
+ besselm1nextcheb(y, -4.44505912879632808065E-8, b0, b1, b2);
680
+ besselm1nextcheb(y, 2.00329475355213526229E-7, b0, b1, b2);
681
+ besselm1nextcheb(y, -8.56872026469545474066E-7, b0, b1, b2);
682
+ besselm1nextcheb(y, 3.47025130813767847674E-6, b0, b1, b2);
683
+ besselm1nextcheb(y, -1.32731636560394358279E-5, b0, b1, b2);
684
+ besselm1nextcheb(y, 4.78156510755005422638E-5, b0, b1, b2);
685
+ besselm1nextcheb(y, -1.61760815825896745588E-4, b0, b1, b2);
686
+ besselm1nextcheb(y, 5.12285956168575772895E-4, b0, b1, b2);
687
+ besselm1nextcheb(y, -1.51357245063125314899E-3, b0, b1, b2);
688
+ besselm1nextcheb(y, 4.15642294431288815669E-3, b0, b1, b2);
689
+ besselm1nextcheb(y, -1.05640848946261981558E-2, b0, b1, b2);
690
+ besselm1nextcheb(y, 2.47264490306265168283E-2, b0, b1, b2);
691
+ besselm1nextcheb(y, -5.29459812080949914269E-2, b0, b1, b2);
692
+ besselm1nextcheb(y, 1.02643658689847095384E-1, b0, b1, b2);
693
+ besselm1nextcheb(y, -1.76416518357834055153E-1, b0, b1, b2);
694
+ besselm1nextcheb(y, 2.52587186443633654823E-1, b0, b1, b2);
695
+ v = 0.5*(b0-b2);
696
+ z = v*z*exp(z);
697
+ }
698
+ else
699
+ {
700
+ y = 32.0/z-2.0;
701
+ besselm1firstcheb(7.51729631084210481353E-18, b0, b1, b2);
702
+ besselm1nextcheb(y, 4.41434832307170791151E-18, b0, b1, b2);
703
+ besselm1nextcheb(y, -4.65030536848935832153E-17, b0, b1, b2);
704
+ besselm1nextcheb(y, -3.20952592199342395980E-17, b0, b1, b2);
705
+ besselm1nextcheb(y, 2.96262899764595013876E-16, b0, b1, b2);
706
+ besselm1nextcheb(y, 3.30820231092092828324E-16, b0, b1, b2);
707
+ besselm1nextcheb(y, -1.88035477551078244854E-15, b0, b1, b2);
708
+ besselm1nextcheb(y, -3.81440307243700780478E-15, b0, b1, b2);
709
+ besselm1nextcheb(y, 1.04202769841288027642E-14, b0, b1, b2);
710
+ besselm1nextcheb(y, 4.27244001671195135429E-14, b0, b1, b2);
711
+ besselm1nextcheb(y, -2.10154184277266431302E-14, b0, b1, b2);
712
+ besselm1nextcheb(y, -4.08355111109219731823E-13, b0, b1, b2);
713
+ besselm1nextcheb(y, -7.19855177624590851209E-13, b0, b1, b2);
714
+ besselm1nextcheb(y, 2.03562854414708950722E-12, b0, b1, b2);
715
+ besselm1nextcheb(y, 1.41258074366137813316E-11, b0, b1, b2);
716
+ besselm1nextcheb(y, 3.25260358301548823856E-11, b0, b1, b2);
717
+ besselm1nextcheb(y, -1.89749581235054123450E-11, b0, b1, b2);
718
+ besselm1nextcheb(y, -5.58974346219658380687E-10, b0, b1, b2);
719
+ besselm1nextcheb(y, -3.83538038596423702205E-9, b0, b1, b2);
720
+ besselm1nextcheb(y, -2.63146884688951950684E-8, b0, b1, b2);
721
+ besselm1nextcheb(y, -2.51223623787020892529E-7, b0, b1, b2);
722
+ besselm1nextcheb(y, -3.88256480887769039346E-6, b0, b1, b2);
723
+ besselm1nextcheb(y, -1.10588938762623716291E-4, b0, b1, b2);
724
+ besselm1nextcheb(y, -9.76109749136146840777E-3, b0, b1, b2);
725
+ besselm1nextcheb(y, 7.78576235018280120474E-1, b0, b1, b2);
726
+ v = 0.5*(b0-b2);
727
+ z = v*exp(z)/sqrt(z);
728
+ }
729
+ if( x<0 )
730
+ {
731
+ z = -z;
732
+ }
733
+ result = z;
734
+ return result;
735
+ }
736
+
737
+
738
+ /*************************************************************************
739
+ Modified Bessel function, second kind, order zero
740
+
741
+ Returns modified Bessel function of the second kind
742
+ of order zero of the argument.
743
+
744
+ The range is partitioned into the two intervals [0,8] and
745
+ (8, infinity). Chebyshev polynomial expansions are employed
746
+ in each interval.
747
+
748
+ ACCURACY:
749
+
750
+ Tested at 2000 random points between 0 and 8. Peak absolute
751
+ error (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15.
752
+ Relative error:
753
+ arithmetic domain # trials peak rms
754
+ IEEE 0, 30 30000 1.2e-15 1.6e-16
755
+
756
+ Cephes Math Library Release 2.8: June, 2000
757
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
758
+ *************************************************************************/
759
+ double besselk0(double x)
760
+ {
761
+ double result;
762
+ double y;
763
+ double z;
764
+ double v;
765
+ double b0;
766
+ double b1;
767
+ double b2;
768
+
769
+ ap::ap_error::make_assertion(x>0, "Domain error in BesselK0: x<=0");
770
+ if( x<=2 )
771
+ {
772
+ y = x*x-2.0;
773
+ besselmfirstcheb(1.37446543561352307156E-16, b0, b1, b2);
774
+ besselmnextcheb(y, 4.25981614279661018399E-14, b0, b1, b2);
775
+ besselmnextcheb(y, 1.03496952576338420167E-11, b0, b1, b2);
776
+ besselmnextcheb(y, 1.90451637722020886025E-9, b0, b1, b2);
777
+ besselmnextcheb(y, 2.53479107902614945675E-7, b0, b1, b2);
778
+ besselmnextcheb(y, 2.28621210311945178607E-5, b0, b1, b2);
779
+ besselmnextcheb(y, 1.26461541144692592338E-3, b0, b1, b2);
780
+ besselmnextcheb(y, 3.59799365153615016266E-2, b0, b1, b2);
781
+ besselmnextcheb(y, 3.44289899924628486886E-1, b0, b1, b2);
782
+ besselmnextcheb(y, -5.35327393233902768720E-1, b0, b1, b2);
783
+ v = 0.5*(b0-b2);
784
+ v = v-log(0.5*x)*besseli0(x);
785
+ }
786
+ else
787
+ {
788
+ z = 8.0/x-2.0;
789
+ besselmfirstcheb(5.30043377268626276149E-18, b0, b1, b2);
790
+ besselmnextcheb(z, -1.64758043015242134646E-17, b0, b1, b2);
791
+ besselmnextcheb(z, 5.21039150503902756861E-17, b0, b1, b2);
792
+ besselmnextcheb(z, -1.67823109680541210385E-16, b0, b1, b2);
793
+ besselmnextcheb(z, 5.51205597852431940784E-16, b0, b1, b2);
794
+ besselmnextcheb(z, -1.84859337734377901440E-15, b0, b1, b2);
795
+ besselmnextcheb(z, 6.34007647740507060557E-15, b0, b1, b2);
796
+ besselmnextcheb(z, -2.22751332699166985548E-14, b0, b1, b2);
797
+ besselmnextcheb(z, 8.03289077536357521100E-14, b0, b1, b2);
798
+ besselmnextcheb(z, -2.98009692317273043925E-13, b0, b1, b2);
799
+ besselmnextcheb(z, 1.14034058820847496303E-12, b0, b1, b2);
800
+ besselmnextcheb(z, -4.51459788337394416547E-12, b0, b1, b2);
801
+ besselmnextcheb(z, 1.85594911495471785253E-11, b0, b1, b2);
802
+ besselmnextcheb(z, -7.95748924447710747776E-11, b0, b1, b2);
803
+ besselmnextcheb(z, 3.57739728140030116597E-10, b0, b1, b2);
804
+ besselmnextcheb(z, -1.69753450938905987466E-9, b0, b1, b2);
805
+ besselmnextcheb(z, 8.57403401741422608519E-9, b0, b1, b2);
806
+ besselmnextcheb(z, -4.66048989768794782956E-8, b0, b1, b2);
807
+ besselmnextcheb(z, 2.76681363944501510342E-7, b0, b1, b2);
808
+ besselmnextcheb(z, -1.83175552271911948767E-6, b0, b1, b2);
809
+ besselmnextcheb(z, 1.39498137188764993662E-5, b0, b1, b2);
810
+ besselmnextcheb(z, -1.28495495816278026384E-4, b0, b1, b2);
811
+ besselmnextcheb(z, 1.56988388573005337491E-3, b0, b1, b2);
812
+ besselmnextcheb(z, -3.14481013119645005427E-2, b0, b1, b2);
813
+ besselmnextcheb(z, 2.44030308206595545468E0, b0, b1, b2);
814
+ v = 0.5*(b0-b2);
815
+ v = v*exp(-x)/sqrt(x);
816
+ }
817
+ result = v;
818
+ return result;
819
+ }
820
+
821
+
822
+ /*************************************************************************
823
+ Modified Bessel function, second kind, order one
824
+
825
+ Computes the modified Bessel function of the second kind
826
+ of order one of the argument.
827
+
828
+ The range is partitioned into the two intervals [0,2] and
829
+ (2, infinity). Chebyshev polynomial expansions are employed
830
+ in each interval.
831
+
832
+ ACCURACY:
833
+
834
+ Relative error:
835
+ arithmetic domain # trials peak rms
836
+ IEEE 0, 30 30000 1.2e-15 1.6e-16
837
+
838
+ Cephes Math Library Release 2.8: June, 2000
839
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
840
+ *************************************************************************/
841
+ double besselk1(double x)
842
+ {
843
+ double result;
844
+ double y;
845
+ double z;
846
+ double v;
847
+ double b0;
848
+ double b1;
849
+ double b2;
850
+
851
+ z = 0.5*x;
852
+ ap::ap_error::make_assertion(z>0, "Domain error in K1");
853
+ if( x<=2 )
854
+ {
855
+ y = x*x-2.0;
856
+ besselm1firstcheb(-7.02386347938628759343E-18, b0, b1, b2);
857
+ besselm1nextcheb(y, -2.42744985051936593393E-15, b0, b1, b2);
858
+ besselm1nextcheb(y, -6.66690169419932900609E-13, b0, b1, b2);
859
+ besselm1nextcheb(y, -1.41148839263352776110E-10, b0, b1, b2);
860
+ besselm1nextcheb(y, -2.21338763073472585583E-8, b0, b1, b2);
861
+ besselm1nextcheb(y, -2.43340614156596823496E-6, b0, b1, b2);
862
+ besselm1nextcheb(y, -1.73028895751305206302E-4, b0, b1, b2);
863
+ besselm1nextcheb(y, -6.97572385963986435018E-3, b0, b1, b2);
864
+ besselm1nextcheb(y, -1.22611180822657148235E-1, b0, b1, b2);
865
+ besselm1nextcheb(y, -3.53155960776544875667E-1, b0, b1, b2);
866
+ besselm1nextcheb(y, 1.52530022733894777053E0, b0, b1, b2);
867
+ v = 0.5*(b0-b2);
868
+ result = log(z)*besseli1(x)+v/x;
869
+ }
870
+ else
871
+ {
872
+ y = 8.0/x-2.0;
873
+ besselm1firstcheb(-5.75674448366501715755E-18, b0, b1, b2);
874
+ besselm1nextcheb(y, 1.79405087314755922667E-17, b0, b1, b2);
875
+ besselm1nextcheb(y, -5.68946255844285935196E-17, b0, b1, b2);
876
+ besselm1nextcheb(y, 1.83809354436663880070E-16, b0, b1, b2);
877
+ besselm1nextcheb(y, -6.05704724837331885336E-16, b0, b1, b2);
878
+ besselm1nextcheb(y, 2.03870316562433424052E-15, b0, b1, b2);
879
+ besselm1nextcheb(y, -7.01983709041831346144E-15, b0, b1, b2);
880
+ besselm1nextcheb(y, 2.47715442448130437068E-14, b0, b1, b2);
881
+ besselm1nextcheb(y, -8.97670518232499435011E-14, b0, b1, b2);
882
+ besselm1nextcheb(y, 3.34841966607842919884E-13, b0, b1, b2);
883
+ besselm1nextcheb(y, -1.28917396095102890680E-12, b0, b1, b2);
884
+ besselm1nextcheb(y, 5.13963967348173025100E-12, b0, b1, b2);
885
+ besselm1nextcheb(y, -2.12996783842756842877E-11, b0, b1, b2);
886
+ besselm1nextcheb(y, 9.21831518760500529508E-11, b0, b1, b2);
887
+ besselm1nextcheb(y, -4.19035475934189648750E-10, b0, b1, b2);
888
+ besselm1nextcheb(y, 2.01504975519703286596E-9, b0, b1, b2);
889
+ besselm1nextcheb(y, -1.03457624656780970260E-8, b0, b1, b2);
890
+ besselm1nextcheb(y, 5.74108412545004946722E-8, b0, b1, b2);
891
+ besselm1nextcheb(y, -3.50196060308781257119E-7, b0, b1, b2);
892
+ besselm1nextcheb(y, 2.40648494783721712015E-6, b0, b1, b2);
893
+ besselm1nextcheb(y, -1.93619797416608296024E-5, b0, b1, b2);
894
+ besselm1nextcheb(y, 1.95215518471351631108E-4, b0, b1, b2);
895
+ besselm1nextcheb(y, -2.85781685962277938680E-3, b0, b1, b2);
896
+ besselm1nextcheb(y, 1.03923736576817238437E-1, b0, b1, b2);
897
+ besselm1nextcheb(y, 2.72062619048444266945E0, b0, b1, b2);
898
+ v = 0.5*(b0-b2);
899
+ result = exp(-x)*v/sqrt(x);
900
+ }
901
+ return result;
902
+ }
903
+
904
+
905
+ /*************************************************************************
906
+ Modified Bessel function, second kind, integer order
907
+
908
+ Returns modified Bessel function of the second kind
909
+ of order n of the argument.
910
+
911
+ The range is partitioned into the two intervals [0,9.55] and
912
+ (9.55, infinity). An ascending power series is used in the
913
+ low range, and an asymptotic expansion in the high range.
914
+
915
+ ACCURACY:
916
+
917
+ Relative error:
918
+ arithmetic domain # trials peak rms
919
+ IEEE 0,30 90000 1.8e-8 3.0e-10
920
+
921
+ Error is high only near the crossover point x = 9.55
922
+ between the two expansions used.
923
+
924
+ Cephes Math Library Release 2.8: June, 2000
925
+ Copyright 1984, 1987, 1988, 2000 by Stephen L. Moshier
926
+ *************************************************************************/
927
+ double besselkn(int nn, double x)
928
+ {
929
+ double result;
930
+ double k;
931
+ double kf;
932
+ double nk1f;
933
+ double nkf;
934
+ double zn;
935
+ double t;
936
+ double s;
937
+ double z0;
938
+ double z;
939
+ double ans;
940
+ double fn;
941
+ double pn;
942
+ double pk;
943
+ double zmn;
944
+ double tlg;
945
+ double tox;
946
+ int i;
947
+ int n;
948
+ double eul;
949
+
950
+ eul = 5.772156649015328606065e-1;
951
+ if( nn<0 )
952
+ {
953
+ n = -nn;
954
+ }
955
+ else
956
+ {
957
+ n = nn;
958
+ }
959
+ ap::ap_error::make_assertion(n<=31, "Overflow in BesselKN");
960
+ ap::ap_error::make_assertion(x>0, "Domain error in BesselKN");
961
+ if( x<=9.55 )
962
+ {
963
+ ans = 0.0;
964
+ z0 = 0.25*x*x;
965
+ fn = 1.0;
966
+ pn = 0.0;
967
+ zmn = 1.0;
968
+ tox = 2.0/x;
969
+ if( n>0 )
970
+ {
971
+ pn = -eul;
972
+ k = 1.0;
973
+ for(i = 1; i <= n-1; i++)
974
+ {
975
+ pn = pn+1.0/k;
976
+ k = k+1.0;
977
+ fn = fn*k;
978
+ }
979
+ zmn = tox;
980
+ if( n==1 )
981
+ {
982
+ ans = 1.0/x;
983
+ }
984
+ else
985
+ {
986
+ nk1f = fn/n;
987
+ kf = 1.0;
988
+ s = nk1f;
989
+ z = -z0;
990
+ zn = 1.0;
991
+ for(i = 1; i <= n-1; i++)
992
+ {
993
+ nk1f = nk1f/(n-i);
994
+ kf = kf*i;
995
+ zn = zn*z;
996
+ t = nk1f*zn/kf;
997
+ s = s+t;
998
+ ap::ap_error::make_assertion(ap::maxrealnumber-fabs(t)>fabs(s), "Overflow in BesselKN");
999
+ ap::ap_error::make_assertion(!(tox>1.0&&ap::maxrealnumber/tox<zmn), "Overflow in BesselKN");
1000
+ zmn = zmn*tox;
1001
+ }
1002
+ s = s*0.5;
1003
+ t = fabs(s);
1004
+ ap::ap_error::make_assertion(!(zmn>1.0&&ap::maxrealnumber/zmn<t), "Overflow in BesselKN");
1005
+ ap::ap_error::make_assertion(!(t>1.0&&ap::maxrealnumber/t<zmn), "Overflow in BesselKN");
1006
+ ans = s*zmn;
1007
+ }
1008
+ }
1009
+ tlg = 2.0*log(0.5*x);
1010
+ pk = -eul;
1011
+ if( n==0 )
1012
+ {
1013
+ pn = pk;
1014
+ t = 1.0;
1015
+ }
1016
+ else
1017
+ {
1018
+ pn = pn+1.0/n;
1019
+ t = 1.0/fn;
1020
+ }
1021
+ s = (pk+pn-tlg)*t;
1022
+ k = 1.0;
1023
+ do
1024
+ {
1025
+ t = t*(z0/(k*(k+n)));
1026
+ pk = pk+1.0/k;
1027
+ pn = pn+1.0/(k+n);
1028
+ s = s+(pk+pn-tlg)*t;
1029
+ k = k+1.0;
1030
+ }
1031
+ while(fabs(t/s)>ap::machineepsilon);
1032
+ s = 0.5*s/zmn;
1033
+ if( n%2!=0 )
1034
+ {
1035
+ s = -s;
1036
+ }
1037
+ ans = ans+s;
1038
+ result = ans;
1039
+ return result;
1040
+ }
1041
+ if( x>log(ap::maxrealnumber) )
1042
+ {
1043
+ result = 0;
1044
+ return result;
1045
+ }
1046
+ k = n;
1047
+ pn = 4.0*k*k;
1048
+ pk = 1.0;
1049
+ z0 = 8.0*x;
1050
+ fn = 1.0;
1051
+ t = 1.0;
1052
+ s = t;
1053
+ nkf = ap::maxrealnumber;
1054
+ i = 0;
1055
+ do
1056
+ {
1057
+ z = pn-pk*pk;
1058
+ t = t*z/(fn*z0);
1059
+ nk1f = fabs(t);
1060
+ if( i>=n&&nk1f>nkf )
1061
+ {
1062
+ break;
1063
+ }
1064
+ nkf = nk1f;
1065
+ s = s+t;
1066
+ fn = fn+1.0;
1067
+ pk = pk+2.0;
1068
+ i = i+1;
1069
+ }
1070
+ while(fabs(t/s)>ap::machineepsilon);
1071
+ result = exp(-x)*sqrt(ap::pi()/(2.0*x))*s;
1072
+ return result;
1073
+ }
1074
+
1075
+
1076
+ /*************************************************************************
1077
+ Internal subroutine
1078
+
1079
+ Cephes Math Library Release 2.8: June, 2000
1080
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
1081
+ *************************************************************************/
1082
+ static void besselmfirstcheb(double c, double& b0, double& b1, double& b2)
1083
+ {
1084
+
1085
+ b0 = c;
1086
+ b1 = 0.0;
1087
+ b2 = 0.0;
1088
+ }
1089
+
1090
+
1091
+ /*************************************************************************
1092
+ Internal subroutine
1093
+
1094
+ Cephes Math Library Release 2.8: June, 2000
1095
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
1096
+ *************************************************************************/
1097
+ static void besselmnextcheb(double x,
1098
+ double c,
1099
+ double& b0,
1100
+ double& b1,
1101
+ double& b2)
1102
+ {
1103
+
1104
+ b2 = b1;
1105
+ b1 = b0;
1106
+ b0 = x*b1-b2+c;
1107
+ }
1108
+
1109
+
1110
+ /*************************************************************************
1111
+ Internal subroutine
1112
+
1113
+ Cephes Math Library Release 2.8: June, 2000
1114
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
1115
+ *************************************************************************/
1116
+ static void besselm1firstcheb(double c, double& b0, double& b1, double& b2)
1117
+ {
1118
+
1119
+ b0 = c;
1120
+ b1 = 0.0;
1121
+ b2 = 0.0;
1122
+ }
1123
+
1124
+
1125
+ /*************************************************************************
1126
+ Internal subroutine
1127
+
1128
+ Cephes Math Library Release 2.8: June, 2000
1129
+ Copyright 1984, 1987, 2000 by Stephen L. Moshier
1130
+ *************************************************************************/
1131
+ static void besselm1nextcheb(double x,
1132
+ double c,
1133
+ double& b0,
1134
+ double& b1,
1135
+ double& b2)
1136
+ {
1137
+
1138
+ b2 = b1;
1139
+ b1 = b0;
1140
+ b0 = x*b1-b2+c;
1141
+ }
1142
+
1143
+
1144
+ static void besselasympt0(double x, double& pzero, double& qzero)
1145
+ {
1146
+ double xsq;
1147
+ double p2;
1148
+ double q2;
1149
+ double p3;
1150
+ double q3;
1151
+
1152
+ xsq = 64.0/(x*x);
1153
+ p2 = 0.0;
1154
+ p2 = 2485.271928957404011288128951+xsq*p2;
1155
+ p2 = 153982.6532623911470917825993+xsq*p2;
1156
+ p2 = 2016135.283049983642487182349+xsq*p2;
1157
+ p2 = 8413041.456550439208464315611+xsq*p2;
1158
+ p2 = 12332384.76817638145232406055+xsq*p2;
1159
+ p2 = 5393485.083869438325262122897+xsq*p2;
1160
+ q2 = 1.0;
1161
+ q2 = 2615.700736920839685159081813+xsq*q2;
1162
+ q2 = 156001.7276940030940592769933+xsq*q2;
1163
+ q2 = 2025066.801570134013891035236+xsq*q2;
1164
+ q2 = 8426449.050629797331554404810+xsq*q2;
1165
+ q2 = 12338310.22786324960844856182+xsq*q2;
1166
+ q2 = 5393485.083869438325560444960+xsq*q2;
1167
+ p3 = -0.0;
1168
+ p3 = -4.887199395841261531199129300+xsq*p3;
1169
+ p3 = -226.2630641933704113967255053+xsq*p3;
1170
+ p3 = -2365.956170779108192723612816+xsq*p3;
1171
+ p3 = -8239.066313485606568803548860+xsq*p3;
1172
+ p3 = -10381.41698748464093880530341+xsq*p3;
1173
+ p3 = -3984.617357595222463506790588+xsq*p3;
1174
+ q3 = 1.0;
1175
+ q3 = 408.7714673983499223402830260+xsq*q3;
1176
+ q3 = 15704.89191515395519392882766+xsq*q3;
1177
+ q3 = 156021.3206679291652539287109+xsq*q3;
1178
+ q3 = 533291.3634216897168722255057+xsq*q3;
1179
+ q3 = 666745.4239319826986004038103+xsq*q3;
1180
+ q3 = 255015.5108860942382983170882+xsq*q3;
1181
+ pzero = p2/q2;
1182
+ qzero = 8*p3/q3/x;
1183
+ }
1184
+
1185
+
1186
+ static void besselasympt1(double x, double& pzero, double& qzero)
1187
+ {
1188
+ double xsq;
1189
+ double p2;
1190
+ double q2;
1191
+ double p3;
1192
+ double q3;
1193
+
1194
+ xsq = 64.0/(x*x);
1195
+ p2 = -1611.616644324610116477412898;
1196
+ p2 = -109824.0554345934672737413139+xsq*p2;
1197
+ p2 = -1523529.351181137383255105722+xsq*p2;
1198
+ p2 = -6603373.248364939109255245434+xsq*p2;
1199
+ p2 = -9942246.505077641195658377899+xsq*p2;
1200
+ p2 = -4435757.816794127857114720794+xsq*p2;
1201
+ q2 = 1.0;
1202
+ q2 = -1455.009440190496182453565068+xsq*q2;
1203
+ q2 = -107263.8599110382011903063867+xsq*q2;
1204
+ q2 = -1511809.506634160881644546358+xsq*q2;
1205
+ q2 = -6585339.479723087072826915069+xsq*q2;
1206
+ q2 = -9934124.389934585658967556309+xsq*q2;
1207
+ q2 = -4435757.816794127856828016962+xsq*q2;
1208
+ p3 = 35.26513384663603218592175580;
1209
+ p3 = 1706.375429020768002061283546+xsq*p3;
1210
+ p3 = 18494.26287322386679652009819+xsq*p3;
1211
+ p3 = 66178.83658127083517939992166+xsq*p3;
1212
+ p3 = 85145.16067533570196555001171+xsq*p3;
1213
+ p3 = 33220.91340985722351859704442+xsq*p3;
1214
+ q3 = 1.0;
1215
+ q3 = 863.8367769604990967475517183+xsq*q3;
1216
+ q3 = 37890.22974577220264142952256+xsq*q3;
1217
+ q3 = 400294.4358226697511708610813+xsq*q3;
1218
+ q3 = 1419460.669603720892855755253+xsq*q3;
1219
+ q3 = 1819458.042243997298924553839+xsq*q3;
1220
+ q3 = 708712.8194102874357377502472+xsq*q3;
1221
+ pzero = p2/q2;
1222
+ qzero = 8*p3/q3/x;
1223
+ }
1224
+
1225
+
1226
+