scipy.special.

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_{(2n)}^{(2k)} \cos 2kz\]
\[\mathrm{ce}_{2n+1}(z, q) = \sum_{k=0}^{\infty} A_{(2n+1)}^{(2k+1)} \cos (2k+1)z\]

This function returns the coefficients \(A_{(2n)}^{(2k)}\) for even input m=2n, and the coefficients \(A_{(2n+1)}^{(2k+1)}\) for odd input m=2n+1.

Parameters:
mint

Order of Mathieu functions. Must be non-negative.

qfloat (>=0)

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

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_cem(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_cem
>>> m = 5
>>> q = 14

a holds the Fourier coefficients. As noted above, the number of coefficients returned by mathieu_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 x values.

>>> period = 180 if m % 2 == 0 else 360
>>> 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) * (np.pi/180) * 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_cem(m, q, x).

>>> plt.plot(x, y, 'k--', label="Fourier sum")
>>> ce, _dce = mathieu_cem(m, q, x)
>>> plt.plot(x, ce, alpha=0.35, linewidth=3.5, label="mathieu_cem")
>>> plt.grid(True)
>>> plt.title(f'Mathieu Function $\\rm{{ce_{m}}}(x, {q})$')
>>> plt.xlabel('x [degrees]')
>>> plt.legend(shadow=True, loc='upper left', bbox_to_anchor=(1, 1))
>>> plt.tight_layout()
>>> plt.show()
../../_images/scipy-special-mathieu_even_coef-1.png