n=input('import the principal quantum number: ');
l=input('enter angle quantum number:');
colordef white;
a0=5.29e-11;
i=25000;
r=12*a0*rand(1,i);
Nr=8/(n*a0)^3*factorial(n+l)/((factorial(n-l-1)*2*n)*factorial(2*l+1)*factorial(2*l+1));
F=1;
for k=0:n-l
F=F+(-1).^k*factorial(n-l-1)*factorial(2*l+1)*(2*r/(n*a0)).^k/(factorial(n-l-1-k)*factorial(2*l+1+k)*factorial(k));
end
wr=Nr*exp(-r/(n*a0)).*(2*r/(n*a0)).^l.*F.^2;
theta=pi*rand(1,i);
phi=2*pi*rand(1,i);
Y=legendre(l,sin(theta));
for m=0:1;
Nj=factorial(l-m)*(2*l+1)/(factorial(l+m)*4*pi);
wj=Nj*Y(m+1,:).^2;
end
w=wr.*wj;wm=max(w(:));
[x,y,z]=sph2cart(theta,phi,r);
A=rand(1,i)*wm;
subplot(1,1,1);
axis([-0.5e-11 0.5e-11 -0.5e-11 0.5e-11 -0.5e-11 0.5e-11]);
p=A<=w;
plot3(x(p),y(p),z(p),'b.','MarkerSize',2);
有图像了!但是n,l值变化没有不同