gsl_specfunc__bessel_K1.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* specfunc/bessel_K1.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. /* Author: G. Jungman */
  20. #include "gsl__config.h"
  21. #include "gsl_math.h"
  22. #include "gsl_errno.h"
  23. #include "gsl_sf_exp.h"
  24. #include "gsl_sf_bessel.h"
  25. #include "gsl_specfunc__error.h"
  26. #include "gsl_specfunc__chebyshev.h"
  27. #include "gsl_specfunc__cheb_eval.c"
  28. /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
  29. /* based on SLATEC besk1(), besk1e() */
  30. /* chebyshev expansions
  31. series for bk1 on the interval 0. to 4.00000d+00
  32. with weighted error 7.02e-18
  33. log weighted error 17.15
  34. significant figures required 16.73
  35. decimal places required 17.67
  36. series for ak1 on the interval 1.25000d-01 to 5.00000d-01
  37. with weighted error 6.06e-17
  38. log weighted error 16.22
  39. significant figures required 15.41
  40. decimal places required 16.83
  41. series for ak12 on the interval 0. to 1.25000d-01
  42. with weighted error 2.58e-17
  43. log weighted error 16.59
  44. significant figures required 15.22
  45. decimal places required 17.16
  46. */
  47. static double bk1_data[11] = {
  48. 0.0253002273389477705,
  49. -0.3531559607765448760,
  50. -0.1226111808226571480,
  51. -0.0069757238596398643,
  52. -0.0001730288957513052,
  53. -0.0000024334061415659,
  54. -0.0000000221338763073,
  55. -0.0000000001411488392,
  56. -0.0000000000006666901,
  57. -0.0000000000000024274,
  58. -0.0000000000000000070
  59. };
  60. static cheb_series bk1_cs = {
  61. bk1_data,
  62. 10,
  63. -1, 1,
  64. 8
  65. };
  66. static double ak1_data[17] = {
  67. 0.27443134069738830,
  68. 0.07571989953199368,
  69. -0.00144105155647540,
  70. 0.00006650116955125,
  71. -0.00000436998470952,
  72. 0.00000035402774997,
  73. -0.00000003311163779,
  74. 0.00000000344597758,
  75. -0.00000000038989323,
  76. 0.00000000004720819,
  77. -0.00000000000604783,
  78. 0.00000000000081284,
  79. -0.00000000000011386,
  80. 0.00000000000001654,
  81. -0.00000000000000248,
  82. 0.00000000000000038,
  83. -0.00000000000000006
  84. };
  85. static cheb_series ak1_cs = {
  86. ak1_data,
  87. 16,
  88. -1, 1,
  89. 9
  90. };
  91. static double ak12_data[14] = {
  92. 0.06379308343739001,
  93. 0.02832887813049721,
  94. -0.00024753706739052,
  95. 0.00000577197245160,
  96. -0.00000020689392195,
  97. 0.00000000973998344,
  98. -0.00000000055853361,
  99. 0.00000000003732996,
  100. -0.00000000000282505,
  101. 0.00000000000023720,
  102. -0.00000000000002176,
  103. 0.00000000000000215,
  104. -0.00000000000000022,
  105. 0.00000000000000002
  106. };
  107. static cheb_series ak12_cs = {
  108. ak12_data,
  109. 13,
  110. -1, 1,
  111. 7
  112. };
  113. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  114. int gsl_sf_bessel_K1_scaled_e(const double x, gsl_sf_result * result)
  115. {
  116. /* CHECK_POINTER(result) */
  117. if(x <= 0.0) {
  118. DOMAIN_ERROR(result);
  119. }
  120. else if(x < 2.0*GSL_DBL_MIN) {
  121. OVERFLOW_ERROR(result);
  122. }
  123. else if(x <= 2.0) {
  124. const double lx = log(x);
  125. const double ex = exp(x);
  126. int stat_I1;
  127. gsl_sf_result I1;
  128. gsl_sf_result c;
  129. cheb_eval_e(&bk1_cs, 0.5*x*x-1.0, &c);
  130. stat_I1 = gsl_sf_bessel_I1_e(x, &I1);
  131. result->val = ex * ((lx-M_LN2)*I1.val + (0.75 + c.val)/x);
  132. result->err = ex * (c.err/x + fabs(lx)*I1.err);
  133. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  134. return stat_I1;
  135. }
  136. else if(x <= 8.0) {
  137. const double sx = sqrt(x);
  138. gsl_sf_result c;
  139. cheb_eval_e(&ak1_cs, (16.0/x-5.0)/3.0, &c);
  140. result->val = (1.25 + c.val) / sx;
  141. result->err = c.err / sx;
  142. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  143. return GSL_SUCCESS;
  144. }
  145. else {
  146. const double sx = sqrt(x);
  147. gsl_sf_result c;
  148. cheb_eval_e(&ak12_cs, 16.0/x-1.0, &c);
  149. result->val = (1.25 + c.val) / sx;
  150. result->err = c.err / sx;
  151. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  152. return GSL_SUCCESS;
  153. }
  154. }
  155. int gsl_sf_bessel_K1_e(const double x, gsl_sf_result * result)
  156. {
  157. /* CHECK_POINTER(result) */
  158. if(x <= 0.0) {
  159. DOMAIN_ERROR(result);
  160. }
  161. else if(x < 2.0*GSL_DBL_MIN) {
  162. OVERFLOW_ERROR(result);
  163. }
  164. else if(x <= 2.0) {
  165. const double lx = log(x);
  166. int stat_I1;
  167. gsl_sf_result I1;
  168. gsl_sf_result c;
  169. cheb_eval_e(&bk1_cs, 0.5*x*x-1.0, &c);
  170. stat_I1 = gsl_sf_bessel_I1_e(x, &I1);
  171. result->val = (lx-M_LN2)*I1.val + (0.75 + c.val)/x;
  172. result->err = c.err/x + fabs(lx)*I1.err;
  173. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  174. return stat_I1;
  175. }
  176. else {
  177. gsl_sf_result K1_scaled;
  178. int stat_K1 = gsl_sf_bessel_K1_scaled_e(x, &K1_scaled);
  179. int stat_e = gsl_sf_exp_mult_err_e(-x, 0.0,
  180. K1_scaled.val, K1_scaled.err,
  181. result);
  182. result->err = fabs(result->val) * (GSL_DBL_EPSILON*fabs(x) + K1_scaled.err/K1_scaled.val);
  183. return GSL_ERROR_SELECT_2(stat_e, stat_K1);
  184. }
  185. }
  186. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  187. #include "gsl_specfunc__eval.h"
  188. double gsl_sf_bessel_K1_scaled(const double x)
  189. {
  190. EVAL_RESULT(gsl_sf_bessel_K1_scaled_e(x, &result));
  191. }
  192. double gsl_sf_bessel_K1(const double x)
  193. {
  194. EVAL_RESULT(gsl_sf_bessel_K1_e(x, &result));
  195. }