Erro在python中使用genlaguerre?

2024-09-30 18:24:47 发布

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

我试图用Python绘制以下等式的图形

二维量子环径向微分方程的解

beta参数是

enter image description here

这是我的尝试

    import numpy as np
from scipy.special import gamma, genlaguerre
import matplotlib.pyplot as plt
from scipy import exp, sqrt

m = 0.067*9.1*10E-31
R = 5E-9
r = np.linspace(0, 20E-9)
#Definição do parâmetro beta

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

def Rn(n,gama):

    raiz = sqrt((gamma(n+1)/((2**beta(gama)) * gamma(n+beta(gama)+1))))
    eval_g = genlaguerre((n,beta(gama)),((gama * r/R)**2/2))
    exp_g = exp(-((gama * r/R)**2)/4)


    return  (1/R) * raiz * (gama * r/R)**beta(gama) * exp_g * eval_g

sol1 = Rn(0,1.5)
sol2 = Rn(0,2.0)
sol3 = Rn(0,2.5)
sol4 = Rn(0,3.0)


fig, ax = plt.subplots()
ax.plot(r/R, sol1, color = 'red', label = '$\gamma$ = 1.5')
ax.plot(r/R, sol2, color = 'green', label = '$\gamma$ = 2.0')
ax.plot(r/R, sol3, color = 'blue', label = '$\gamma$ = 2.5')
ax.plot(r/R, sol4, color = 'black', label = '$\gamma$ = 3.0')
ax.legend()
ax.set_xlabel('R/r')
ax.set_ylabel('$R_0(r)$')

使用genlaguerre的erro

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

这里the link to the article


Tags: fromimportplotasnpscipysqrtrn
2条回答

我对这个话题不感兴趣,但至少有以下错误(我认为默认设置n=0是有意的):

  1. 在发布的beta函数图像的对面,您在函数定义中添加了一个4除法。
    正确版本:
    def beta(gama): 
        return np.sqrt((m-flux)**2+(gama**4))

这不是分布式而不是固定峰值的原因,但我告诉你我在这里看到了什么

  1. 由于振幅函数定义中缺乏偏执,因此用乘积代替除法: 正确版本:
    def amplitude(gama):
        return np.sqrt(gamma(1)/((2**beta(gama)*gamma(beta(gama)+1))))
  1. 在Rn函数的定义中,缺少了引入1/R

然而,不幸的是,所有这一切并没有改变峰值发生在相等的x位置

对不起!文章的径向波函数是错误的!我做了计算,找到了正确的答案。以下代码是正确的

import numpy as np
from scipy.special import genlaguerre, gamma
import numpy as np
import matplotlib.pyplot as plt

m = 0 # magnetic number
flux = 0  # Phi in eqn 8
R = 5  # nm
r = np.linspace(0, 6 * R)

rho = r / R

def R0(n, gama):
    beta = np.sqrt((m - flux)**2 + gama**4/4)
    return (gama/R*
            np.sqrt(gamma(n+ 1) / ( 2**beta * gamma(n + beta + 1))) *
            (gama * rho)**beta *
            np.exp(-gama**2 * rho**2 / 4) *
            genlaguerre(n, beta)(gama**2 * rho**2 / 2))


sol1 = R0(0, 1.5)
sol2 = R0(0, 2.0)
sol3 = R0(0, 2.5)
sol4 = R0(0, 3.0)

plt.plot(rho, sol1, rho, sol2, rho, sol3, rho, sol4)
plt.legend(['$\gamma = 1.5$', '$\gamma = 2$', '$\gamma = 2.5$', '$\gamma = 3$'])
plt.ylabel('$R_{0}(r)$')
plt.xlabel('$r/R$')
plt.show()

相关问题 更多 >