Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scipy/special/_ellip_harm.py: 60%
15 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-12 06:31 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-12 06:31 +0000
1import numpy as np
3from ._ufuncs import _ellip_harm
4from ._ellip_harm_2 import _ellipsoid, _ellipsoid_norm
7def ellip_harm(h2, k2, n, p, s, signm=1, signn=1):
8 r"""
9 Ellipsoidal harmonic functions E^p_n(l)
11 These are also known as Lame functions of the first kind, and are
12 solutions to the Lame equation:
14 .. 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
16 where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not
17 returned) corresponding to the solutions.
19 Parameters
20 ----------
21 h2 : float
22 ``h**2``
23 k2 : float
24 ``k**2``; should be larger than ``h**2``
25 n : int
26 Degree
27 s : float
28 Coordinate
29 p : int
30 Order, can range between [1,2n+1]
31 signm : {1, -1}, optional
32 Sign of prefactor of functions. Can be +/-1. See Notes.
33 signn : {1, -1}, optional
34 Sign of prefactor of functions. Can be +/-1. See Notes.
36 Returns
37 -------
38 E : float
39 the harmonic :math:`E^p_n(s)`
41 See Also
42 --------
43 ellip_harm_2, ellip_normal
45 Notes
46 -----
47 The geometric interpretation of the ellipsoidal functions is
48 explained in [2]_, [3]_, [4]_. The `signm` and `signn` arguments control the
49 sign of prefactors for functions according to their type::
51 K : +1
52 L : signm
53 M : signn
54 N : signm*signn
56 .. versionadded:: 0.15.0
58 References
59 ----------
60 .. [1] Digital Library of Mathematical Functions 29.12
61 https://dlmf.nist.gov/29.12
62 .. [2] Bardhan and Knepley, "Computational science and
63 re-discovery: open-source implementations of
64 ellipsoidal harmonics for problems in potential theory",
65 Comput. Sci. Disc. 5, 014006 (2012)
66 :doi:`10.1088/1749-4699/5/1/014006`.
67 .. [3] David J.and Dechambre P, "Computation of Ellipsoidal
68 Gravity Field Harmonics for small solar system bodies"
69 pp. 30-36, 2000
70 .. [4] George Dassios, "Ellipsoidal Harmonics: Theory and Applications"
71 pp. 418, 2012
73 Examples
74 --------
75 >>> from scipy.special import ellip_harm
76 >>> w = ellip_harm(5,8,1,1,2.5)
77 >>> w
78 2.5
80 Check that the functions indeed are solutions to the Lame equation:
82 >>> import numpy as np
83 >>> from scipy.interpolate import UnivariateSpline
84 >>> def eigenvalue(f, df, ddf):
85 ... 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
86 ... return -r.mean(), r.std()
87 >>> s = np.linspace(0.1, 10, 200)
88 >>> k, h, n, p = 8.0, 2.2, 3, 2
89 >>> E = ellip_harm(h**2, k**2, n, p, s)
90 >>> E_spl = UnivariateSpline(s, E)
91 >>> a, a_err = eigenvalue(E_spl(s), E_spl(s,1), E_spl(s,2))
92 >>> a, a_err
93 (583.44366156701483, 6.4580890640310646e-11)
95 """
96 return _ellip_harm(h2, k2, n, p, s, signm, signn)
99_ellip_harm_2_vec = np.vectorize(_ellipsoid, otypes='d')
102def ellip_harm_2(h2, k2, n, p, s):
103 r"""
104 Ellipsoidal harmonic functions F^p_n(l)
106 These are also known as Lame functions of the second kind, and are
107 solutions to the Lame equation:
109 .. 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
111 where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not
112 returned) corresponding to the solutions.
114 Parameters
115 ----------
116 h2 : float
117 ``h**2``
118 k2 : float
119 ``k**2``; should be larger than ``h**2``
120 n : int
121 Degree.
122 p : int
123 Order, can range between [1,2n+1].
124 s : float
125 Coordinate
127 Returns
128 -------
129 F : float
130 The harmonic :math:`F^p_n(s)`
132 Notes
133 -----
134 Lame functions of the second kind are related to the functions of the first kind:
136 .. math::
138 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)}}
140 .. versionadded:: 0.15.0
142 See Also
143 --------
144 ellip_harm, ellip_normal
146 Examples
147 --------
148 >>> from scipy.special import ellip_harm_2
149 >>> w = ellip_harm_2(5,8,2,1,10)
150 >>> w
151 0.00108056853382
153 """
154 with np.errstate(all='ignore'):
155 return _ellip_harm_2_vec(h2, k2, n, p, s)
158def _ellip_normal_vec(h2, k2, n, p):
159 return _ellipsoid_norm(h2, k2, n, p)
162_ellip_normal_vec = np.vectorize(_ellip_normal_vec, otypes='d')
165def ellip_normal(h2, k2, n, p):
166 r"""
167 Ellipsoidal harmonic normalization constants gamma^p_n
169 The normalization constant is defined as
171 .. math::
173 \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)}
175 Parameters
176 ----------
177 h2 : float
178 ``h**2``
179 k2 : float
180 ``k**2``; should be larger than ``h**2``
181 n : int
182 Degree.
183 p : int
184 Order, can range between [1,2n+1].
186 Returns
187 -------
188 gamma : float
189 The normalization constant :math:`\gamma^p_n`
191 See Also
192 --------
193 ellip_harm, ellip_harm_2
195 Notes
196 -----
197 .. versionadded:: 0.15.0
199 Examples
200 --------
201 >>> from scipy.special import ellip_normal
202 >>> w = ellip_normal(5,8,3,7)
203 >>> w
204 1723.38796997
206 """
207 with np.errstate(all='ignore'):
208 return _ellip_normal_vec(h2, k2, n, p)