gsl_specfunc__bessel_I1.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* specfunc/bessel_I1.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. #define ROOT_EIGHT (2.0*M_SQRT2)
  28. /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
  29. /* based on SLATEC besi1(), besi1e() */
  30. /* chebyshev expansions
  31. series for bi1 on the interval 0. to 9.00000d+00
  32. with weighted error 2.40e-17
  33. log weighted error 16.62
  34. significant figures required 16.23
  35. decimal places required 17.14
  36. series for ai1 on the interval 1.25000d-01 to 3.33333d-01
  37. with weighted error 6.98e-17
  38. log weighted error 16.16
  39. significant figures required 14.53
  40. decimal places required 16.82
  41. series for ai12 on the interval 0. to 1.25000d-01
  42. with weighted error 3.55e-17
  43. log weighted error 16.45
  44. significant figures required 14.69
  45. decimal places required 17.12
  46. */
  47. static double bi1_data[11] = {
  48. -0.001971713261099859,
  49. 0.407348876675464810,
  50. 0.034838994299959456,
  51. 0.001545394556300123,
  52. 0.000041888521098377,
  53. 0.000000764902676483,
  54. 0.000000010042493924,
  55. 0.000000000099322077,
  56. 0.000000000000766380,
  57. 0.000000000000004741,
  58. 0.000000000000000024
  59. };
  60. static cheb_series bi1_cs = {
  61. bi1_data,
  62. 10,
  63. -1, 1,
  64. 10
  65. };
  66. static double ai1_data[21] = {
  67. -0.02846744181881479,
  68. -0.01922953231443221,
  69. -0.00061151858579437,
  70. -0.00002069971253350,
  71. 0.00000858561914581,
  72. 0.00000104949824671,
  73. -0.00000029183389184,
  74. -0.00000001559378146,
  75. 0.00000001318012367,
  76. -0.00000000144842341,
  77. -0.00000000029085122,
  78. 0.00000000012663889,
  79. -0.00000000001664947,
  80. -0.00000000000166665,
  81. 0.00000000000124260,
  82. -0.00000000000027315,
  83. 0.00000000000002023,
  84. 0.00000000000000730,
  85. -0.00000000000000333,
  86. 0.00000000000000071,
  87. -0.00000000000000006
  88. };
  89. static cheb_series ai1_cs = {
  90. ai1_data,
  91. 20,
  92. -1, 1,
  93. 11
  94. };
  95. static double ai12_data[22] = {
  96. 0.02857623501828014,
  97. -0.00976109749136147,
  98. -0.00011058893876263,
  99. -0.00000388256480887,
  100. -0.00000025122362377,
  101. -0.00000002631468847,
  102. -0.00000000383538039,
  103. -0.00000000055897433,
  104. -0.00000000001897495,
  105. 0.00000000003252602,
  106. 0.00000000001412580,
  107. 0.00000000000203564,
  108. -0.00000000000071985,
  109. -0.00000000000040836,
  110. -0.00000000000002101,
  111. 0.00000000000004273,
  112. 0.00000000000001041,
  113. -0.00000000000000382,
  114. -0.00000000000000186,
  115. 0.00000000000000033,
  116. 0.00000000000000028,
  117. -0.00000000000000003
  118. };
  119. static cheb_series ai12_cs = {
  120. ai12_data,
  121. 21,
  122. -1, 1,
  123. 9
  124. };
  125. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  126. int gsl_sf_bessel_I1_scaled_e(const double x, gsl_sf_result * result)
  127. {
  128. const double xmin = 2.0 * GSL_DBL_MIN;
  129. const double x_small = ROOT_EIGHT * GSL_SQRT_DBL_EPSILON;
  130. const double y = fabs(x);
  131. /* CHECK_POINTER(result) */
  132. if(y == 0.0) {
  133. result->val = 0.0;
  134. result->err = 0.0;
  135. return GSL_SUCCESS;
  136. }
  137. else if(y < xmin) {
  138. UNDERFLOW_ERROR(result);
  139. }
  140. else if(y < x_small) {
  141. result->val = 0.5*x;
  142. result->err = 0.0;
  143. return GSL_SUCCESS;
  144. }
  145. else if(y <= 3.0) {
  146. const double ey = exp(-y);
  147. gsl_sf_result c;
  148. cheb_eval_e(&bi1_cs, y*y/4.5-1.0, &c);
  149. result->val = x * ey * (0.875 + c.val);
  150. result->err = ey * c.err + y * GSL_DBL_EPSILON * fabs(result->val);
  151. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  152. return GSL_SUCCESS;
  153. }
  154. else if(y <= 8.0) {
  155. const double sy = sqrt(y);
  156. gsl_sf_result c;
  157. double b;
  158. double s;
  159. cheb_eval_e(&ai1_cs, (48.0/y-11.0)/5.0, &c);
  160. b = (0.375 + c.val) / sy;
  161. s = (x > 0.0 ? 1.0 : -1.0);
  162. result->val = s * b;
  163. result->err = c.err / sy;
  164. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  165. return GSL_SUCCESS;
  166. }
  167. else {
  168. const double sy = sqrt(y);
  169. gsl_sf_result c;
  170. double b;
  171. double s;
  172. cheb_eval_e(&ai12_cs, 16.0/y-1.0, &c);
  173. b = (0.375 + c.val) / sy;
  174. s = (x > 0.0 ? 1.0 : -1.0);
  175. result->val = s * b;
  176. result->err = c.err / sy;
  177. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  178. return GSL_SUCCESS;
  179. }
  180. }
  181. int gsl_sf_bessel_I1_e(const double x, gsl_sf_result * result)
  182. {
  183. const double xmin = 2.0 * GSL_DBL_MIN;
  184. const double x_small = ROOT_EIGHT * GSL_SQRT_DBL_EPSILON;
  185. const double y = fabs(x);
  186. /* CHECK_POINTER(result) */
  187. if(y == 0.0) {
  188. result->val = 0.0;
  189. result->err = 0.0;
  190. return GSL_SUCCESS;
  191. }
  192. else if(y < xmin) {
  193. UNDERFLOW_ERROR(result);
  194. }
  195. else if(y < x_small) {
  196. result->val = 0.5*x;
  197. result->err = 0.0;
  198. return GSL_SUCCESS;
  199. }
  200. else if(y <= 3.0) {
  201. gsl_sf_result c;
  202. cheb_eval_e(&bi1_cs, y*y/4.5-1.0, &c);
  203. result->val = x * (0.875 + c.val);
  204. result->err = y * c.err;
  205. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  206. return GSL_SUCCESS;
  207. }
  208. else if(y < GSL_LOG_DBL_MAX) {
  209. const double ey = exp(y);
  210. gsl_sf_result I1_scaled;
  211. gsl_sf_bessel_I1_scaled_e(x, &I1_scaled);
  212. result->val = ey * I1_scaled.val;
  213. result->err = ey * I1_scaled.err + y * GSL_DBL_EPSILON * fabs(result->val);
  214. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  215. return GSL_SUCCESS;
  216. }
  217. else {
  218. OVERFLOW_ERROR(result);
  219. }
  220. }
  221. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  222. #include "gsl_specfunc__eval.h"
  223. double gsl_sf_bessel_I1_scaled(const double x)
  224. {
  225. EVAL_RESULT(gsl_sf_bessel_I1_scaled_e(x, &result));
  226. }
  227. double gsl_sf_bessel_I1(const double x)
  228. {
  229. EVAL_RESULT(gsl_sf_bessel_I1_e(x, &result));
  230. }