最近快要开始一年一度的数学建模竞赛啦,接下来争取每天更一篇数学建模算法!(当然这是理想状态下),今天就先更一些MATLAB常用的绘图吧,论文赏心悦目的关键就在于丰富多彩的图,好看的图一定会成为数学建模竞赛中的加分项!
1. ****二维绘图函数
![](https://i-blog.csdnimg.cn/direct/4f0923927d204ff7ab954af07ef0c345.png)
示例:
Matlab
clc,clear,
syms x y,
ezplot(x^2-y^4)
![](https://i-blog.csdnimg.cn/direct/48202f8f68c244179e18d0fc11b3baa3.png)
2.三维绘图函数
![](https://i-blog.csdnimg.cn/direct/2020e52feb3a43ec9e705666962c73c8.png)
示例:
Matlab
syms t
ezplot3(sin(t),cos(t),t,[0,6*pi],"animate")
![](https://i-blog.csdnimg.cn/direct/3fddfe3da4e84e2eb6d4f207b4491123.png)
3.等高线绘图函数
示例:
Matlab
clc,clear,
syms x y,
f=3*(1-x)^2*exp(-(x^2)-(1+y)^2)-10*(x/5-x^3-y^5)*exp(-x^2-y^2)...
-1/3*exp(-(x+1)^2-y^2);
ezcontour(f,[-3,3],49)
![](https://i-blog.csdnimg.cn/direct/d390bdf8b51d46a39f0e7d766afa9496.png)
填充等高线图
Matlab
clc,clear,
syms x y,
f=3*(1-x)^2*exp(-(x^2)-(1+y)^2)-10*(x/5-x^3-y^5)*exp(-x^2-y^2)...
-1/3*exp(-(x+1)^2-y^2);
ezcontourf(f,[-3,3],49)
![](https://i-blog.csdnimg.cn/direct/42d99578a9844a539aef8d6428a2951e.png)
4.网格图绘图函数
ezmesh函数
Matlab
clc,clear,
syms x y,
ezmesh(x*exp(-x^2-y^2),[-2.5,2.5],40)
![](https://i-blog.csdnimg.cn/direct/797ab8b0abb2431a806ee949198d0337.png)
5.表面图绘图函数
![](https://i-blog.csdnimg.cn/direct/e60b54b3fb0e432cbb3f4936e82bda4b.png)
Matlab
clc,clear;
syms s t,
x=cos(s)*cos(t);
y=cos(s)*sin(t);
z=sin(s);
ezsurf(x,y,z,[0,pi/2,0,3*pi/2])
view(17,40)
shading interp
![](https://i-blog.csdnimg.cn/direct/98bfd0b0293b4d13a02df1caf160834b.png)
6.plot函数绘图
![](https://i-blog.csdnimg.cn/direct/a48dde79f0a244e8aa7e960a30a8afeb.png)
参数介绍:
![](https://i-blog.csdnimg.cn/direct/c4896cf1b85e442b9b00a559226babc8.png)
![](https://i-blog.csdnimg.cn/direct/59cf5a087cc54aafad755dd1d4411ce8.png)
![](https://i-blog.csdnimg.cn/direct/dca7ced11a8e4da59d9fd3774db41ad0.png)
示例:
Matlab
clc,clear,
x=linspace(0,7);
y1=sin(2.*x);
y2=sin(x.^2);
y3=(sin(x)).^2;
plot(x,y1,'r+-',x,y2,'k*:',x,y3,'b--^')
legend('sin(2*x)','sin(x^2)','(sin(x))^2')
xlabel('x轴')
ylabel('y轴')
grid on
![](https://i-blog.csdnimg.cn/direct/bbd4c76061d84a6a80928e48c01750c4.png)
7.subplot的使用
![](https://i-blog.csdnimg.cn/direct/086b65f1061f411380673a83af2b7f4a.png)
示例:
Matlab
x=-10:0.1:10;
y1=x.*cos(x);
y2=-x.*sin(x)+cos(x);
y3=cos(x).*sin(x);
y4=sin(x).^2;
subplot(2,2,1)
plot(x,y1)
title('图1')
subplot(2,2,2);
plot(x,y2,'b--')
title('图2')
subplot(2,2,3)
plot(x,y3,'mo')
title('图3')
subplot(2,2,4)
plot(x,y4,'g*')
title('图4')
![](https://i-blog.csdnimg.cn/direct/6e5661c9a7fd4918bcd76c21e6647306.png)
8.hold的使用
![](https://i-blog.csdnimg.cn/direct/5aab64794815455c86e233683bd1e13a.png)
Matlab
clc,clear;
t=0:pi/10:2*pi;
y1=sin(t);
y2=cos(t);
y3=sin(t)-cos(t);
plot(t,y1,'g*');
hold on;
plot(t,y2,'-.b');
plot(t,y3,'--m');
![](https://i-blog.csdnimg.cn/direct/87901a279f2744db8e014d2d1bea58b5.png)
9.三维绘图
![](https://i-blog.csdnimg.cn/direct/4f05fef3dafc46249bb020c5f7aceada.png)
![](https://i-blog.csdnimg.cn/direct/91aea47b2fb543af87de4c95bad65c12.png)
示例:
Matlab
x=0:0.1:10;
[x,y]=meshgrid(linspace(0,10),linspace(0,10));
z=(1./(x.^3-2.*x+5))+(1./(y.^3-2.*y+5));
mesh(x,y,z);
xlabel('X');
ylabel('Y');
zlabel('Z');
grid on
![](https://i-blog.csdnimg.cn/direct/03cc37bde9e24a56a41961873e32f76e.png)
Matlab
x=-8:0.5:8;
y=x;
[X,Y]=meshgrid(x,y);
r=sqrt(X.^2+Y.^2)+eps;
Z=sin(r)./r;
surf(X,Y,Z);
![](https://i-blog.csdnimg.cn/direct/7bbe40a0d3d0430daaee4d89d3c0af5e.png)
Matlab
t=0:pi/50:10*pi;
x=exp(-t/15).*sin(2*t);
y=exp(-t/15).*cos(2*t);
z=t;
plot3(x,y,z)
axis square;
grid on
![](https://i-blog.csdnimg.cn/direct/9accf23d79f141c78070198e21bc1e70.png)
经典图:
Matlab
z=peaks(40);
surf(z);
![](https://i-blog.csdnimg.cn/direct/947633cc9ac8458fa96937d948219ad1.png)
Matlab
clear;
z=peaks(40);
subplot(2,2,1);
mesh(z)
subplot(2,2,2);
mesh(z)
view(-15,60);
subplot(2,2,3);
mesh(z)
view(-90,0);
subplot(2,2,4);
mesh(z)
view(-7,-10);
![](https://i-blog.csdnimg.cn/direct/900e258617c145fea783a336451744df.png)
10.时间响应绘图
参数介绍:
![](https://i-blog.csdnimg.cn/direct/c74dbcd216124bdfa2e1a0c75c4cf93d.png)
示例:
Matlab
clear;
num1=[0 0 1];num2=[0 1 0];num3=[1 0 0];
den=[1 2 10];
impulse(num1,den);
hold on
gtext('G1')
impulse(num2,den);
gtext('G2')
impulse(num3,den);
gtext('G3')
![](https://i-blog.csdnimg.cn/direct/815c044fca304bdd8f89eda80b10f1f4.png)