Search code examples
matlabmatlab-figure

parametric function plotting in matlab


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?


Solution

  • 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])
    

    enter image description here

    You can also check out fcontour and fmesh.