gsl_specfunc__bessel_Inu.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* specfunc/bessel_Inu.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_gamma.h"
  25. #include "gsl_sf_bessel.h"
  26. #include "gsl_specfunc__error.h"
  27. #include "gsl_specfunc__bessel.h"
  28. #include "gsl_specfunc__bessel_temme.h"
  29. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  30. int
  31. gsl_sf_bessel_Inu_scaled_e(double nu, double x, gsl_sf_result * result)
  32. {
  33. /* CHECK_POINTER(result) */
  34. if(x < 0.0 || nu < 0.0) {
  35. DOMAIN_ERROR(result);
  36. }
  37. else if(x*x < 10.0*(nu+1.0)) {
  38. gsl_sf_result b;
  39. double ex = exp(-x);
  40. int stat = gsl_sf_bessel_IJ_taylor_e(nu, x, 1, 100, GSL_DBL_EPSILON, &b);
  41. result->val = b.val * ex;
  42. result->err = b.err * ex;
  43. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  44. return stat;
  45. }
  46. else if(0.5/(nu*nu + x*x) < GSL_ROOT3_DBL_EPSILON) {
  47. return gsl_sf_bessel_Inu_scaled_asymp_unif_e(nu, x, result);
  48. }
  49. else {
  50. int N = (int)(nu + 0.5);
  51. double mu = nu - N; /* -1/2 <= mu <= 1/2 */
  52. double K_mu, K_mup1, Kp_mu;
  53. double K_nu, K_nup1, K_num1;
  54. double I_nu_ratio;
  55. int stat_Irat;
  56. int stat_Kmu;
  57. int n;
  58. /* obtain K_mu, K_mup1 */
  59. if(x < 2.0) {
  60. stat_Kmu = gsl_sf_bessel_K_scaled_temme(mu, x, &K_mu, &K_mup1, &Kp_mu);
  61. }
  62. else {
  63. stat_Kmu = gsl_sf_bessel_K_scaled_steed_temme_CF2(mu, x, &K_mu, &K_mup1, &Kp_mu);
  64. }
  65. /* recurse forward to obtain K_num1, K_nu */
  66. K_nu = K_mu;
  67. K_nup1 = K_mup1;
  68. for(n=0; n<N; n++) {
  69. K_num1 = K_nu;
  70. K_nu = K_nup1;
  71. K_nup1 = 2.0*(mu+n+1)/x * K_nu + K_num1;
  72. }
  73. /* calculate I_{nu+1}/I_nu */
  74. stat_Irat = gsl_sf_bessel_I_CF1_ser(nu, x, &I_nu_ratio);
  75. /* solve for I_nu */
  76. result->val = 1.0/(x * (K_nup1 + I_nu_ratio * K_nu));
  77. result->err = GSL_DBL_EPSILON * (0.5*N + 2.0) * fabs(result->val);
  78. return GSL_ERROR_SELECT_2(stat_Kmu, stat_Irat);
  79. }
  80. }
  81. int
  82. gsl_sf_bessel_Inu_e(double nu, double x, gsl_sf_result * result)
  83. {
  84. gsl_sf_result b;
  85. int stat_I = gsl_sf_bessel_Inu_scaled_e(nu, x, &b);
  86. int stat_e = gsl_sf_exp_mult_err_e(x, fabs(x*GSL_DBL_EPSILON),
  87. b.val, b.err,
  88. result);
  89. return GSL_ERROR_SELECT_2(stat_e, stat_I);
  90. }
  91. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  92. #include "gsl_specfunc__eval.h"
  93. double gsl_sf_bessel_Inu_scaled(double nu, double x)
  94. {
  95. EVAL_RESULT(gsl_sf_bessel_Inu_scaled_e(nu, x, &result));
  96. }
  97. double gsl_sf_bessel_Inu(double nu, double x)
  98. {
  99. EVAL_RESULT(gsl_sf_bessel_Inu_e(nu, x, &result));
  100. }