k1.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* k1.c
  2. *
  3. * Modified Bessel function, third kind, order one
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * double x, y, k1();
  10. *
  11. * y = k1( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Computes the modified Bessel function of the third kind
  18. * of order one of the argument.
  19. *
  20. * The range is partitioned into the two intervals [0,2] and
  21. * (2, infinity). Chebyshev polynomial expansions are employed
  22. * in each interval.
  23. *
  24. *
  25. *
  26. * ACCURACY:
  27. *
  28. * Relative error:
  29. * arithmetic domain # trials peak rms
  30. * DEC 0, 30 3300 8.9e-17 2.2e-17
  31. * IEEE 0, 30 30000 1.2e-15 1.6e-16
  32. *
  33. * ERROR MESSAGES:
  34. *
  35. * message condition value returned
  36. * k1 domain x <= 0 MAXNUM
  37. *
  38. */
  39. /* k1e.c
  40. *
  41. * Modified Bessel function, third kind, order one,
  42. * exponentially scaled
  43. *
  44. *
  45. *
  46. * SYNOPSIS:
  47. *
  48. * double x, y, k1e();
  49. *
  50. * y = k1e( x );
  51. *
  52. *
  53. *
  54. * DESCRIPTION:
  55. *
  56. * Returns exponentially scaled modified Bessel function
  57. * of the third kind of order one of the argument:
  58. *
  59. * k1e(x) = exp(x) * k1(x).
  60. *
  61. *
  62. *
  63. * ACCURACY:
  64. *
  65. * Relative error:
  66. * arithmetic domain # trials peak rms
  67. * IEEE 0, 30 30000 7.8e-16 1.2e-16
  68. * See k1().
  69. *
  70. */
  71. /*
  72. Cephes Math Library Release 2.8: June, 2000
  73. Copyright 1984, 1987, 2000 by Stephen L. Moshier
  74. */
  75. #include <math.h>
  76. /* Chebyshev coefficients for x(K1(x) - log(x/2) I1(x))
  77. * in the interval [0,2].
  78. *
  79. * lim(x->0){ x(K1(x) - log(x/2) I1(x)) } = 1.
  80. */
  81. #ifdef UNK
  82. static double A[] =
  83. {
  84. -7.02386347938628759343E-18,
  85. -2.42744985051936593393E-15,
  86. -6.66690169419932900609E-13,
  87. -1.41148839263352776110E-10,
  88. -2.21338763073472585583E-8,
  89. -2.43340614156596823496E-6,
  90. -1.73028895751305206302E-4,
  91. -6.97572385963986435018E-3,
  92. -1.22611180822657148235E-1,
  93. -3.53155960776544875667E-1,
  94. 1.52530022733894777053E0
  95. };
  96. #endif
  97. #ifdef DEC
  98. static unsigned short A[] = {
  99. 0122001,0110501,0164746,0151255,
  100. 0124056,0165213,0150034,0147377,
  101. 0126073,0124026,0167207,0001044,
  102. 0130033,0030735,0141061,0033116,
  103. 0131676,0020350,0121341,0107175,
  104. 0133443,0046631,0062031,0070716,
  105. 0135065,0067427,0026435,0164022,
  106. 0136344,0112234,0165752,0006222,
  107. 0137373,0015622,0017016,0155636,
  108. 0137664,0150333,0125730,0067240,
  109. 0040303,0036411,0130200,0043120
  110. };
  111. #endif
  112. #ifdef IBMPC
  113. static unsigned short A[] = {
  114. 0xda56,0x3d3c,0x3228,0xbc60,
  115. 0x99e0,0x7a03,0xdd51,0xbce5,
  116. 0xe045,0xddd0,0x7502,0xbd67,
  117. 0x26ca,0xb846,0x663b,0xbde3,
  118. 0x31d0,0x145c,0xc41d,0xbe57,
  119. 0x2e3a,0x2c83,0x69b3,0xbec4,
  120. 0xbd02,0xe5a3,0xade2,0xbf26,
  121. 0x4192,0x9d7d,0x9293,0xbf7c,
  122. 0xdb74,0x43c1,0x6372,0xbfbf,
  123. 0x0dd4,0x757b,0x9a1b,0xbfd6,
  124. 0x08ca,0x3610,0x67a1,0x3ff8
  125. };
  126. #endif
  127. #ifdef MIEEE
  128. static unsigned short A[] = {
  129. 0xbc60,0x3228,0x3d3c,0xda56,
  130. 0xbce5,0xdd51,0x7a03,0x99e0,
  131. 0xbd67,0x7502,0xddd0,0xe045,
  132. 0xbde3,0x663b,0xb846,0x26ca,
  133. 0xbe57,0xc41d,0x145c,0x31d0,
  134. 0xbec4,0x69b3,0x2c83,0x2e3a,
  135. 0xbf26,0xade2,0xe5a3,0xbd02,
  136. 0xbf7c,0x9293,0x9d7d,0x4192,
  137. 0xbfbf,0x6372,0x43c1,0xdb74,
  138. 0xbfd6,0x9a1b,0x757b,0x0dd4,
  139. 0x3ff8,0x67a1,0x3610,0x08ca
  140. };
  141. #endif
  142. /* Chebyshev coefficients for exp(x) sqrt(x) K1(x)
  143. * in the interval [2,infinity].
  144. *
  145. * lim(x->inf){ exp(x) sqrt(x) K1(x) } = sqrt(pi/2).
  146. */
  147. #ifdef UNK
  148. static double B[] =
  149. {
  150. -5.75674448366501715755E-18,
  151. 1.79405087314755922667E-17,
  152. -5.68946255844285935196E-17,
  153. 1.83809354436663880070E-16,
  154. -6.05704724837331885336E-16,
  155. 2.03870316562433424052E-15,
  156. -7.01983709041831346144E-15,
  157. 2.47715442448130437068E-14,
  158. -8.97670518232499435011E-14,
  159. 3.34841966607842919884E-13,
  160. -1.28917396095102890680E-12,
  161. 5.13963967348173025100E-12,
  162. -2.12996783842756842877E-11,
  163. 9.21831518760500529508E-11,
  164. -4.19035475934189648750E-10,
  165. 2.01504975519703286596E-9,
  166. -1.03457624656780970260E-8,
  167. 5.74108412545004946722E-8,
  168. -3.50196060308781257119E-7,
  169. 2.40648494783721712015E-6,
  170. -1.93619797416608296024E-5,
  171. 1.95215518471351631108E-4,
  172. -2.85781685962277938680E-3,
  173. 1.03923736576817238437E-1,
  174. 2.72062619048444266945E0
  175. };
  176. #endif
  177. #ifdef DEC
  178. static unsigned short B[] = {
  179. 0121724,0061352,0013041,0150076,
  180. 0022245,0074324,0016172,0173232,
  181. 0122603,0030250,0135670,0165221,
  182. 0023123,0165362,0023561,0060124,
  183. 0123456,0112436,0141654,0073623,
  184. 0024022,0163557,0077564,0006753,
  185. 0124374,0165221,0131014,0026524,
  186. 0024737,0017512,0144250,0175451,
  187. 0125312,0021456,0123136,0076633,
  188. 0025674,0077720,0020125,0102607,
  189. 0126265,0067543,0007744,0043701,
  190. 0026664,0152702,0033002,0074202,
  191. 0127273,0055234,0120016,0071733,
  192. 0027712,0133200,0042441,0075515,
  193. 0130346,0057000,0015456,0074470,
  194. 0031012,0074441,0051636,0111155,
  195. 0131461,0136444,0177417,0002101,
  196. 0032166,0111743,0032176,0021410,
  197. 0132674,0001224,0076555,0027060,
  198. 0033441,0077430,0135226,0106663,
  199. 0134242,0065610,0167155,0113447,
  200. 0035114,0131304,0043664,0102163,
  201. 0136073,0045065,0171465,0122123,
  202. 0037324,0152767,0147401,0017732,
  203. 0040456,0017275,0050061,0062120,
  204. };
  205. #endif
  206. #ifdef IBMPC
  207. static unsigned short B[] = {
  208. 0x3a08,0x42c4,0x8c5d,0xbc5a,
  209. 0x5ed3,0x838f,0xaf1a,0x3c74,
  210. 0x1d52,0x1777,0x6615,0xbc90,
  211. 0x2c0b,0x44ee,0x7d5e,0x3caa,
  212. 0x8ef2,0xd875,0xd2a3,0xbcc5,
  213. 0x81bd,0xefee,0x5ced,0x3ce2,
  214. 0x85ab,0x3641,0x9d52,0xbcff,
  215. 0x1f65,0x5915,0xe3e9,0x3d1b,
  216. 0xcfb3,0xd4cb,0x4465,0xbd39,
  217. 0xb0b1,0x040a,0x8ffa,0x3d57,
  218. 0x88f8,0x61fc,0xadec,0xbd76,
  219. 0x4f10,0x46c0,0x9ab8,0x3d96,
  220. 0xce7b,0x9401,0x6b53,0xbdb7,
  221. 0x2f6a,0x08a4,0x56d0,0x3dd9,
  222. 0xcf27,0x0365,0xcbc0,0xbdfc,
  223. 0xd24e,0x2a73,0x4f24,0x3e21,
  224. 0xe088,0x9fe1,0x37a4,0xbe46,
  225. 0xc461,0x668f,0xd27c,0x3e6e,
  226. 0xa5c6,0x8fad,0x8052,0xbe97,
  227. 0xd1b6,0x1752,0x2fe3,0x3ec4,
  228. 0xb2e5,0x1dcd,0x4d71,0xbef4,
  229. 0x908e,0x88f6,0x9658,0x3f29,
  230. 0xb48a,0xbe66,0x6946,0xbf67,
  231. 0x23fb,0xf9e0,0x9abe,0x3fba,
  232. 0x2c8a,0xaa06,0xc3d7,0x4005
  233. };
  234. #endif
  235. #ifdef MIEEE
  236. static unsigned short B[] = {
  237. 0xbc5a,0x8c5d,0x42c4,0x3a08,
  238. 0x3c74,0xaf1a,0x838f,0x5ed3,
  239. 0xbc90,0x6615,0x1777,0x1d52,
  240. 0x3caa,0x7d5e,0x44ee,0x2c0b,
  241. 0xbcc5,0xd2a3,0xd875,0x8ef2,
  242. 0x3ce2,0x5ced,0xefee,0x81bd,
  243. 0xbcff,0x9d52,0x3641,0x85ab,
  244. 0x3d1b,0xe3e9,0x5915,0x1f65,
  245. 0xbd39,0x4465,0xd4cb,0xcfb3,
  246. 0x3d57,0x8ffa,0x040a,0xb0b1,
  247. 0xbd76,0xadec,0x61fc,0x88f8,
  248. 0x3d96,0x9ab8,0x46c0,0x4f10,
  249. 0xbdb7,0x6b53,0x9401,0xce7b,
  250. 0x3dd9,0x56d0,0x08a4,0x2f6a,
  251. 0xbdfc,0xcbc0,0x0365,0xcf27,
  252. 0x3e21,0x4f24,0x2a73,0xd24e,
  253. 0xbe46,0x37a4,0x9fe1,0xe088,
  254. 0x3e6e,0xd27c,0x668f,0xc461,
  255. 0xbe97,0x8052,0x8fad,0xa5c6,
  256. 0x3ec4,0x2fe3,0x1752,0xd1b6,
  257. 0xbef4,0x4d71,0x1dcd,0xb2e5,
  258. 0x3f29,0x9658,0x88f6,0x908e,
  259. 0xbf67,0x6946,0xbe66,0xb48a,
  260. 0x3fba,0x9abe,0xf9e0,0x23fb,
  261. 0x4005,0xc3d7,0xaa06,0x2c8a
  262. };
  263. #endif
  264. #ifdef ANSIPROT
  265. extern double chbevl ( double, void *, int );
  266. extern double exp ( double );
  267. extern double i1 ( double );
  268. extern double log ( double );
  269. extern double sqrt ( double );
  270. #else
  271. double chbevl(), exp(), i1(), log(), sqrt();
  272. #endif
  273. extern double PI;
  274. extern double MINLOG, MAXNUM;
  275. double k1(x)
  276. double x;
  277. {
  278. double y, z;
  279. z = 0.5 * x;
  280. if( z <= 0.0 )
  281. {
  282. mtherr( "k1", DOMAIN );
  283. return( MAXNUM );
  284. }
  285. if( x <= 2.0 )
  286. {
  287. y = x * x - 2.0;
  288. y = log(z) * i1(x) + chbevl( y, A, 11 ) / x;
  289. return( y );
  290. }
  291. return( exp(-x) * chbevl( 8.0/x - 2.0, B, 25 ) / sqrt(x) );
  292. }
  293. double k1e( x )
  294. double x;
  295. {
  296. double y;
  297. if( x <= 0.0 )
  298. {
  299. mtherr( "k1e", DOMAIN );
  300. return( MAXNUM );
  301. }
  302. if( x <= 2.0 )
  303. {
  304. y = x * x - 2.0;
  305. y = log( 0.5 * x ) * i1(x) + chbevl( y, A, 11 ) / x;
  306. return( y * exp(x) );
  307. }
  308. return( chbevl( 8.0/x - 2.0, B, 25 ) / sqrt(x) );
  309. }