_spherical_bessel.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. from __future__ import division, print_function, absolute_import
  2. from ._ufuncs import (_spherical_jn, _spherical_yn, _spherical_in,
  3. _spherical_kn, _spherical_jn_d, _spherical_yn_d,
  4. _spherical_in_d, _spherical_kn_d)
  5. def spherical_jn(n, z, derivative=False):
  6. r"""Spherical Bessel function of the first kind or its derivative.
  7. Defined as [1]_,
  8. .. math:: j_n(z) = \sqrt{\frac{\pi}{2z}} J_{n + 1/2}(z),
  9. where :math:`J_n` is the Bessel function of the first kind.
  10. Parameters
  11. ----------
  12. n : int, array_like
  13. Order of the Bessel function (n >= 0).
  14. z : complex or float, array_like
  15. Argument of the Bessel function.
  16. derivative : bool, optional
  17. If True, the value of the derivative (rather than the function
  18. itself) is returned.
  19. Returns
  20. -------
  21. jn : ndarray
  22. Notes
  23. -----
  24. For real arguments greater than the order, the function is computed
  25. using the ascending recurrence [2]_. For small real or complex
  26. arguments, the definitional relation to the cylindrical Bessel function
  27. of the first kind is used.
  28. The derivative is computed using the relations [3]_,
  29. .. math::
  30. j_n'(z) = j_{n-1}(z) - \frac{n + 1}{z} j_n(z).
  31. j_0'(z) = -j_1(z)
  32. .. versionadded:: 0.18.0
  33. References
  34. ----------
  35. .. [1] https://dlmf.nist.gov/10.47.E3
  36. .. [2] https://dlmf.nist.gov/10.51.E1
  37. .. [3] https://dlmf.nist.gov/10.51.E2
  38. """
  39. if derivative:
  40. return _spherical_jn_d(n, z)
  41. else:
  42. return _spherical_jn(n, z)
  43. def spherical_yn(n, z, derivative=False):
  44. r"""Spherical Bessel function of the second kind or its derivative.
  45. Defined as [1]_,
  46. .. math:: y_n(z) = \sqrt{\frac{\pi}{2z}} Y_{n + 1/2}(z),
  47. where :math:`Y_n` is the Bessel function of the second kind.
  48. Parameters
  49. ----------
  50. n : int, array_like
  51. Order of the Bessel function (n >= 0).
  52. z : complex or float, array_like
  53. Argument of the Bessel function.
  54. derivative : bool, optional
  55. If True, the value of the derivative (rather than the function
  56. itself) is returned.
  57. Returns
  58. -------
  59. yn : ndarray
  60. Notes
  61. -----
  62. For real arguments, the function is computed using the ascending
  63. recurrence [2]_. For complex arguments, the definitional relation to
  64. the cylindrical Bessel function of the second kind is used.
  65. The derivative is computed using the relations [3]_,
  66. .. math::
  67. y_n' = y_{n-1} - \frac{n + 1}{z} y_n.
  68. y_0' = -y_1
  69. .. versionadded:: 0.18.0
  70. References
  71. ----------
  72. .. [1] https://dlmf.nist.gov/10.47.E4
  73. .. [2] https://dlmf.nist.gov/10.51.E1
  74. .. [3] https://dlmf.nist.gov/10.51.E2
  75. """
  76. if derivative:
  77. return _spherical_yn_d(n, z)
  78. else:
  79. return _spherical_yn(n, z)
  80. def spherical_in(n, z, derivative=False):
  81. r"""Modified spherical Bessel function of the first kind or its derivative.
  82. Defined as [1]_,
  83. .. math:: i_n(z) = \sqrt{\frac{\pi}{2z}} I_{n + 1/2}(z),
  84. where :math:`I_n` is the modified Bessel function of the first kind.
  85. Parameters
  86. ----------
  87. n : int, array_like
  88. Order of the Bessel function (n >= 0).
  89. z : complex or float, array_like
  90. Argument of the Bessel function.
  91. derivative : bool, optional
  92. If True, the value of the derivative (rather than the function
  93. itself) is returned.
  94. Returns
  95. -------
  96. in : ndarray
  97. Notes
  98. -----
  99. The function is computed using its definitional relation to the
  100. modified cylindrical Bessel function of the first kind.
  101. The derivative is computed using the relations [2]_,
  102. .. math::
  103. i_n' = i_{n-1} - \frac{n + 1}{z} i_n.
  104. i_1' = i_0
  105. .. versionadded:: 0.18.0
  106. References
  107. ----------
  108. .. [1] https://dlmf.nist.gov/10.47.E7
  109. .. [2] https://dlmf.nist.gov/10.51.E5
  110. """
  111. if derivative:
  112. return _spherical_in_d(n, z)
  113. else:
  114. return _spherical_in(n, z)
  115. def spherical_kn(n, z, derivative=False):
  116. r"""Modified spherical Bessel function of the second kind or its derivative.
  117. Defined as [1]_,
  118. .. math:: k_n(z) = \sqrt{\frac{\pi}{2z}} K_{n + 1/2}(z),
  119. where :math:`K_n` is the modified Bessel function of the second kind.
  120. Parameters
  121. ----------
  122. n : int, array_like
  123. Order of the Bessel function (n >= 0).
  124. z : complex or float, array_like
  125. Argument of the Bessel function.
  126. derivative : bool, optional
  127. If True, the value of the derivative (rather than the function
  128. itself) is returned.
  129. Returns
  130. -------
  131. kn : ndarray
  132. Notes
  133. -----
  134. The function is computed using its definitional relation to the
  135. modified cylindrical Bessel function of the second kind.
  136. The derivative is computed using the relations [2]_,
  137. .. math::
  138. k_n' = -k_{n-1} - \frac{n + 1}{z} k_n.
  139. k_0' = -k_1
  140. .. versionadded:: 0.18.0
  141. References
  142. ----------
  143. .. [1] https://dlmf.nist.gov/10.47.E9
  144. .. [2] https://dlmf.nist.gov/10.51.E5
  145. """
  146. if derivative:
  147. return _spherical_kn_d(n, z)
  148. else:
  149. return _spherical_kn(n, z)