Reputation: 166
I need to plot x = cos(u)*cos(v), y=cos(v)*sin(u), z = -sin(v) where u,v both are from (0,\pi). I looked at fplot3
function but it takes only one parameter. Can anyone point to some function or is there some other way like writing a script to do the plotting?
Upvotes: 0
Views: 975
Reputation: 1824
I would use meshgrid
for this:
u = linspace(0,pi,51);
v = linspace(0,pi,51);
[U,V] = meshgrid(u,v);
X = cos(U).*cos(V);
Y = sin(U).*cos(V);
Z = -sin(V);
Then you can plot it as a mesh (using mesh(X,Y,Z)
) or as a set of lines (e.g., shown here via plot3(X',Y',Z')
), as you like:
Upvotes: 2
Reputation: 6863
You can use fsurf
for parametric surface plots. fsurf
accepts two inputs, u
, and v
.
% your functions
f_x = @(u,v) cos(u).*cos(v);
f_y = @(u,v) cos(v).*sin(u);
f_z = @(u,v) -sin(v);
% plot
umin = 0;
umax = pi;
vmin = 0;
vmax = pi;
figure(1); clf;
fsurf(f_x,f_y,f_z, [umin umax vmin vmax])
You can also check out fcontour
and fmesh
.
Upvotes: 4