mathieu_functions.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. """ This module contains the Mathieu functions.
  2. """
  3. from sympy.core.function import Function, ArgumentIndexError
  4. from sympy.functions.elementary.miscellaneous import sqrt
  5. from sympy.functions.elementary.trigonometric import sin, cos
  6. class MathieuBase(Function):
  7. """
  8. Abstract base class for Mathieu functions.
  9. This class is meant to reduce code duplication.
  10. """
  11. unbranched = True
  12. def _eval_conjugate(self):
  13. a, q, z = self.args
  14. return self.func(a.conjugate(), q.conjugate(), z.conjugate())
  15. class mathieus(MathieuBase):
  16. r"""
  17. The Mathieu Sine function $S(a,q,z)$.
  18. Explanation
  19. ===========
  20. This function is one solution of the Mathieu differential equation:
  21. .. math ::
  22. y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0
  23. The other solution is the Mathieu Cosine function.
  24. Examples
  25. ========
  26. >>> from sympy import diff, mathieus
  27. >>> from sympy.abc import a, q, z
  28. >>> mathieus(a, q, z)
  29. mathieus(a, q, z)
  30. >>> mathieus(a, 0, z)
  31. sin(sqrt(a)*z)
  32. >>> diff(mathieus(a, q, z), z)
  33. mathieusprime(a, q, z)
  34. See Also
  35. ========
  36. mathieuc: Mathieu cosine function.
  37. mathieusprime: Derivative of Mathieu sine function.
  38. mathieucprime: Derivative of Mathieu cosine function.
  39. References
  40. ==========
  41. .. [1] https://en.wikipedia.org/wiki/Mathieu_function
  42. .. [2] https://dlmf.nist.gov/28
  43. .. [3] https://mathworld.wolfram.com/MathieuFunction.html
  44. .. [4] https://functions.wolfram.com/MathieuandSpheroidalFunctions/MathieuS/
  45. """
  46. def fdiff(self, argindex=1):
  47. if argindex == 3:
  48. a, q, z = self.args
  49. return mathieusprime(a, q, z)
  50. else:
  51. raise ArgumentIndexError(self, argindex)
  52. @classmethod
  53. def eval(cls, a, q, z):
  54. if q.is_Number and q.is_zero:
  55. return sin(sqrt(a)*z)
  56. # Try to pull out factors of -1
  57. if z.could_extract_minus_sign():
  58. return -cls(a, q, -z)
  59. class mathieuc(MathieuBase):
  60. r"""
  61. The Mathieu Cosine function $C(a,q,z)$.
  62. Explanation
  63. ===========
  64. This function is one solution of the Mathieu differential equation:
  65. .. math ::
  66. y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0
  67. The other solution is the Mathieu Sine function.
  68. Examples
  69. ========
  70. >>> from sympy import diff, mathieuc
  71. >>> from sympy.abc import a, q, z
  72. >>> mathieuc(a, q, z)
  73. mathieuc(a, q, z)
  74. >>> mathieuc(a, 0, z)
  75. cos(sqrt(a)*z)
  76. >>> diff(mathieuc(a, q, z), z)
  77. mathieucprime(a, q, z)
  78. See Also
  79. ========
  80. mathieus: Mathieu sine function
  81. mathieusprime: Derivative of Mathieu sine function
  82. mathieucprime: Derivative of Mathieu cosine function
  83. References
  84. ==========
  85. .. [1] https://en.wikipedia.org/wiki/Mathieu_function
  86. .. [2] https://dlmf.nist.gov/28
  87. .. [3] https://mathworld.wolfram.com/MathieuFunction.html
  88. .. [4] https://functions.wolfram.com/MathieuandSpheroidalFunctions/MathieuC/
  89. """
  90. def fdiff(self, argindex=1):
  91. if argindex == 3:
  92. a, q, z = self.args
  93. return mathieucprime(a, q, z)
  94. else:
  95. raise ArgumentIndexError(self, argindex)
  96. @classmethod
  97. def eval(cls, a, q, z):
  98. if q.is_Number and q.is_zero:
  99. return cos(sqrt(a)*z)
  100. # Try to pull out factors of -1
  101. if z.could_extract_minus_sign():
  102. return cls(a, q, -z)
  103. class mathieusprime(MathieuBase):
  104. r"""
  105. The derivative $S^{\prime}(a,q,z)$ of the Mathieu Sine function.
  106. Explanation
  107. ===========
  108. This function is one solution of the Mathieu differential equation:
  109. .. math ::
  110. y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0
  111. The other solution is the Mathieu Cosine function.
  112. Examples
  113. ========
  114. >>> from sympy import diff, mathieusprime
  115. >>> from sympy.abc import a, q, z
  116. >>> mathieusprime(a, q, z)
  117. mathieusprime(a, q, z)
  118. >>> mathieusprime(a, 0, z)
  119. sqrt(a)*cos(sqrt(a)*z)
  120. >>> diff(mathieusprime(a, q, z), z)
  121. (-a + 2*q*cos(2*z))*mathieus(a, q, z)
  122. See Also
  123. ========
  124. mathieus: Mathieu sine function
  125. mathieuc: Mathieu cosine function
  126. mathieucprime: Derivative of Mathieu cosine function
  127. References
  128. ==========
  129. .. [1] https://en.wikipedia.org/wiki/Mathieu_function
  130. .. [2] https://dlmf.nist.gov/28
  131. .. [3] https://mathworld.wolfram.com/MathieuFunction.html
  132. .. [4] https://functions.wolfram.com/MathieuandSpheroidalFunctions/MathieuSPrime/
  133. """
  134. def fdiff(self, argindex=1):
  135. if argindex == 3:
  136. a, q, z = self.args
  137. return (2*q*cos(2*z) - a)*mathieus(a, q, z)
  138. else:
  139. raise ArgumentIndexError(self, argindex)
  140. @classmethod
  141. def eval(cls, a, q, z):
  142. if q.is_Number and q.is_zero:
  143. return sqrt(a)*cos(sqrt(a)*z)
  144. # Try to pull out factors of -1
  145. if z.could_extract_minus_sign():
  146. return cls(a, q, -z)
  147. class mathieucprime(MathieuBase):
  148. r"""
  149. The derivative $C^{\prime}(a,q,z)$ of the Mathieu Cosine function.
  150. Explanation
  151. ===========
  152. This function is one solution of the Mathieu differential equation:
  153. .. math ::
  154. y(x)^{\prime\prime} + (a - 2 q \cos(2 x)) y(x) = 0
  155. The other solution is the Mathieu Sine function.
  156. Examples
  157. ========
  158. >>> from sympy import diff, mathieucprime
  159. >>> from sympy.abc import a, q, z
  160. >>> mathieucprime(a, q, z)
  161. mathieucprime(a, q, z)
  162. >>> mathieucprime(a, 0, z)
  163. -sqrt(a)*sin(sqrt(a)*z)
  164. >>> diff(mathieucprime(a, q, z), z)
  165. (-a + 2*q*cos(2*z))*mathieuc(a, q, z)
  166. See Also
  167. ========
  168. mathieus: Mathieu sine function
  169. mathieuc: Mathieu cosine function
  170. mathieusprime: Derivative of Mathieu sine function
  171. References
  172. ==========
  173. .. [1] https://en.wikipedia.org/wiki/Mathieu_function
  174. .. [2] https://dlmf.nist.gov/28
  175. .. [3] https://mathworld.wolfram.com/MathieuFunction.html
  176. .. [4] https://functions.wolfram.com/MathieuandSpheroidalFunctions/MathieuCPrime/
  177. """
  178. def fdiff(self, argindex=1):
  179. if argindex == 3:
  180. a, q, z = self.args
  181. return (2*q*cos(2*z) - a)*mathieuc(a, q, z)
  182. else:
  183. raise ArgumentIndexError(self, argindex)
  184. @classmethod
  185. def eval(cls, a, q, z):
  186. if q.is_Number and q.is_zero:
  187. return -sqrt(a)*sin(sqrt(a)*z)
  188. # Try to pull out factors of -1
  189. if z.could_extract_minus_sign():
  190. return -cls(a, q, -z)