数学学习中,有很多地方需要画图来直观对比显示,本节记录一下用matlab画三维图形的几种方法。
例:,
1、surf、surfc、surfl
surf:
clear
clc
close all
%% gride
[x,y]=meshgrid(0:0.1:3,0:0.1:3);
%% plot
z = x.^2-y;
surf(x,y,z)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('z=x^2-y')
surfc:有等高线
surfc(x,y,z)
surfl:MATLAB中内置了surfl函数,基于运用漫反射、镜面发射光和环境照明模型。使用一个单色颜色映像(如灰色,纯白,铜黄或粉红色)和插值色彩,会画出效果更好的曲面
surfl(x,y,z,s)
2、mesh
clear
clc
close all
%% grid
[x,y]=meshgrid(0:0.1:3,0:0.1:3);
%% first
% plot
z = x.^2-y;
c=zeros(31,31);
c=c+0.1;
mesh(x,y,z,c)
xlabel('X')
ylabel('Y')
zlabel('Z')
% make label
hold on
s='x^2-y';
text(x(1,31),y(1,31),z(1,31),s,'fontsize',15,'HorizontalAlignment','center');
%% second
% plot
hold on
z1=sqrt(x)-y;
c1=c+0.2;
mesh(x,y,z1,c1)
% make label
hold on
s='√x-y';
text(x(1,31),y(1,31),z1(1,31),s,'fontsize',15,'HorizontalAlignment','center');
%% third
% plot
hold on
z2=sqrt(x+y)-2*x;
c2=c+0.3;
mesh(x,y,z2,c2)
% make lable
hold on
s='√(x+y)-2y';
text(x(1,31),y(1,31),z2(1,31),s,'fontsize',15,'HorizontalAlignment','center');
title('x^2-y,√x-y,√(x+y)-2y')