视频
拓展学习
例1 绘制空间曲线。
x = 2:6;
y = (3:8)';
[X, Y] = meshgrid(x, y);
Z = randn(size(X));
plot3(X,Y,Z)
grid on;
例2 绘制三维曲面图。
t = -2:0.2:2;
[X, Y] = meshgrid(t);
Z = X .* exp(-X.^2 - Y.^2);
subplot(1,3,1)
mesh(X,Y,Z);
subplot(1,3,2)
surf(X,Y,Z);
subplot(1,3,3)
plot3(X,Y,Z);
grid on
例3 用4种方式绘制函数=(−1)^2+(−2)^2−1的曲面图。
其中,x∈[0,2],y∈[1,3]。
[x,y]=meshgrid(0:0.1:2,1:0.1:3);
z=(x-1).^2+(y-2).^2-1;
subplot(2,2,1);
meshc(x,y,z);title('meshc(x,y,z)')
subplot(2,2,2);
meshz(x,y,z);title('meshz(x,y,z)')
subplot(2,2,3);
surfc(x,y,z);title('surfc(x,y,z)')
subplot(2,2,4);
surfl(x,y,z); title('surfl(x,y,z)')
例4 用cylinder函数分别绘制柱面、花瓶和圆锥面。
subplot(1,3,1);
[x,y,z]=cylinder;
surf(x,y,z);
subplot(1,3,2);
t=linspace(0,2*pi,40);
[x,y,z]= cylinder(2+cos(t),30);
surf(x,y,z);
subplot(1,3,3);
[x,y,z]= cylinder(0:0.2:2,30);
surf(x,y,z);
例5 用cylinder函数绘制两个相互垂直且直径相等的圆柱面的相交图形。
[x,y,z]= cylinder(1,60);
z=[-1*z(2,:);z(2,:)];
surf(x,y,z)
hold on
surf(y,z,x)
axis equal
例6 绘制螺旋曲面。
funx = @(u,v) u.*sin(v);
funy = @(u,v) -u.*cos(v);
funz = @(u,v) v;
fsurf(funx,funy,funz,[-5 5 -5 -2])
hold on
fmesh(funx,funy,funz,[-5 5 -2 2])
hold off

