_ellip_harm.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import numpy as np
  2. from ._ufuncs import _ellip_harm
  3. from ._ellip_harm_2 import _ellipsoid, _ellipsoid_norm
  4. def ellip_harm(h2, k2, n, p, s, signm=1, signn=1):
  5. r"""
  6. Ellipsoidal harmonic functions E^p_n(l)
  7. These are also known as Lame functions of the first kind, and are
  8. solutions to the Lame equation:
  9. .. math:: (s^2 - h^2)(s^2 - k^2)E''(s) + s(2s^2 - h^2 - k^2)E'(s) + (a - q s^2)E(s) = 0
  10. where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not
  11. returned) corresponding to the solutions.
  12. Parameters
  13. ----------
  14. h2 : float
  15. ``h**2``
  16. k2 : float
  17. ``k**2``; should be larger than ``h**2``
  18. n : int
  19. Degree
  20. s : float
  21. Coordinate
  22. p : int
  23. Order, can range between [1,2n+1]
  24. signm : {1, -1}, optional
  25. Sign of prefactor of functions. Can be +/-1. See Notes.
  26. signn : {1, -1}, optional
  27. Sign of prefactor of functions. Can be +/-1. See Notes.
  28. Returns
  29. -------
  30. E : float
  31. the harmonic :math:`E^p_n(s)`
  32. See Also
  33. --------
  34. ellip_harm_2, ellip_normal
  35. Notes
  36. -----
  37. The geometric interpretation of the ellipsoidal functions is
  38. explained in [2]_, [3]_, [4]_. The `signm` and `signn` arguments control the
  39. sign of prefactors for functions according to their type::
  40. K : +1
  41. L : signm
  42. M : signn
  43. N : signm*signn
  44. .. versionadded:: 0.15.0
  45. References
  46. ----------
  47. .. [1] Digital Library of Mathematical Functions 29.12
  48. https://dlmf.nist.gov/29.12
  49. .. [2] Bardhan and Knepley, "Computational science and
  50. re-discovery: open-source implementations of
  51. ellipsoidal harmonics for problems in potential theory",
  52. Comput. Sci. Disc. 5, 014006 (2012)
  53. :doi:`10.1088/1749-4699/5/1/014006`.
  54. .. [3] David J.and Dechambre P, "Computation of Ellipsoidal
  55. Gravity Field Harmonics for small solar system bodies"
  56. pp. 30-36, 2000
  57. .. [4] George Dassios, "Ellipsoidal Harmonics: Theory and Applications"
  58. pp. 418, 2012
  59. Examples
  60. --------
  61. >>> from scipy.special import ellip_harm
  62. >>> w = ellip_harm(5,8,1,1,2.5)
  63. >>> w
  64. 2.5
  65. Check that the functions indeed are solutions to the Lame equation:
  66. >>> import numpy as np
  67. >>> from scipy.interpolate import UnivariateSpline
  68. >>> def eigenvalue(f, df, ddf):
  69. ... r = ((s**2 - h**2)*(s**2 - k**2)*ddf + s*(2*s**2 - h**2 - k**2)*df - n*(n+1)*s**2*f)/f
  70. ... return -r.mean(), r.std()
  71. >>> s = np.linspace(0.1, 10, 200)
  72. >>> k, h, n, p = 8.0, 2.2, 3, 2
  73. >>> E = ellip_harm(h**2, k**2, n, p, s)
  74. >>> E_spl = UnivariateSpline(s, E)
  75. >>> a, a_err = eigenvalue(E_spl(s), E_spl(s,1), E_spl(s,2))
  76. >>> a, a_err
  77. (583.44366156701483, 6.4580890640310646e-11)
  78. """
  79. return _ellip_harm(h2, k2, n, p, s, signm, signn)
  80. _ellip_harm_2_vec = np.vectorize(_ellipsoid, otypes='d')
  81. def ellip_harm_2(h2, k2, n, p, s):
  82. r"""
  83. Ellipsoidal harmonic functions F^p_n(l)
  84. These are also known as Lame functions of the second kind, and are
  85. solutions to the Lame equation:
  86. .. math:: (s^2 - h^2)(s^2 - k^2)F''(s) + s(2s^2 - h^2 - k^2)F'(s) + (a - q s^2)F(s) = 0
  87. where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not
  88. returned) corresponding to the solutions.
  89. Parameters
  90. ----------
  91. h2 : float
  92. ``h**2``
  93. k2 : float
  94. ``k**2``; should be larger than ``h**2``
  95. n : int
  96. Degree.
  97. p : int
  98. Order, can range between [1,2n+1].
  99. s : float
  100. Coordinate
  101. Returns
  102. -------
  103. F : float
  104. The harmonic :math:`F^p_n(s)`
  105. Notes
  106. -----
  107. Lame functions of the second kind are related to the functions of the first kind:
  108. .. math::
  109. F^p_n(s)=(2n + 1)E^p_n(s)\int_{0}^{1/s}\frac{du}{(E^p_n(1/u))^2\sqrt{(1-u^2k^2)(1-u^2h^2)}}
  110. .. versionadded:: 0.15.0
  111. See Also
  112. --------
  113. ellip_harm, ellip_normal
  114. Examples
  115. --------
  116. >>> from scipy.special import ellip_harm_2
  117. >>> w = ellip_harm_2(5,8,2,1,10)
  118. >>> w
  119. 0.00108056853382
  120. """
  121. with np.errstate(all='ignore'):
  122. return _ellip_harm_2_vec(h2, k2, n, p, s)
  123. def _ellip_normal_vec(h2, k2, n, p):
  124. return _ellipsoid_norm(h2, k2, n, p)
  125. _ellip_normal_vec = np.vectorize(_ellip_normal_vec, otypes='d')
  126. def ellip_normal(h2, k2, n, p):
  127. r"""
  128. Ellipsoidal harmonic normalization constants gamma^p_n
  129. The normalization constant is defined as
  130. .. math::
  131. \gamma^p_n=8\int_{0}^{h}dx\int_{h}^{k}dy\frac{(y^2-x^2)(E^p_n(y)E^p_n(x))^2}{\sqrt((k^2-y^2)(y^2-h^2)(h^2-x^2)(k^2-x^2)}
  132. Parameters
  133. ----------
  134. h2 : float
  135. ``h**2``
  136. k2 : float
  137. ``k**2``; should be larger than ``h**2``
  138. n : int
  139. Degree.
  140. p : int
  141. Order, can range between [1,2n+1].
  142. Returns
  143. -------
  144. gamma : float
  145. The normalization constant :math:`\gamma^p_n`
  146. See Also
  147. --------
  148. ellip_harm, ellip_harm_2
  149. Notes
  150. -----
  151. .. versionadded:: 0.15.0
  152. Examples
  153. --------
  154. >>> from scipy.special import ellip_normal
  155. >>> w = ellip_normal(5,8,3,7)
  156. >>> w
  157. 1723.38796997
  158. """
  159. with np.errstate(all='ignore'):
  160. return _ellip_normal_vec(h2, k2, n, p)