gsl_specfunc__bessel_I0.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* specfunc/bessel_I0.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_bessel.h"
  24. #include "gsl_specfunc__error.h"
  25. #include "gsl_specfunc__chebyshev.h"
  26. #include "gsl_specfunc__cheb_eval.c"
  27. /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
  28. /* based on SLATEC besi0 */
  29. /* chebyshev expansions
  30. series for bi0 on the interval 0. to 9.00000d+00
  31. with weighted error 2.46e-18
  32. log weighted error 17.61
  33. significant figures required 17.90
  34. decimal places required 18.15
  35. series for ai0 on the interval 1.25000d-01 to 3.33333d-01
  36. with weighted error 7.87e-17
  37. log weighted error 16.10
  38. significant figures required 14.69
  39. decimal places required 16.76
  40. series for ai02 on the interval 0. to 1.25000d-01
  41. with weighted error 3.79e-17
  42. log weighted error 16.42
  43. significant figures required 14.86
  44. decimal places required 17.09
  45. */
  46. static double bi0_data[12] = {
  47. -.07660547252839144951,
  48. 1.92733795399380827000,
  49. .22826445869203013390,
  50. .01304891466707290428,
  51. .00043442709008164874,
  52. .00000942265768600193,
  53. .00000014340062895106,
  54. .00000000161384906966,
  55. .00000000001396650044,
  56. .00000000000009579451,
  57. .00000000000000053339,
  58. .00000000000000000245
  59. };
  60. static cheb_series bi0_cs = {
  61. bi0_data,
  62. 11,
  63. -1, 1,
  64. 11
  65. };
  66. static double ai0_data[21] = {
  67. .07575994494023796,
  68. .00759138081082334,
  69. .00041531313389237,
  70. .00001070076463439,
  71. -.00000790117997921,
  72. -.00000078261435014,
  73. .00000027838499429,
  74. .00000000825247260,
  75. -.00000001204463945,
  76. .00000000155964859,
  77. .00000000022925563,
  78. -.00000000011916228,
  79. .00000000001757854,
  80. .00000000000112822,
  81. -.00000000000114684,
  82. .00000000000027155,
  83. -.00000000000002415,
  84. -.00000000000000608,
  85. .00000000000000314,
  86. -.00000000000000071,
  87. .00000000000000007
  88. };
  89. static cheb_series ai0_cs = {
  90. ai0_data,
  91. 20,
  92. -1, 1,
  93. 13
  94. };
  95. static double ai02_data[22] = {
  96. .05449041101410882,
  97. .00336911647825569,
  98. .00006889758346918,
  99. .00000289137052082,
  100. .00000020489185893,
  101. .00000002266668991,
  102. .00000000339623203,
  103. .00000000049406022,
  104. .00000000001188914,
  105. -.00000000003149915,
  106. -.00000000001321580,
  107. -.00000000000179419,
  108. .00000000000071801,
  109. .00000000000038529,
  110. .00000000000001539,
  111. -.00000000000004151,
  112. -.00000000000000954,
  113. .00000000000000382,
  114. .00000000000000176,
  115. -.00000000000000034,
  116. -.00000000000000027,
  117. .00000000000000003
  118. };
  119. static cheb_series ai02_cs = {
  120. ai02_data,
  121. 21,
  122. -1, 1,
  123. 11
  124. };
  125. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  126. int gsl_sf_bessel_I0_scaled_e(const double x, gsl_sf_result * result)
  127. {
  128. double y = fabs(x);
  129. /* CHECK_POINTER(result) */
  130. if(y < 2.0 * GSL_SQRT_DBL_EPSILON) {
  131. result->val = 1.0 - y;
  132. result->err = 0.5*y*y;
  133. return GSL_SUCCESS;
  134. }
  135. else if(y <= 3.0) {
  136. const double ey = exp(-y);
  137. gsl_sf_result c;
  138. cheb_eval_e(&bi0_cs, y*y/4.5-1.0, &c);
  139. result->val = ey * (2.75 + c.val);
  140. result->err = GSL_DBL_EPSILON * fabs(result->val) + ey * c.err;
  141. return GSL_SUCCESS;
  142. }
  143. else if(y <= 8.0) {
  144. const double sy = sqrt(y);
  145. gsl_sf_result c;
  146. cheb_eval_e(&ai0_cs, (48.0/y-11.0)/5.0, &c);
  147. result->val = (0.375 + c.val) / sy;
  148. result->err = 2.0 * GSL_DBL_EPSILON * (0.375 + fabs(c.val)) / sy;
  149. result->err += c.err / sy;
  150. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  151. return GSL_SUCCESS;
  152. }
  153. else {
  154. const double sy = sqrt(y);
  155. gsl_sf_result c;
  156. cheb_eval_e(&ai02_cs, 16.0/y-1.0, &c);
  157. result->val = (0.375 + c.val) / sy;
  158. result->err = 2.0 * GSL_DBL_EPSILON * (0.375 + fabs(c.val)) / sy;
  159. result->err += c.err / sy;
  160. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  161. return GSL_SUCCESS;
  162. }
  163. }
  164. int gsl_sf_bessel_I0_e(const double x, gsl_sf_result * result)
  165. {
  166. double y = fabs(x);
  167. /* CHECK_POINTER(result) */
  168. if(y < 2.0 * GSL_SQRT_DBL_EPSILON) {
  169. result->val = 1.0;
  170. result->err = 0.5*y*y;
  171. return GSL_SUCCESS;
  172. }
  173. else if(y <= 3.0) {
  174. gsl_sf_result c;
  175. cheb_eval_e(&bi0_cs, y*y/4.5-1.0, &c);
  176. result->val = 2.75 + c.val;
  177. result->err = GSL_DBL_EPSILON * (2.75 + fabs(c.val));
  178. result->err += c.err;
  179. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  180. return GSL_SUCCESS;
  181. }
  182. else if(y < GSL_LOG_DBL_MAX - 1.0) {
  183. const double ey = exp(y);
  184. gsl_sf_result b_scaled;
  185. gsl_sf_bessel_I0_scaled_e(x, &b_scaled);
  186. result->val = ey * b_scaled.val;
  187. result->err = ey * b_scaled.err + y*GSL_DBL_EPSILON*fabs(result->val);
  188. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  189. return GSL_SUCCESS;
  190. }
  191. else {
  192. OVERFLOW_ERROR(result);
  193. }
  194. }
  195. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  196. #include "gsl_specfunc__eval.h"
  197. double gsl_sf_bessel_I0_scaled(const double x)
  198. {
  199. EVAL_RESULT(gsl_sf_bessel_I0_scaled_e(x, &result); )
  200. }
  201. double gsl_sf_bessel_I0(const double x)
  202. {
  203. EVAL_RESULT(gsl_sf_bessel_I0_e(x, &result); )
  204. }