我是(理论上的)物理学专业的学生,我真的是这个程序设计的新手。我正在尝试在Python中绘制2D量子系统的径向Schrodinger波函数,但遇到很多麻烦
import numpy as np
import scipy.special as ss
import matplotlib.pyplot as plt
#definition of the beta parameter
def beta(m, flux, gama):
flux = np.arange(0,1.0,0.1)
return np.sqrt((m-flux)**2-gama**4)
#Definição da coordenada radial
def radial (n,R,r,gama,beta, ro):
return (1/R)*np.sqrt((ss.gamma(n+1)/2**beta*ss.gamma(n+beta+1)))*(gama*ro)**beta*np.exp(-(gama*ro)**2/4)*ss.genlaguerre(n,beta,((gama*ro)**2/2))
r0 = np.arange(0,5,0.1)
sol = radial(0, 5.0E-9,np.arange(0,5,0.1), 1.5, 6, ro = np.arange(0,10,0.1))
plt.plot(sol, r0, 'b-')
plt.xlabel('r/R')
plt.ylabel('R(r)')
plt.title('Solução radial em fução da coordenada radial')
plt.legend("\gamma=1,5")
plt.grid()
plt.show()
我收到以下错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我不知道如何解决这个问题,想问:用多个参数甚至是特殊函数来绘制类似函数的最佳方法是什么?
您正在genlaguerre函数的布尔参数中输入非布尔值https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.genlaguerre.html
def genlaguerre(n: int,
alpha: float,
monic: Optional[bool] = False) -> orthopoly1d)
您正在输入:
ss.genlaguerre(n=n,
alpha=beta,
monic=((gama*ro)**2/2) # <--- this is your issue
)
[ss.genlaguerre
函数将布尔作为第三个参数,而不是数组。