首页 > 解决方案 > 使用 scipy.quad 集成的 Bessel 函数不起作用

问题描述

我正在尝试使用 scipy.quad 积分方法在 2D 中绘制 Bessel 函数。

我的问题:情节中间只有一个小点,因为我的最低值太低了。

这是我的代码:

import numpy as np
import scipy.integrate as si
import matplotlib.pyplot as plt

wavelength = 5.0
k = 2 * np.pi / wavelength

side = 100.0
points = 100
spacing = side / points


def J(x, m):
    def f(t):
        return np.cos(m * t - x * np.sin(t)) / np.pi

    y = si.quad(f, 0, np.pi)
    return y[0]


x1 = side / 2
y1 = side / 2


data = np.empty([points, points], float)
data[0, 0] = 0.5

for i in range(1, points):
    y = spacing * i
    for j in range(1, points):
        x = spacing * j
        r = np.sqrt((x - x1) ** 2 + (y - y1) ** 2)
        if r == 0:
            data[i, j] = 1
        else:
            data[i, j] = (2 * J(1, r) / r) ** 2
print(data.min(), data.max())
plt.imshow(data, origin="lower", extent=[0, side, 0, side])
plt.show()

标签: quadbessel-functions

解决方案


推荐阅读