quad - 使用 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()
解决方案
推荐阅读
- java - 如何定义和初始化一个生成从 2 到 20 的随机整数的变量?
- python - 在 Django 中保存和更新数据
- python - 布局 PySimpleGUI IndexError:列表索引超出范围
- arrays - 检查numpy数组中的重复项
- r - 在 R 中隐藏未选择的 visNetwork 节点
- html - 我应该使用什么定位器来获取在 Selenium 中切换页面的元素列表?
- java - Activity 中的 LiveData、setValue 和片段中的观察。可能吗?
- android - google play 控制台无法识别打包在 android app bundle 文件 (.aab) 中的调试符号和映射文件
- javascript - Express Nodejs S3 上传到三个不同的目录
- r - 加载 ade4 和 adegenet 包时出现问题