# How to plot sin(theta)*cos(phi) in spherical coordinates

14 views (last 30 days)
Nathan Cross on 21 Feb 2018
Answered: Unai San Miguel on 21 Feb 2018
[theta,phi] = meshgrid(linspace(-pi,pi,41),linspace(-pi/2,pi/2,41));
R = sin(theta)*cos(phi);
[X,Y,Z] = sph2cart(theta,phi,R);
surf(X,Y,Z)
alpha 0.5
axis vis3d
Tried using the code above but it is not giving me what I would expect (a p orbital looking shape). Any way anyone could help me figure this out?

Amjad Green on 21 Feb 2018
plot3(X,Y,Z)
Nathan Cross on 21 Feb 2018
[theta,phi] = meshgrid(linspace(-pi,pi,41),linspace(-pi/2,pi/2,41));
R = sin(theta)*cos(phi);
[X,Y,Z] = sph2cart(theta,phi,R);
plot3(X,Y,Z)
Tried this and it seems like I am still having an issue because I am getting this for the graph

Unai San Miguel on 21 Feb 2018
sin(theta) * cos(phi) is the result of the matrix multiplication of the two terms. Maybe you wanted sin(theta) .* cos(phi)? The latter has in every element of the array the product of sin(theta(i,j)) and cos(phi(i,j))