k0f.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* k0f.c
  2. *
  3. * Modified Bessel function, third kind, order zero
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float x, y, k0f();
  10. *
  11. * y = k0f( x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns modified Bessel function of the third kind
  18. * of order zero of the argument.
  19. *
  20. * The range is partitioned into the two intervals [0,8] and
  21. * (8, infinity). Chebyshev polynomial expansions are employed
  22. * in each interval.
  23. *
  24. *
  25. *
  26. * ACCURACY:
  27. *
  28. * Tested at 2000 random points between 0 and 8. Peak absolute
  29. * error (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15.
  30. * Relative error:
  31. * arithmetic domain # trials peak rms
  32. * IEEE 0, 30 30000 7.8e-7 8.5e-8
  33. *
  34. * ERROR MESSAGES:
  35. *
  36. * message condition value returned
  37. * K0 domain x <= 0 MAXNUM
  38. *
  39. */
  40. /* k0ef()
  41. *
  42. * Modified Bessel function, third kind, order zero,
  43. * exponentially scaled
  44. *
  45. *
  46. *
  47. * SYNOPSIS:
  48. *
  49. * float x, y, k0ef();
  50. *
  51. * y = k0ef( x );
  52. *
  53. *
  54. *
  55. * DESCRIPTION:
  56. *
  57. * Returns exponentially scaled modified Bessel function
  58. * of the third kind of order zero of the argument.
  59. *
  60. *
  61. *
  62. * ACCURACY:
  63. *
  64. * Relative error:
  65. * arithmetic domain # trials peak rms
  66. * IEEE 0, 30 30000 8.1e-7 7.8e-8
  67. * See k0().
  68. *
  69. */
  70. /*
  71. Cephes Math Library Release 2.0: April, 1987
  72. Copyright 1984, 1987 by Stephen L. Moshier
  73. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  74. */
  75. #include <math.h>
  76. /* Chebyshev coefficients for K0(x) + log(x/2) I0(x)
  77. * in the interval [0,2]. The odd order coefficients are all
  78. * zero; only the even order coefficients are listed.
  79. *
  80. * lim(x->0){ K0(x) + log(x/2) I0(x) } = -EUL.
  81. */
  82. static float A[] =
  83. {
  84. 1.90451637722020886025E-9f,
  85. 2.53479107902614945675E-7f,
  86. 2.28621210311945178607E-5f,
  87. 1.26461541144692592338E-3f,
  88. 3.59799365153615016266E-2f,
  89. 3.44289899924628486886E-1f,
  90. -5.35327393233902768720E-1f
  91. };
  92. /* Chebyshev coefficients for exp(x) sqrt(x) K0(x)
  93. * in the inverted interval [2,infinity].
  94. *
  95. * lim(x->inf){ exp(x) sqrt(x) K0(x) } = sqrt(pi/2).
  96. */
  97. static float B[] = {
  98. -1.69753450938905987466E-9f,
  99. 8.57403401741422608519E-9f,
  100. -4.66048989768794782956E-8f,
  101. 2.76681363944501510342E-7f,
  102. -1.83175552271911948767E-6f,
  103. 1.39498137188764993662E-5f,
  104. -1.28495495816278026384E-4f,
  105. 1.56988388573005337491E-3f,
  106. -3.14481013119645005427E-2f,
  107. 2.44030308206595545468E0f
  108. };
  109. /* k0.c */
  110. extern float MAXNUMF;
  111. #ifdef ANSIC
  112. float chbevlf(float, float *, int);
  113. float expf(float), i0f(float), logf(float), sqrtf(float);
  114. #else
  115. float chbevlf(), expf(), i0f(), logf(), sqrtf();
  116. #endif
  117. float k0f( float xx )
  118. {
  119. float x, y, z;
  120. x = xx;
  121. if( x <= 0.0f )
  122. {
  123. mtherr( "k0f", DOMAIN );
  124. return( MAXNUMF );
  125. }
  126. if( x <= 2.0f )
  127. {
  128. y = x * x - 2.0f;
  129. y = chbevlf( y, A, 7 ) - logf( 0.5f * x ) * i0f(x);
  130. return( y );
  131. }
  132. z = 8.0f/x - 2.0f;
  133. y = expf(-x) * chbevlf( z, B, 10 ) / sqrtf(x);
  134. return(y);
  135. }
  136. float k0ef( float xx )
  137. {
  138. float x, y;
  139. x = xx;
  140. if( x <= 0.0f )
  141. {
  142. mtherr( "k0ef", DOMAIN );
  143. return( MAXNUMF );
  144. }
  145. if( x <= 2.0f )
  146. {
  147. y = x * x - 2.0f;
  148. y = chbevlf( y, A, 7 ) - logf( 0.5f * x ) * i0f(x);
  149. return( y * expf(x) );
  150. }
  151. y = chbevlf( 8.0f/x - 2.0f, B, 10 ) / sqrtf(x);
  152. return(y);
  153. }