【问题标题】:Python: Plotting Bessel functions of the first kind with a float argumentPython:用浮点参数绘制第一类贝塞尔函数
【发布时间】:2013-05-27 18:44:05
【问题描述】:

我正在使用的方程式是

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

其中 $\mathcal{J}_n(x)$ 是第 n 个第一类贝塞尔函数。

作为测试,我绘制了前 6 个贝塞尔函数,一切正常。当我输入 $n * e$ 的参数时,情节并不是我预期的那样。

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()

情节应该看起来像 n = 10

【问题讨论】:

    标签: python matplotlib plot bessel-functions


    【解决方案1】:

    问题是贝塞尔函数sp.jv(n * e, M)的使用,而它应该是顺序,参数。这反过来会导致sp.jv(n , n * e) 生成正确的绘图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多