0% found this document useful (0 votes)
11 views2 pages

Spherical

Uploaded by

opwatson55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Spherical

Uploaded by

opwatson55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Spherical Harmonics

Problem Statement
Draw Spherical Harmonics for all values of m for l = [1, 2, 3]

In [49]: import numpy as np


import scipy as sc
import matplotlib.pyplot as plt
import sympy as sp
from matplotlib import cm
import math

In [50]: theta=np.linspace(0,np.pi,300)
phi=np.linspace(0,2*np.pi,300)
theta,phi=np.meshgrid(theta,phi)
def spherical_harmonic(l,m):
P=sc.special.lpmv(m,l,np.cos(theta))
exp=np.exp(1j*m*phi)
cons=np.sqrt((2*l+1)*math.factorial(l-m)/(4*np.pi)*math.factorial(l+m))
Y=abs(P*exp*cons)**2 In [52]: fig=plt.figure(figsize=(20,25))
x = Y * np.sin(theta) * np.cos(phi) for i in range(-2,3,1):
y = Y * np.sin(theta) * np.sin(phi) x,y,z,P=spherical_harmonic(2,i)
z = Y * np.cos(theta) ax = fig.add_subplot(323+i, projection='3d')
return x,y,z,Y surface=ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=cm.viridis
ax.tick_params(labelsize=10)
In [54]: fig=plt.figure(figsize=(20,12)) ax.set_xlabel('$x$-axis',fontsize=10)
for i in range(-1,2,1): ax.set_ylabel('$y$-axis',fontsize=10)
x,y,z,P=spherical_harmonic(1,i) ax.set_zlabel('$z$-axis',fontsize=10)
ax = fig.add_subplot(222+i, projection='3d') ax.set_title(f"Spherical Harmonics with l={2}, m={i}",fontsize=9)
surface=ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=cm.viridis cbar = plt.colorbar(surface, label='Normalized Probability Density')
ax.tick_params(labelsize=10) cbar.ax.tick_params(labelsize=5)
ax.set_xlabel('$x$-axis',fontsize=10) cbar.set_label('Normalized Probability Density', fontsize=8)
ax.set_ylabel('$y$-axis',fontsize=10)
ax.set_zlabel('$z$-axis',fontsize=10) plt.show()
ax.set_title(f"Spherical Harmonics with l={1}, m={i}",fontsize=9)
cbar = plt.colorbar(surface, label='Normalized Probability Density')
cbar.ax.tick_params(labelsize=5)
cbar.set_label('Normalized Probability Density', fontsize=8)

plt.show()
plt.show()

In [53]: fig=plt.figure(figsize=(20,25))
for i in range(-3,4,1):
x,y,z,P=spherical_harmonic(3,i)
ax = fig.add_subplot(424+i, projection='3d')
surface=ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=cm.viridis
ax.tick_params(labelsize=10)
ax.set_xlabel('$x$-axis',fontsize=10)
ax.set_ylabel('$y$-axis',fontsize=10)
ax.set_zlabel('$z$-axis',fontsize=10)
ax.set_title(f"Spherical Harmonics with l={3}, m={i}",fontsize=9)
cbar = plt.colorbar(surface, label='Normalized Probability Density')
cbar.ax.tick_params(labelsize=5)
cbar.set_label('Normalized Probability Density', fontsize=8)

You might also like