Reputation: 1373
I have three functions in spherical coordinates that I want to plot. They are functions of r,theta,phi and I want to view them in the x-y,y-z,x-z planes. I've tried accomplishing this for literally 8 hours. Every method I've tried has been unsuccessful.
How can I accomplish this phenomenally simple task?
F1 = (r.^2).*abs((1/(8*sqrt(pi))).*r.*exp(-r/2).*sin(theta).*cos(phi)).^2;
F2 = (r.^2).*abs((1/(8*sqrt(pi))).*r.*exp(-r/2).*sin(theta).*sin(phi)).^2;
F3 = (r.^2).*abs((1/(4*sqrt(2*pi))).*r.*exp(-r/2).*cos(theta)).^2;
As you can see, all three of the functions are F(r,theta,phi). That means that there are four dimensions: F,r,theta,phi.
Upvotes: 1
Views: 744
Reputation: 3116
If your functions cannot be expressed as r=f(theta,phi), maybe you can compute the value of f(theta,phi,r) over a grid and then plot an isosurface where your volume data equals your value twoPx.
I tried this small example from which you can expand but I do not know if the shape is correct because I do not know what to expect:
n=20;
rmax=5;
twoPx=0;
%%%%%%%%%%
[theta phi r]=ndgrid(linspace(0,2*pi,n),linspace(-pi/2,pi/2,n),linspace(0,rmax,n));
%%%%%%%%%%
value=(r.^2).*abs((1/(8*sqrt(pi))).*r.*exp(-r/2).*sin(theta).*cos(phi)).^2;
%%%%%%%%%%
[x y z]=sph2cart(theta,phi,r);
%%%%%%%%%%
p=patch(isosurface(x,y,z,value,twoPx));
%%%%%%%%%%
set(p,'FaceColor','b','EdgeColor','k','FaceAlpha',0.5);
daspect([1 1 1])
axis square;
grid on;
camlight;
view([0 0]);
A little explanation of what this snippet does:
ndgrid
)sph2cart
)patch
and isosurface
)Finally you may want to use the Matlab function view
to specify which plane you want to look from.
Upvotes: 2