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

1import numpy as np 

2 

3from ._ufuncs import _ellip_harm 

4from ._ellip_harm_2 import _ellipsoid, _ellipsoid_norm 

5 

6 

7def ellip_harm(h2, k2, n, p, s, signm=1, signn=1): 

8 r""" 

9 Ellipsoidal harmonic functions E^p_n(l) 

10 

11 These are also known as Lame functions of the first kind, and are 

12 solutions to the Lame equation: 

13 

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 

15 

16 where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not 

17 returned) corresponding to the solutions. 

18 

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. 

35 

36 Returns 

37 ------- 

38 E : float 

39 the harmonic :math:`E^p_n(s)` 

40 

41 See Also 

42 -------- 

43 ellip_harm_2, ellip_normal 

44 

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:: 

50 

51 K : +1 

52 L : signm 

53 M : signn 

54 N : signm*signn 

55 

56 .. versionadded:: 0.15.0 

57 

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 

72 

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 

79 

80 Check that the functions indeed are solutions to the Lame equation: 

81 

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) 

94 

95 """ 

96 return _ellip_harm(h2, k2, n, p, s, signm, signn) 

97 

98 

99_ellip_harm_2_vec = np.vectorize(_ellipsoid, otypes='d') 

100 

101 

102def ellip_harm_2(h2, k2, n, p, s): 

103 r""" 

104 Ellipsoidal harmonic functions F^p_n(l) 

105 

106 These are also known as Lame functions of the second kind, and are 

107 solutions to the Lame equation: 

108 

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 

110 

111 where :math:`q = (n+1)n` and :math:`a` is the eigenvalue (not 

112 returned) corresponding to the solutions. 

113 

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 

126 

127 Returns 

128 ------- 

129 F : float 

130 The harmonic :math:`F^p_n(s)` 

131 

132 Notes 

133 ----- 

134 Lame functions of the second kind are related to the functions of the first kind: 

135 

136 .. math:: 

137 

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)}} 

139 

140 .. versionadded:: 0.15.0 

141 

142 See Also 

143 -------- 

144 ellip_harm, ellip_normal 

145 

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 

152 

153 """ 

154 with np.errstate(all='ignore'): 

155 return _ellip_harm_2_vec(h2, k2, n, p, s) 

156 

157 

158def _ellip_normal_vec(h2, k2, n, p): 

159 return _ellipsoid_norm(h2, k2, n, p) 

160 

161 

162_ellip_normal_vec = np.vectorize(_ellip_normal_vec, otypes='d') 

163 

164 

165def ellip_normal(h2, k2, n, p): 

166 r""" 

167 Ellipsoidal harmonic normalization constants gamma^p_n 

168 

169 The normalization constant is defined as 

170 

171 .. math:: 

172 

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)} 

174 

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]. 

185 

186 Returns 

187 ------- 

188 gamma : float 

189 The normalization constant :math:`\gamma^p_n` 

190 

191 See Also 

192 -------- 

193 ellip_harm, ellip_harm_2 

194 

195 Notes 

196 ----- 

197 .. versionadded:: 0.15.0 

198 

199 Examples 

200 -------- 

201 >>> from scipy.special import ellip_normal 

202 >>> w = ellip_normal(5,8,3,7) 

203 >>> w 

204 1723.38796997 

205 

206 """ 

207 with np.errstate(all='ignore'): 

208 return _ellip_normal_vec(h2, k2, n, p)