函数图形绘制
1.ezplot
syms x
fh1 = x^2*sin(2*x)/5;
fh2 = 3/8*(exp(-2*x/3)*sin(1+2*x));
h1 = ezplot(fh1,[-5,5]);
set(h1,{'LineWidth','LineStyle','Color'},{1.3,':','r'})
grid on
hold on
h2 = ezplot(fh2,[-5,5]);
set(h2,{'LineWidth','LineStyle','Color'},{1.3,'-.','b'})
axis([-5,5,-3.5,3.5])
legend('fh1 = x^2*sin(2*x)/5','fh2 = 3/8*(exp(-2*x/3)*sin(1+2*x))')
legend('boxoff'
2.绘制隐函数图像
syms x y
fh = x^2*sin(x+y^2)+y^2*exp(x)+6*cos(x^2+y);
h = ezplot(fh, [-6 6]);
set(h,{'LineWidth','LineStyle','Color'},{1,'-','b'})
grid on
3.绘制参数方程图像
syms t;
x = sin(3*t)*cos(t);
y = sin(3*t)*sin(t);
h = ezplot(x,y,[0,pi]);
set(h,'linewidth',1.3,'linestyle','-.','color','r')
grid on
4.绘制三维参数曲线
syms t
x=cos(t);y=sin(t); z=t; %参数方程
subplot(2,1,1); ezplot3(x,y,z,[0,6*pi],'animate');
subplot(2,1,2)
h1 = ezplot3(x,y,z,[0,2*pi]);
set(h1,'linewidth',1.3,'linestyle',':','color','r')
hold on
h2 = ezplot3(x,y,z,[2*pi,4*pi]);
set(h2,'linewidth',1.3,'linestyle','-.','color','b')
h3 = ezplot3(x,y,z,[4*pi,6*pi]);
set(h3,'linewidth',1.3,'linestyle','--','color','c')
5.ezmesh和ezsurf
syms x y;
z=x*exp(-x^2-y^2);
subplot(2,2,1)
ezmesh(z,[-2.5,2.5],30);
subplot(2,2,2)
ezsurf(z,[-2.5,2.5],30);
subplot(2,2,3)
ezmesh(z,[-2.5,2.5],60);
subplot(2,2,4)
ezsurf(z,[-2.5,2.5],60);
shading inter
r = @(s,t) 2 + sin(7.*s + 5.*t);
x = @(s,t) r(s,t).*cos(s).*sin(t); y = @(s,t) r(s,t).*sin(s).*sin(t); z = @(s,t) r(s,t).*cos(t); %参数方程匿名函数
fmesh(x,y,z,[0 2*pi 0 pi])
alpha(0.8)
fsurf(x,y,z,[0 2*pi 0 pi]
6.绘制等值线
syms x y
f = 3*(1-x)^2*exp(-(x^2)-(y+1)^2)-10*(x/5 - x^3 - y^5)*exp(-x^2-y^2)-1/3*exp(-(x+1)^2 - y^2);
subplot(1,2,1),
ezcontour(f,[-3,3],49)
title('ezcoutour');
subplot(1,2,2),
ezcontourf(f,[-3,3],49)
title('filled ezcoutour');
fh = @(x,y)3*(1-x).^2.*exp(-(x.^2)-(y+1).^2)-10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2)-1/3*exp(-(x+1).^2 - y.^2);
subplot(1,2,1)
fcontour(fh);
grid on
set(gca,'Xtick',-5:1:5)
subplot(1,2,2)
fc = fcontour(fh,'fill','on');
set(gca,'Xtick',-5:1:5