在python中绘制具有多个参数的数学函数的最佳方法是什么?

2024-10-17 02:28:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我是(理论)物理系的学生,我对编程这门课很陌生。我试图用Python绘制2d量子系统的径向薛定谔波函数,但我遇到了很多麻烦

import numpy as np
import scipy.special as ss
import matplotlib.pyplot as plt


#beta parameter definition
def beta(m, flux, gama):
    flux = np.linspace(0,1.0)
    return np.sqrt((m-flux)**2+gama**4)

#radial wave function definition
beta = beta(0.067*9.1E-31, 0.5, 1.5)
R=5.0E-9
r=np.linspace(0, 0.6)
ro = r/R
def radial (n,gama,beta, ro, R,r):
    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.eval_genlaguerre(n,beta,((gama*ro)**2/2))

sol = radial(0, 1.5, beta, ro, R,r)
plt.plot(ro, sol, '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()

我想问:向数学函数传递多个参数的最佳方法是什么? 即使有多个参数和特殊函数,我也只能在绘图上得到一条直线。 谢谢你的提示和帮助


Tags: importreturnrodefasnppltss
2条回答

您正在向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
               )

相关问题 更多 >