MATLAB编程:在同一平面的两个窗口分别画出心形线和马鞍面

2024-12-02 04:32:29
推荐回答(1个)
回答1:

你的问题确实很麻烦.

%问题1.
clear
ax1=subplot(1,2,1);
t=0:.01*pi:2*pi;
f1=polar(t,1+cos(t));
title('心形线');
legend(f1,'r=1+cost')

ax2=subplot(1,2,2);
x1=linspace(-40,20,40);
y1=linspace(-40,20,40);
[xx1,yy1]=meshgrid(x1,y1);
zz1=xx1.*yy1;
f2=surf(xx1,yy1,zz1);
title('马鞍面');
legend(f2,'z=x^2-y^2','Location','NorthWest')
xlabel('x轴')
ylabel('y轴')
zlabel('z轴')
axis([-40 20 -40 20 -1000 1500])
setAllowAxesRotate(rotate3d,ax1,false);
grid on

%问题2(给你四个程序,你自己挑吧):
%1)
clear
[x,y,z]=sphere(200);
i=find(x.^2+y.^2-x>=0&x.^2+y.^2+z.^2<1);
z(i)=NaN;
mesh(x,y,z)
hold on
t=0:pi/20:2*pi;
x=(cos(t)+1)/2;
y=sin(t)/2;
z=linspace(-1.2,1.2,length(t));
X=meshgrid(x);
Y=meshgrid(y);
Z=[meshgrid(z)]';
surf(X,Y,Z)
xlabel('x'),ylabel('y'),zlabel('z')
title('球面 X^2+Y^2+Z^2=1和圆柱面X^2+Y^2=X所围成的区域')
rotate3d on

%2)
clear
[X,Y,Z]=sphere(20);
mesh(X,Y,Z)
hidden on
hold on
axis equal
t=0:pi/20:2*pi;
x=(cos(t)+1)/2;
y=sin(t)/2;
z=linspace(-1.2,1.2,length(t));
X=meshgrid(x);
Y=meshgrid(y);
Z=[meshgrid(z)]';
surf(X,Y,Z)
xlabel('x'),ylabel('y'),zlabel('z')
rotate3d on

%3)
[x,y,z]=sphere(200);
i=find(x.^2+y.^2-x<=0&x.^2+y.^2+z.^2>=1);
z(i)=NaN;
mesh(x,y,z)
hidden on
hold on
ezplot('x^2+y^2=x')
title('球面 X^2+Y^2+Z^2=1和圆柱面X^2+Y^2=X所围成的区域')
rotate3d on

%4)
[x,y,z]=sphere(200);
i=find(x.^2+y.^2-x>=0);
z(i)=NaN;
mesh(x,y,z)
hidden on
hold on
ezplot('x^2+y^2=x')
title('球面 X^2+Y^2+Z^2=1和圆柱面X^2+Y^2=X所围成的区域')
rotate3d on