Coverage for /usr/lib/python3/dist-packages/sympy/functions/special/mathieu_functions.py: 39%

56 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-14 15:55 +0200

1""" This module contains the Mathieu functions. 

2""" 

3 

4from sympy.core.function import Function, ArgumentIndexError 

5from sympy.functions.elementary.miscellaneous import sqrt 

6from sympy.functions.elementary.trigonometric import sin, cos 

7 

8 

9class MathieuBase(Function): 

10 """ 

11 Abstract base class for Mathieu functions. 

12 

13 This class is meant to reduce code duplication. 

14 

15 """ 

16 

17 unbranched = True 

18 

19 def _eval_conjugate(self): 

20 a, q, z = self.args 

21 return self.func(a.conjugate(), q.conjugate(), z.conjugate()) 

22 

23 

24class mathieus(MathieuBase): 

25 r""" 

26 The Mathieu Sine function $S(a,q,z)$. 

27 

28 Explanation 

29 =========== 

30 

31 This function is one solution of the Mathieu differential equation: 

32 

33 .. math :: 

34 y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0 

35 

36 The other solution is the Mathieu Cosine function. 

37 

38 Examples 

39 ======== 

40 

41 >>> from sympy import diff, mathieus 

42 >>> from sympy.abc import a, q, z 

43 

44 >>> mathieus(a, q, z) 

45 mathieus(a, q, z) 

46 

47 >>> mathieus(a, 0, z) 

48 sin(sqrt(a)*z) 

49 

50 >>> diff(mathieus(a, q, z), z) 

51 mathieusprime(a, q, z) 

52 

53 See Also 

54 ======== 

55 

56 mathieuc: Mathieu cosine function. 

57 mathieusprime: Derivative of Mathieu sine function. 

58 mathieucprime: Derivative of Mathieu cosine function. 

59 

60 References 

61 ========== 

62 

63 .. [1] https://en.wikipedia.org/wiki/Mathieu_function 

64 .. [2] https://dlmf.nist.gov/28 

65 .. [3] https://mathworld.wolfram.com/MathieuFunction.html 

66 .. [4] https://functions.wolfram.com/MathieuandSpheroidalFunctions/MathieuS/ 

67 

68 """ 

69 

70 def fdiff(self, argindex=1): 

71 if argindex == 3: 

72 a, q, z = self.args 

73 return mathieusprime(a, q, z) 

74 else: 

75 raise ArgumentIndexError(self, argindex) 

76 

77 @classmethod 

78 def eval(cls, a, q, z): 

79 if q.is_Number and q.is_zero: 

80 return sin(sqrt(a)*z) 

81 # Try to pull out factors of -1 

82 if z.could_extract_minus_sign(): 

83 return -cls(a, q, -z) 

84 

85 

86class mathieuc(MathieuBase): 

87 r""" 

88 The Mathieu Cosine function $C(a,q,z)$. 

89 

90 Explanation 

91 =========== 

92 

93 This function is one solution of the Mathieu differential equation: 

94 

95 .. math :: 

96 y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0 

97 

98 The other solution is the Mathieu Sine function. 

99 

100 Examples 

101 ======== 

102 

103 >>> from sympy import diff, mathieuc 

104 >>> from sympy.abc import a, q, z 

105 

106 >>> mathieuc(a, q, z) 

107 mathieuc(a, q, z) 

108 

109 >>> mathieuc(a, 0, z) 

110 cos(sqrt(a)*z) 

111 

112 >>> diff(mathieuc(a, q, z), z) 

113 mathieucprime(a, q, z) 

114 

115 See Also 

116 ======== 

117 

118 mathieus: Mathieu sine function 

119 mathieusprime: Derivative of Mathieu sine function 

120 mathieucprime: Derivative of Mathieu cosine function 

121 

122 References 

123 ========== 

124 

125 .. [1] https://en.wikipedia.org/wiki/Mathieu_function 

126 .. [2] https://dlmf.nist.gov/28 

127 .. [3] https://mathworld.wolfram.com/MathieuFunction.html 

128 .. [4] https://functions.wolfram.com/MathieuandSpheroidalFunctions/MathieuC/ 

129 

130 """ 

131 

132 def fdiff(self, argindex=1): 

133 if argindex == 3: 

134 a, q, z = self.args 

135 return mathieucprime(a, q, z) 

136 else: 

137 raise ArgumentIndexError(self, argindex) 

138 

139 @classmethod 

140 def eval(cls, a, q, z): 

141 if q.is_Number and q.is_zero: 

142 return cos(sqrt(a)*z) 

143 # Try to pull out factors of -1 

144 if z.could_extract_minus_sign(): 

145 return cls(a, q, -z) 

146 

147 

148class mathieusprime(MathieuBase): 

149 r""" 

150 The derivative $S^{\prime}(a,q,z)$ of the Mathieu Sine function. 

151 

152 Explanation 

153 =========== 

154 

155 This function is one solution of the Mathieu differential equation: 

156 

157 .. math :: 

158 y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0 

159 

160 The other solution is the Mathieu Cosine function. 

161 

162 Examples 

163 ======== 

164 

165 >>> from sympy import diff, mathieusprime 

166 >>> from sympy.abc import a, q, z 

167 

168 >>> mathieusprime(a, q, z) 

169 mathieusprime(a, q, z) 

170 

171 >>> mathieusprime(a, 0, z) 

172 sqrt(a)*cos(sqrt(a)*z) 

173 

174 >>> diff(mathieusprime(a, q, z), z) 

175 (-a + 2*q*cos(2*z))*mathieus(a, q, z) 

176 

177 See Also 

178 ======== 

179 

180 mathieus: Mathieu sine function 

181 mathieuc: Mathieu cosine function 

182 mathieucprime: Derivative of Mathieu cosine function 

183 

184 References 

185 ========== 

186 

187 .. [1] https://en.wikipedia.org/wiki/Mathieu_function 

188 .. [2] https://dlmf.nist.gov/28 

189 .. [3] https://mathworld.wolfram.com/MathieuFunction.html 

190 .. [4] https://functions.wolfram.com/MathieuandSpheroidalFunctions/MathieuSPrime/ 

191 

192 """ 

193 

194 def fdiff(self, argindex=1): 

195 if argindex == 3: 

196 a, q, z = self.args 

197 return (2*q*cos(2*z) - a)*mathieus(a, q, z) 

198 else: 

199 raise ArgumentIndexError(self, argindex) 

200 

201 @classmethod 

202 def eval(cls, a, q, z): 

203 if q.is_Number and q.is_zero: 

204 return sqrt(a)*cos(sqrt(a)*z) 

205 # Try to pull out factors of -1 

206 if z.could_extract_minus_sign(): 

207 return cls(a, q, -z) 

208 

209 

210class mathieucprime(MathieuBase): 

211 r""" 

212 The derivative $C^{\prime}(a,q,z)$ of the Mathieu Cosine function. 

213 

214 Explanation 

215 =========== 

216 

217 This function is one solution of the Mathieu differential equation: 

218 

219 .. math :: 

220 y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0 

221 

222 The other solution is the Mathieu Sine function. 

223 

224 Examples 

225 ======== 

226 

227 >>> from sympy import diff, mathieucprime 

228 >>> from sympy.abc import a, q, z 

229 

230 >>> mathieucprime(a, q, z) 

231 mathieucprime(a, q, z) 

232 

233 >>> mathieucprime(a, 0, z) 

234 -sqrt(a)*sin(sqrt(a)*z) 

235 

236 >>> diff(mathieucprime(a, q, z), z) 

237 (-a + 2*q*cos(2*z))*mathieuc(a, q, z) 

238 

239 See Also 

240 ======== 

241 

242 mathieus: Mathieu sine function 

243 mathieuc: Mathieu cosine function 

244 mathieusprime: Derivative of Mathieu sine function 

245 

246 References 

247 ========== 

248 

249 .. [1] https://en.wikipedia.org/wiki/Mathieu_function 

250 .. [2] https://dlmf.nist.gov/28 

251 .. [3] https://mathworld.wolfram.com/MathieuFunction.html 

252 .. [4] https://functions.wolfram.com/MathieuandSpheroidalFunctions/MathieuCPrime/ 

253 

254 """ 

255 

256 def fdiff(self, argindex=1): 

257 if argindex == 3: 

258 a, q, z = self.args 

259 return (2*q*cos(2*z) - a)*mathieuc(a, q, z) 

260 else: 

261 raise ArgumentIndexError(self, argindex) 

262 

263 @classmethod 

264 def eval(cls, a, q, z): 

265 if q.is_Number and q.is_zero: 

266 return -sqrt(a)*sin(sqrt(a)*z) 

267 # Try to pull out factors of -1 

268 if z.could_extract_minus_sign(): 

269 return -cls(a, q, -z)