This is a class assignment. I had written some codes which I hope someone can help me.
This is the code that I have
% --- This is optional to verify whether my parametrization is consistent with the
% --- original equation
% syms x y z p t
% ellipsoid=[2*sin(p)*cos(t),4*sin(t)*sin(p),sqrt(2)*cos(p)]
% simplify(subs((x^2/4)+(y^2/16)+(z^2/2),[x,y,z],ellipsoid))
% --- END
t=linspace(-2,2*pi,20);
s=linspace(0,pi/2,20);
[s t]=meshgrid(s,t);
x=2*cos(t).*sin(s);
y=4.*sin(s).*sin(t);
z=sqrt(2).*cos(s);
surf(x,y,z);
grid on;
xlabel('x');ylabel('y');zlabel('z'); axis equal
hold on;
% I think this is how we draw the lower half of the ellipsoid using -sqr开发者_如何学Got(2)
t=linspace(-2,2*pi,20);
s=linspace(0,pi/2,20);
[s t]=meshgrid(s,t);
x=-2.*cos(t).*sin(s); y=-4.*sin(s).*sin(t); z=-sqrt(2).*cos(s);
surf(x,y,z)
axis equal
The second way to do it is using ellipsoid comment which is the second part of this problem.
[x, y, z] = ellipsoid(0,0,0,2.0,4.0,sqrt(2),20);
surfl(x, y, z)
colormap copper
axis equal
The outupt image please click on the link below (too big)
http://i26.tinypic.com/6ye1j7.jpg The left side is Part a, and right image is using ellipsoid...
Do you think they are the same?
Thank you
Yes, they're pretty much the same.
You can test it by plotting both ellipsoids in the same axes, i.e. after you plotted the first ellipsoid, you run
[x, y, z] = ellipsoid(0,0,0,2.0,4.0,sqrt(2),20);
sh = surfl(x, y, z); %# capture the handle, i.e. the unique identifier, of the surface
%# set color to gray, make mostly transparent
set(sh,'FaceColor',[0.5,0.5,0.5],'FaceAlpha',0.5)
Now you can rotate the plot (click on the button with the circlular arrow, then drag the plot) and you'll see that the two ellipsoids coincide very well. If the second one was bigger than the first one, you'd see a space between the two; if the second one was smaller than the first one, you would only see the first, opaque one.
精彩评论