gsl_specfunc__bessel_Ynu.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* specfunc/bessel_Ynu.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__bessel.h"
  26. #include "gsl_specfunc__bessel_olver.h"
  27. #include "gsl_specfunc__bessel_temme.h"
  28. /* Perform forward recurrence for Y_nu(x) and Y'_nu(x)
  29. *
  30. * Y_{nu+1} = nu/x Y_nu - Y'_nu
  31. * Y'_{nu+1} = -(nu+1)/x Y_{nu+1} + Y_nu
  32. */
  33. #if 0
  34. static
  35. int
  36. bessel_Y_recur(const double nu_min, const double x, const int kmax,
  37. const double Y_start, const double Yp_start,
  38. double * Y_end, double * Yp_end)
  39. {
  40. double x_inv = 1.0/x;
  41. double nu = nu_min;
  42. double Y_nu = Y_start;
  43. double Yp_nu = Yp_start;
  44. int k;
  45. for(k=1; k<=kmax; k++) {
  46. double nuox = nu*x_inv;
  47. double Y_nu_save = Y_nu;
  48. Y_nu = -Yp_nu + nuox * Y_nu;
  49. Yp_nu = Y_nu_save - (nuox+x_inv) * Y_nu;
  50. nu += 1.0;
  51. }
  52. *Y_end = Y_nu;
  53. *Yp_end = Yp_nu;
  54. return GSL_SUCCESS;
  55. }
  56. #endif
  57. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  58. int
  59. gsl_sf_bessel_Ynu_e(double nu, double x, gsl_sf_result * result)
  60. {
  61. /* CHECK_POINTER(result) */
  62. if(x <= 0.0 || nu < 0.0) {
  63. DOMAIN_ERROR(result);
  64. }
  65. else if(nu > 50.0) {
  66. return gsl_sf_bessel_Ynu_asymp_Olver_e(nu, x, result);
  67. }
  68. else {
  69. /* -1/2 <= mu <= 1/2 */
  70. int N = (int)(nu + 0.5);
  71. double mu = nu - N;
  72. gsl_sf_result Y_mu, Y_mup1;
  73. int stat_mu;
  74. double Ynm1;
  75. double Yn;
  76. double Ynp1;
  77. int n;
  78. if(x < 2.0) {
  79. /* Determine Ymu, Ymup1 directly. This is really
  80. * an optimization since this case could as well
  81. * be handled by a call to gsl_sf_bessel_JY_mu_restricted(),
  82. * as below.
  83. */
  84. stat_mu = gsl_sf_bessel_Y_temme(mu, x, &Y_mu, &Y_mup1);
  85. }
  86. else {
  87. /* Determine Ymu, Ymup1 and Jmu, Jmup1.
  88. */
  89. gsl_sf_result J_mu, J_mup1;
  90. stat_mu = gsl_sf_bessel_JY_mu_restricted(mu, x, &J_mu, &J_mup1, &Y_mu, &Y_mup1);
  91. }
  92. /* Forward recursion to get Ynu, Ynup1.
  93. */
  94. Ynm1 = Y_mu.val;
  95. Yn = Y_mup1.val;
  96. for(n=1; n<=N; n++) {
  97. Ynp1 = 2.0*(mu+n)/x * Yn - Ynm1;
  98. Ynm1 = Yn;
  99. Yn = Ynp1;
  100. }
  101. result->val = Ynm1; /* Y_nu */
  102. result->err = (N + 1.0) * fabs(Ynm1) * (fabs(Y_mu.err/Y_mu.val) + fabs(Y_mup1.err/Y_mup1.val));
  103. result->err += 2.0 * GSL_DBL_EPSILON * fabs(Ynm1);
  104. return stat_mu;
  105. }
  106. }
  107. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  108. #include "gsl_specfunc__eval.h"
  109. double gsl_sf_bessel_Ynu(const double nu, const double x)
  110. {
  111. EVAL_RESULT(gsl_sf_bessel_Ynu_e(nu, x, &result));
  112. }