ich habe ein Programm zur grafischen Darstellung von Atomorbitalen geschrieben (wobei ich mich auch an Code von anderen bedient habe). Wenn ich das Programm versuche auszuführen, kommt die Fehlermeldung:
Googeln hat ergeben, dass offensichtlich in einer Funktion ein Skalar, anstatt eines Arrays erwartet wird. Ich verstehe allerdings nicht warum. Die Zeilen des Fehlers sind offensichtlich immer die Funktionsaufrufe bzw. die Definitionen selber. Habe das mit #Fehler im Code markiert.TypeError: only size-1 arrays can be converted to Python scalars
Code: Alles auswählen
import math as ma
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import sph_harm, genlaguerre
Z = 1 # Anzahl der Elementarladungen
a_0 = 1 # Bohrscher Atomradius
#n = 1 #Hauptquantenzahl
#l = 0 #Drehimpulsquantenzahl
#m = 0 #Magnetquantenzahl
#Radialfunktion
def R(n, l, r):
rho = (2*Z*r)/(n*a_0)
wurzel = ma.sqrt(((rho/r)**3) * (ma.factorial(n-l-1))/(2*n*ma.factorial(n+l)))
L = np.polyval(genlaguerre(n-l-1, 2*l+1), rho) #Fehler
return wurzel * ma.e(-rho/2) * rho**l * L
#Wellenfunktion
def psi(n, l, m, r, phi, theta):
R_nl = R(n,l,r) #Fehler
Y_lm = sph_harm(m,l,phi,theta)
return R_nl * Y_lm
#Zeichnen des Orbitals
def Orbital(n, l, m, x, z, r, phi, theta):
plt.figure()
s_nlm = np.abs(psi(n,l,m,r,phi,theta)) #Fehler
plt.pcolormesh(x, z, s_nlm)
n_max = 4
for n in range(1,n_max+1):
for l in range(n):
plot_range = (4*n + 4*l) * a_0
x_1d = np.linspace(-plot_range,plot_range)
y = 0
z_1d = np.linspace(-plot_range,plot_range)
x,z = np.meshgrid(x_1d,z_1d)
r = np.sqrt(x**2 + y**2 + z**2)
theta = np.arctan2(np.sqrt(x**2+y**2), z)
phi = np.arctan2(y, x)
for m in range(0, l+1):
Orbital(n,l,m,x,z,r,phi,theta) #Fehler
plt.show()