MATLAB: 3D plot an ellipsoid

3d plotellipsoidmeshsurface plot

hi, i'm making a code that will plot an ellipsoid with the following equations:
x = a * (cos*phi) * (cos * theta); y = b * (cos*phi) * (sin * theta); z = b * (sin*phi);
and i'm supposed to plot it with a = 2, and b = 1, but it doesn't appear to be working.. help anyone?
a = 2;
b = 1;
x = a * (cos*phi) * (cos * theta);
y = b * (cos*phi) * (sin * theta);
z = b * (sin*phi);
[Xm, Ym] = meshgrid(x,y);
surf(x,y,z)

Best Answer

How about using a fsurf function, like:
a = 2;
b = 1;
funx = @(theta,phi) a*cos(theta).*cos(phi);
funy = @(theta,phi) b*cos(theta).*sin(phi);
funz = @(theta,phi) b*sin(theta);
fsurf(funx,funy,funz,[-pi/2 pi/2 -pi pi])