【发布时间】:2018-08-09 20:52:02
【问题描述】:
我编写了以下代码来绘制出光学组件的光强度,这基本上是入射场上的球面傅里叶积分,因此它具有贝塞尔函数。其参数取决于积分变量(x)和绘图变量(r)。
from sympy import *
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import quad
from scipy.special import jn
#constants
mm = 1
um = 1e-3 * mm
nm = 1e-6 * mm
wavelength = 532*nm
klaser = 2*np.pi / wavelength
waist = 3.2*mm
angle = 2 #degrees
focus = 125 * mm
ng = 1.5 # refractive index of axicon
upperintegration = 5
#integrals
def b(angle):
radians = angle* np.pi/180
return klaser * (ng-1) * np.tan(radians)
def delta(angle):
return np.pi/(b(angle)*waist)
def integrand(x, r):
return klaser/focus * waist**2 * np.exp(-x**2) * np.exp(-np.pi * 1j * x/delta(angle)) * jn(0, waist*klaser*r*x/focus) * x
def intensity1D(r):
return np.sqrt(quad(lambda x: np.real(integrand(x, r)), 0, upperintegration)[0]**2 + quad(lambda x: np.imag(integrand(x, r)), 0, upperintegration)[0]**2)
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.linspace(-3.5, 3.5, 25)
plt.plot(t, np.vectorize(intensity1D)(t))
问题是,当我改变我在linspace 中使用的点数时,情节发生了巨大变化。
我怀疑这可能是因为积分的振荡性质,因此所采用的步长可以显着改变指数的值,从而改变积分的值。
quad 如何处理这个问题?有没有更好的方法来为这个特定的应用程序进行数值积分?
【问题讨论】:
-
您确定公式正确吗?通常你不会有像 mm 这样的单位出现在 exp 或 jn 函数中。 (例如,平方毫米的指数是多少??)
-
X 是无量纲的
标签: python python-2.7 matplotlib scipy