扬州大学MATLAB实验7.1.4_matlab与数学实验答案
扬州大学MATLAB实验7.1.4由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“matlab与数学实验答案”。
1.实验目的(1)学习MATLAB的各种二维绘图(2)学习MATLAB的三维绘图(3)MATLAB的绘图修饰 2.实验内容
在下面的实验操作中,认真记录每项操作的作用和目的。(1)基本二维绘图 1)向量绘图
>> x=0:2*pi/100:2*pi;>> y1=sin(2*x);y2=cos(2*x);>> plot(x,y1)>>plot(x,y2)
>> plot(x,y1,x,y2)
>> plot(x,y1);hold on;>> plot(x,y2);hold off;
>> plot(x',[y1' y2'])
>> plot(x,y1,'c:',x,y2,'ro')
>> figure(1);plot(x,y1);
>> figure(2);plot(x,y2);
>> figure(1);plot(x,y1);>> figure(2);plot(x,y2);>> subplot(221);plot(x,y1);
>> subplot(222);plot(x,y2);>> subplot(223);plot(x,y1,x,y1+y2);>> subplot(224);plot(x,y2,x,y1-y2);
>> w=0.01:0.01:10;>> G=1./(1+2*w*i);>> subplot(121);plot(G);>> subplot(122);plot(real(G),imag(G));
>> x=0:2*pi/8:2*pi;y=sin(x);>> plot(x,y,'o');hold on;
>> x=0:2*pi/8:2*pi;y=sin(x);>> plot(x,y,'o');hold on;
>> xi=0:2*pi/100:2*pi;>> yi=spline(x,y,xi);>> plot(xi,yi,'m');>> whitebg
>> whitebg('b')
>> whitebg('k')
2)函数绘图。
>> fplot('sin',[0 4*pi])>> f='sin(x)';fplot(f,[0 4*pi])
>> fplot('sin(1/x)',[0.01 0.1],1e-3)
>> fplot('[tan(x),sin(x),cos(x)]',[-2*pi,2*pi,-2*pi,2*pi])
>> syms x >> f=exp(-0.5*x)*sin(x);>> ezplot(f,[0,10])
(2)多种二维绘图
1)半对数绘图
>> w=logspace(-1,1);>> g=20*log10(1./(1+2*w*i));>> p=angle(1./(1+2*w*i))*180/pi;>> subplot(211);semilogx(w,g);grid;>> subplot(212);semilogx(w,p);grid;
2)极坐标绘图。>> t=0:2*pi/180:2*pi;>> mo=cos(2*t);>> polar(t,mo);
3)直方图。
>> t=0:2*pi/8:2*pi;>> y=sin(t);>> bar(t,y)
4)离散棒图
>> t=0:2*pi/8:2*pi;>> y=sin(t);>> stairs(t,y)
5)阶梯图。
>> t=0:2*pi/8:2*pi;>> y=sin(t);>> stem(t,y)
6)彗星绘图。>> t=-pi:pi/200:pi;>> comet(t,tan(sin(t))-sin(tan(t)));
(3)图形注释
>> y1=dsolve('D2u+2*Du+10*u=0','Du(0)=1,u(0)=0','x');>> y2=dsolve('D2u+2*Du+10*u=1','Du(0)=0,u(0)=0','x');>> ezplot(y1,[0,5]);hold on;ezplot(y2,[0,5]);
>> axis([0,5,-0.1,0.2])>> title('二阶系统时间响应');>> xlabel('时间t');ylabel('响应幅值y');>> gtext('零输入响应');>> gtext('零状态响应');>> grid;hold off;
(4)三维绘图 1)三维线图。>> t=0:pi/50:10*pi;>> plot3(sin(t),cos(t),t);>> comet3(sin(t),cos(t),t);
2)单变量高度网线图。>> Z2=[1 1;1-1];>> Z4=[Z2 Z2;Z2-Z2];>> Z8=[Z4 Z4;Z4-Z4];>> mesh(Z8);
3)3变量马鞍面网线图。>> x=-4:0.5:4;y=x;>> [X,Y]=meshgrid(x,y);>> Z=X.^2-Y.^2;>> mesh(X,Y,Z);
4)圆锥面网线图。>> t1=0:0.1:0.9;>> t2=1:0.1:2;>> r=[t1-t2+2];>> [X,Y,Z]=cylinder(r,40);>> mesh(X,Y,Z);
5)视角修饰。>> t1=0:0.1:0.9;>> t2=1:0.1:2;>> r=[t1-t2+2];>> [X,Y,Z]=cylinder(r,30);>> mesh(X,Y,Z);>> subplot(2,2,1);mesh(X,Y,Z);view(0,0);>> subplot(2,2,2);mesh(X,Y,Z);view(-20,20);>> subplot(2,2,3);mesh(X,Y,Z);view(-30,30);>> subplot(2,2,4);mesh(X,Y,Z);view(-40,40);
6)MATLABA暖色(hot)函数色图。>> peaks(20);
z = 3*(1-x).^2.*exp(-(x.^2)x.^3y.^2)
>> axis('off')>> colormap(hot);>> colorbar('horiz');
7)光照修饰。>> surfl(peaks(20));>> colormap(hot);>> shading interp;
8)表面修饰。
>> subplot(131);peaks(20);shading flat;
z = 3*(1-x).^2.*exp(-(x.^2)x.^3y.^2)
>> subplot(132);peaks(20);shading interp;
z = 3*(1-x).^2.*exp(-(x.^2)x.^3y.^2)
>> subplot(133);peaks(20);shading faceted;
z = 3*(1-x).^2.*exp(-(x.^2)x.^3y.^2)
9)透视与消隐。>> P=peaks(30);>> subplot(121);mesh(P);hidden off;>> subplot(122);mesh(P);hidden on;
10)裁剪修饰。>> P=peaks(30);>> P(20:23,9:15)=NaN*ones(4,7);>> subplot(121);meshz(P);>> subplot(122);meshc(P);
11)水线修饰。
>> waterfall(peaks(20))>> colormap([1 0 0])
12)等高线修饰。
>> contour(peaks(20),6)>> contour3(peaks(20),10)>> clabei(contour(peaks(20),4))>> clabel(contour(peaks(20),4))>> clabel(contour3(peaks(20),3))