首页 > 解决方案 > 在python和matlab中使用相同的一维数组作为一阶贝塞尔函数的输入,为什么我有不同的结果?

问题描述

我正在将代码从 Matlab 翻译成 Python。在 Python 和 Matlab 中使用相同的一维数组作为一阶 Bessel 函数的输入时,为什么会得到不同的结果?

假设T是我输入的数组,在 Matlab 中是besselj(1,T),在 Python 中是scipy.special.jv(1,T).

这是我的代码。

wave0=5000
pixelscale=4e-4
abe = np.zeros((6,1))
psfsize=4191
diam = 2
centr = 0

temx = np.linspace(-1 * pixelscale * math.floor(psfsize/2), 
pixelscale * math.floor(psfsize/2),psfsize)
[meshtheta,meshphi] = np.meshgrid(temx,np.transpose(temx))
R_pup = np.sqrt(meshphi**2 + meshtheta**2)
teltheta = (R_pup) * np.pi * diam * (wave0 * 1e-10) / 206265

while teltheta.any() == 0:
    teltheta=1e-9

T=teltheta

plt.figure()
plt.imshow(jv(1,T),cmap='hot')
plt.show()

因此,我在 Python 中得到了 Bessel 函数(一阶)的图像矩阵。后来我在 Python 中使用图像矩阵来减少 Matlab 中的结果,得到的结果如下:

在此处输入图像描述

标签: pythonarraysmatlabscipy

解决方案


推荐阅读