Python: Plotting Bessel functions of the first kind with a float argument

dustin picture dustin · May 27, 2013 · Viewed 10.9k times · Source

The equation I am working with is

$$ E = M_e + \sum_{n = 1}^N\frac{2}{n}\mathcal{J}_n(ne)\sin(nM_e) $$

where $\mathcal{J}_n(x)$ is the nth Bessel function of the first kind.

As a test, I plotted the first 6 Bessel functions and everything worked out correctly. When I enter the argument of $n * e$, the plot isn't what I anticipated it to be.

import numpy as np
import pylab as py
import scipy.special as sp

x = np.linspace(0, 15, 500000)

for v in range(0, 6):
    py.plot(x, sp.jv(v, x))

py.xlim((0, 15))
py.ylim((-0.5, 1.1))
py.legend(('$\mathcal{J}_0(x)$', '$\mathcal{J}_1(x)$', '$\mathcal{J}_2(x)$',
           '$\mathcal{J}_3(x)$', '$\mathcal{J}_4(x)$', '$\mathcal{J}_5(x)$'),
           loc = 0)
py.xlabel('$x$')
py.ylabel('$\mathcal{J}_n(x)$')
#py.title('Plots of the first six Bessel Functions')                                
py.grid(True)
#py.savefig('besseln0to6.eps', format = 'eps')                                      
py.show()

e = 0.99


def E(M):
    return (M + sum(2.0 / n * sp.jv(n * e, M) * np.sin(n * M)
                    for n in range(1, 3, 1)))

M = np.linspace(0, 2 * np.pi, 500000)

fig2 = py.figure()
ax2 = fig2.add_subplot(111, aspect = 'equal')
ax2.plot(E(M), M, 'b')


def E2(M):
    return (M + sum(2.0 / n * sp.jv(n * e, M) * np.sin(n * M)
                    for n in range(1, 11, 1)))


ax2.plot(E2(M), M, 'r')
py.xlim((0, 2 * np.pi))
py.ylim((0, 2 * np.pi))
py.xlabel('Eccentric anomaly, $E$')
py.ylabel('Mean anomaly, $M_e$')
py.show()

enter image description here

The plot is supposed to look like for n = 10

enter image description here

Answer

dustin picture dustin · May 27, 2013

The problem is the use of the Bessel function sp.jv(n * e, M) whereas it should be order, argument. That in turn leads to sp.jv(n , n * e) which generates the correct plot.