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
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1""" This module contains the Mathieu functions.
2"""
4from sympy.core.function import Function, ArgumentIndexError
5from sympy.functions.elementary.miscellaneous import sqrt
6from sympy.functions.elementary.trigonometric import sin, cos
9class MathieuBase(Function):
10 """
11 Abstract base class for Mathieu functions.
13 This class is meant to reduce code duplication.
15 """
17 unbranched = True
19 def _eval_conjugate(self):
20 a, q, z = self.args
21 return self.func(a.conjugate(), q.conjugate(), z.conjugate())
24class mathieus(MathieuBase):
25 r"""
26 The Mathieu Sine function $S(a,q,z)$.
28 Explanation
29 ===========
31 This function is one solution of the Mathieu differential equation:
33 .. math ::
34 y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0
36 The other solution is the Mathieu Cosine function.
38 Examples
39 ========
41 >>> from sympy import diff, mathieus
42 >>> from sympy.abc import a, q, z
44 >>> mathieus(a, q, z)
45 mathieus(a, q, z)
47 >>> mathieus(a, 0, z)
48 sin(sqrt(a)*z)
50 >>> diff(mathieus(a, q, z), z)
51 mathieusprime(a, q, z)
53 See Also
54 ========
56 mathieuc: Mathieu cosine function.
57 mathieusprime: Derivative of Mathieu sine function.
58 mathieucprime: Derivative of Mathieu cosine function.
60 References
61 ==========
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/
68 """
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)
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)
86class mathieuc(MathieuBase):
87 r"""
88 The Mathieu Cosine function $C(a,q,z)$.
90 Explanation
91 ===========
93 This function is one solution of the Mathieu differential equation:
95 .. math ::
96 y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0
98 The other solution is the Mathieu Sine function.
100 Examples
101 ========
103 >>> from sympy import diff, mathieuc
104 >>> from sympy.abc import a, q, z
106 >>> mathieuc(a, q, z)
107 mathieuc(a, q, z)
109 >>> mathieuc(a, 0, z)
110 cos(sqrt(a)*z)
112 >>> diff(mathieuc(a, q, z), z)
113 mathieucprime(a, q, z)
115 See Also
116 ========
118 mathieus: Mathieu sine function
119 mathieusprime: Derivative of Mathieu sine function
120 mathieucprime: Derivative of Mathieu cosine function
122 References
123 ==========
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/
130 """
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)
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)
148class mathieusprime(MathieuBase):
149 r"""
150 The derivative $S^{\prime}(a,q,z)$ of the Mathieu Sine function.
152 Explanation
153 ===========
155 This function is one solution of the Mathieu differential equation:
157 .. math ::
158 y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0
160 The other solution is the Mathieu Cosine function.
162 Examples
163 ========
165 >>> from sympy import diff, mathieusprime
166 >>> from sympy.abc import a, q, z
168 >>> mathieusprime(a, q, z)
169 mathieusprime(a, q, z)
171 >>> mathieusprime(a, 0, z)
172 sqrt(a)*cos(sqrt(a)*z)
174 >>> diff(mathieusprime(a, q, z), z)
175 (-a + 2*q*cos(2*z))*mathieus(a, q, z)
177 See Also
178 ========
180 mathieus: Mathieu sine function
181 mathieuc: Mathieu cosine function
182 mathieucprime: Derivative of Mathieu cosine function
184 References
185 ==========
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/
192 """
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)
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)
210class mathieucprime(MathieuBase):
211 r"""
212 The derivative $C^{\prime}(a,q,z)$ of the Mathieu Cosine function.
214 Explanation
215 ===========
217 This function is one solution of the Mathieu differential equation:
219 .. math ::
220 y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0
222 The other solution is the Mathieu Sine function.
224 Examples
225 ========
227 >>> from sympy import diff, mathieucprime
228 >>> from sympy.abc import a, q, z
230 >>> mathieucprime(a, q, z)
231 mathieucprime(a, q, z)
233 >>> mathieucprime(a, 0, z)
234 -sqrt(a)*sin(sqrt(a)*z)
236 >>> diff(mathieucprime(a, q, z), z)
237 (-a + 2*q*cos(2*z))*mathieuc(a, q, z)
239 See Also
240 ========
242 mathieus: Mathieu sine function
243 mathieuc: Mathieu cosine function
244 mathieusprime: Derivative of Mathieu sine function
246 References
247 ==========
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/
254 """
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)
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)