mathieu_even_coef#
- scipy.special.mathieu_even_coef(m, q)[source]#
Fourier coefficients for even Mathieu and modified Mathieu functions.
The Fourier series of the even solutions of the Mathieu differential equation are of the form
\[\mathrm{ce}_{2n}(z, q) = \sum_{k=0}^{\infty} A_{2k}^{(2n)}(q) \cos ((2k)z)\]\[\mathrm{ce}_{2n+1}(z, q) = \sum_{k=0}^{\infty} A_{2k+1}^{(2n+1)}(q) \cos ((2k+1)z)\]This function returns the coefficients \(A_{2k}^{(2n)}(q)\) for even input \(m=2n\), and the coefficients \(A_{2k+1}^{(2n+1)}(q)\) for odd input \(m=2n+1\).
- Parameters:
- mint
Order of Mathieu functions. Must be non-negative.
- qfloat
Parameter of Mathieu functions. Must be non-negative.
- Returns:
- Akndarray
Even or odd Fourier coefficients, corresponding to even or odd m. The number of coefficients returned is determined by an empirical formula that depends on \(m\) and \(q\) [1].
See also
Notes
Array API Standard Support
mathieu_even_coefis not in-scope for support of Python Array API Standard compatible backends other than NumPy.See Support for the array API standard for more information.
References
[1]Zhang, Shanjie and Jin, Jianming. “Computation of Special Functions”, John Wiley and Sons, 1996. Original source code hosted by John Burkardt: https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
[2]NIST Digital Library of Mathematical Functions https://dlmf.nist.gov/28.4#i
Examples
We use the Fourier coefficients to construct an approximation of
mathieu_ce(5, 14, x), the even Mathieu function of order m = 5 and parameter q = 14.>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from scipy.special import mathieu_even_coef, mathieu_ce >>> m = 5 >>> q = 14
aholds the Fourier coefficients. As noted above, the number of coefficients returned bymathieu_even_coef(m, q)is based on an empirical formula that depends on m and q. In this case, we get 29 coefficients.>>> a = mathieu_even_coef(m, q) >>> a.shape (29,)
Sum the Fourier cosine series on a grid of
xvalues.>>> period = np.pi if m % 2 == 0 else 2*np.pi >>> x = np.linspace(0, period, 5000) # x has shape (5000,) >>> k = np.arange(len(a)).reshape((-1, 1)) # k has shape (len(a), 1) >>> c = np.cos((2*k + m % 2) * x) # c has shape (len(a), 5000) >>> y = a @ c # y has shape (5000,)
Plot the approximation, along with the function computed directly by
mathieu_ce(m, q, x).>>> plt.plot(x, y, 'k--', label="Fourier sum") >>> ce, _dce = mathieu_ce(m, q, x) >>> plt.plot(x, ce, alpha=0.35, linewidth=3.5, label="mathieu_ce") >>> plt.xticks( ... [0, np.pi/2, np.pi, 3*np.pi/2, 2*np.pi], ... [r"$0$", r"$\pi/2$", r"$\pi$", r"$3\pi/2$", r"$2\pi$"] ... ) >>> plt.grid(True) >>> plt.title(f'Mathieu Function $\\rm{{ce_{m}}}(x, {q})$') >>> plt.xlabel('x [radians]') >>> plt.legend(shadow=True, loc='upper left', bbox_to_anchor=(1, 1)) >>> plt.tight_layout() >>> plt.show()