[r,t] = meshgrid(linspace(0,2*pi,361),linspace(0,pi,361));
[x,y]=pol2cart(sin(t)*cos(r),sin(t)*sin(r));
%[x,y]=pol2cart(r,t);
surf(x,y);
I played with this addon but trying to find an default function to for this. How can I do the 3D-polar-plot?
I am trying to help this guy to vizualise different integrals here.
There are several problems in your code:
sin(theta)*cos(phi)
and sin(theta)*sin(phi)
bit. Why are you calling pol2cart
on this (moreover, we're not working in polar coordinates!)? z
) in your plot. For unity radius, r
can be omitted in the spherical domain, where it is completely defined by theta
and phi
, but in the cartesian domain, you have all three x
, y
and z
. The formula for z
is z = cos(theta)
(for unit radius). You didn't read the documentation for surf
, which says:
surf(Z,C)
plots the height ofZ
, a single-valued function defined over a geometrically rectangular grid, and uses matrixC
, assumed to be the same size asZ
, to color the surface.
In other words, your surf(x,y)
line merely plots the matrix x
and colors it using y
as a colormap.
Here's the above code with the mistakes fixed and plotted correctly:
[f,t] = meshgrid(linspace(0,2*pi,361),linspace(0,pi,361));
x = sin(t)*cos(f);
y = sin(t)*sin(f);
z = cos(t);
surf(x,y,z)