简体   繁体   中英

The best way to plot a math function with multiple parameters in python?

I'm (theoretical) physics student and I'm really new to this programming stuff. I'm trying to plot the radial Schrodinger wave function of a 2d quantum system in Python but I'm having lots of troubles

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()

I would like to ask: what's the best way to pass multiple parameters to a math function? Even with multiple parameters and special functions I get just an straight line on the plot. Thanks for any tips or help.

You are inputting a non boolean into a boolean argument in the genlaguerre function https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.genlaguerre.html

def genlaguerre(n: int,
                alpha: float,
                monic: Optional[bool] = False) -> orthopoly1d)

you are inputting:

ss.genlaguerre(n=n,
               alpha=beta,
               monic=((gama*ro)**2/2)  #  <--- this is your issue
               )

The function ss.genlaguerre takes a bool as the third argument, not an array.

https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.genlaguerre.html#scipy.special.genlaguerre

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM