《MATLAB第四章实验报告.doc》由会员分享,可在线阅读,更多相关《MATLAB第四章实验报告.doc(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、MATLAB图形基础班级:11电信一班姓名:何得中学号:实验目的:1. 掌握MATLAB图形绘制功能;2. 学会使用MATLAB提供的绘图函数;3. 了解MATLAB对图形线性、色彩、光线、视角等的制定和处理。实验仪器:MATLAB软件,电脑实验数据:绘制fracreturnl变量同一图轴下绘制两条曲线增加子图分割子图删除图轴后仍保留两个子图效果添加图轴信息设定曲线样式 在交互式绘图工具中增加图例 rand(state,27) startprice=50;fracreturns1=0.0015*randn(200,1)+0.0003; x1=startprice;1+fracreturns1;
2、 prices1=cumprod(x1); t=(1:length(prices1); randn(state,7)fracreturns2=0.0015*randn(200,1)+0.0003; x2=startprice;1+fracreturns2; prices2=cumprod(x2); whos Name Size Bytes Class L 51x51 20808 double array fracreturns1 200x1 1600 double array fracreturns2 200x1 1600 double array l1 1x1 8 double array
3、l2 1x1 8 double array prices1 201x1 1608 double array prices2 201x1 1608 double array s 1x1 8 double array startprice 1x1 8 double array t 201x1 1608 double array x1 201x1 1608 double array x2 201x1 1608 double arrayGrand total is 4010 elements using 32080 bytes plot (prices2, DisplayName, prices2,
4、YDataSource, prices2); figure(gcf) x=0:pi/1000:2*pi; y=exp(-0.5*x).*sin(2*pi*x+pi/4); plot(x,y)plot(x,y,x,y+1,x,y-1) B=pascal(6)B = 1 1 1 1 1 1 1 2 3 4 5 6 1 3 6 10 15 21 1 4 10 20 35 56 1 5 15 35 70 126 1 6 21 56 126 252 plot(B) x=(0:pi/100:2*pi); y1=2*exp(-0.5*x)*1,-1; y2=2*exp(-0.5*x).*sin(2*pi*x
5、); x1=(0:12)/2; y3=2*exp(-0.5*x1).*sin(2*pi*x1); plot(x,y1,g:,x,y2,b-,x1,y3,rp); x1=0:pi/100:2*pi; x2=0:pi/100:3*pi; y1=exp(-0.5*x1).*sin(2*pi*x1); y2=1.5*exp(-0.1*x2).*sin(x2); plotyy(x1,y1,x2,y2); x=(0:pi/100:2*pi); y1=2*exp(-0.5*x)*1,-1; y2=2*exp(-0.5*x).*sin(2*pi*x); x1=(0:12)/2; y3=2*exp(-0.5*x
6、1).*sin(2*pi*x1); plot(x,y1,g:,x,y2,b-,x1,y3,rp); title(曲线及其包络线); %加图形标题 xlabel(independent variable X); %加X轴说明 ylabel(independent variable Y); %加y轴说明 text(2.8,0.5,包络线); %在指定位置添加图形说明 text(0.5,0.5,曲线y); text(1.4,0.1,离散数据点); legend(包络线,包络线,曲线y,离散数据点) %加图例 x=(0:pi/100:2*pi); y1=2*exp(-0.5*x)*1,-1; y2=2
7、*exp(-0.5*x).*sin(2*pi*x); plot(x,y1,b:); axis(0,2*pi,-2,2); hold on; plot(x,y2,k); grid on; box off; hold off; x=(0:pi/100:2*pi); y1=2*exp(-0.5*x)*1,-1; y2=2*exp(-0.5*x).*sin(2*pi*x); plot(x,y1,b:); hold on; plot(x,y2,k); grid on; box off; hold offalpha=-0.5;beta=3;A=50;t=0:0.01:10;y=A*exp(alpha*t)
8、.*sin(beta*t);plot(t,y);title(fontname隶书fontsize16隶书fontnameImpactImpact)xlabel(上标and_下标)ylabel(Somebf粗体rm and someit斜体)txt=y=itAealphaxsin(betaitt),. itArm,=.num2str(A),. alpha=num2str(alpha),. beta=,num2str(beta); text(2,22,txt)x=linspace(0,2*pi,60);y=sin(x);z=cos(x);t=sin(x)./(cos(x)+eps);ct=cos(
9、x)./(sin(x)+eps);subplot(2,2,1);plot(x,y);title(sin(x);axis(0,2*pi,-1,1);subplot(2,2,2);plot(x,z);title(cos(x);axis(0,2*pi,-1,1);subplot(2,2,3);plot(x,t);title(tangent(x);axis(0,2*pi,-40,40);subplot(2,2,4);plot(x,ct);title(cotangent(x);axis(0,2*pi,-40,40);x=linspace(0,2*pi,60);y=sin(x);z=cos(x);t=si
10、n(x)./(cos(x)+eps);ct=cos(x)./(sin(x)+eps);subplot(2,2,1);stairs(x,y);title(sin(x)-1);axis(0,2*pi,-1,1);subplot(2,1,2);stem(x,y);title(sin(x)-2);axis(0,2*pi,-1,1);subplot(4,4,3);plot(x,y);title(sin(x);axis(0,2*pi,-1,1);subplot(4,4,4);plot(x,z);title(cos(x);axis(0,2*pi,-1,1);subplot(4,4,7);plot(x,t);
11、title(tangent(x);axis(0,2*pi,-40,40);subplot(4,4,8);plot(x,ct);title(cotangent(x);axis(0,2*pi,-40,40);x=0:0.35:7;y=2*exp(-0.4*x);subplot(2,2,1);bar(x,y,g);title(bar(x,y,g);axis(0,7,0,2);subplot(2,2,2);fill(x,y,r);title(fill(x,y,r);axis(0,7,0,2);subplot(2,3,4);stairs(x,y,b);title(stairs(x,y,b);axis(0
12、,7,0,2);subplot(2,3,5);stem(x,y,k);title(stem(x,y,k);axis(0,7,0,2);subplot(2,3,6);area(x,y);title(area(x,y);axis(0,7,0,2);theta=0:0.01:2*pi;rho=sin(3*theta).*cos(3*theta);polar(theta,rho,r);x=0:0.1:10;y=12*x.*x;subplot(2,2,1);plot(x,y);title(plot(x,y);grid on;subplot(2,2,2);semilogx(x,y);title(semil
13、ogx(x,y);grid on;subplot(2,2,3);semilogx(x,y);title(semipogx(x,y);grid on;subplot(2,2,4);loglog(x,y);title(loglog(x,y);grid on;function y=myf(x);y=cos(tan(pi*x);fplot(myf,-0.2,1.2,1e-4);subplot(1,2,1);pie(7,17,23,19,5);title(饼图);legend(优秀,良好,中等,及格,不及格);subplot(1,2,2);compass(3+2i,4.5-i,-1.5+5i);titl
14、e(相量图);t=0:pi/50:2*pi;x=8*cos(t);y=4*sqrt(2)*sin(t);z=-4*sqrt(2)*sin(t);plot3(x,y,z,p);title(Line in 3-D space);text(0,0,0,origin);xlabel(X),ylabel(Y),zlabel(Z);grid;x=5:29;y=14:35;x,y=meshgrid(x,y);z=2*x+5*y;k=find(z=126);x(k),y(k) bans =8 13 18 23 28ans =22 20 18 16 14x=0:0.1:2*pi;x,y=meshgrid(x);
15、z=sin(y).*cos(x);mesh(x,y,z);xlabel(x-axis),ylabel(y-axis),zlabel(z-axis);title(mesh); x=0:0.1:2*pi;x,y=meshgrid(x);z=sin(y).*cos(x);surf(x,y,z);xlabel(x-asis),ylabel(y-axis),zlabel(z-axis);title(surf);x=0:0.1:2*pi;x,y=meshgrid(x);z=sin(y).*cos(x);plot3(x,y,z);xlabel(x-axis),ylabel(y-axis),zlabel(z-
16、axis);title(plot3);grid;x,y=meshgrid(-10:0.5:10);z=sin(sqrt(x.3+y.2)./sqrt(x.2+y.2+eps);subplot(2,2,1);meshc(x,y,z);title(meshc(x,y,x);subplot(2,2,2);meshz(x,y,z);title(meshz(x,y,x);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);t=0:pi/20:2*pi;x,y,z=cyl
17、inder(2+sin(t),30);subplot(1,3,1);surf(x,y,z);subplot(1,3,2);x,y,z=sphere;surf(x,y,z);subplot(1,3,3);x,y,z=peaks(300);meshz(x,y,z);subplot(2,2,1);bar3(magic(5);subplot(2,2,2);y=3*sin(0:pi/10:2*pi);stem3(y);subplot(2,2,3);pie3(2347,1827,2043,3025);subplot(2,2,4);fill3(rand(3,6),rand(3,6),rand(3,6),r)
18、;subplot(1,2,1);x,y,z=peaks;waterfall(x,y,z);xlabel(x-axis),ylabel(y-axis),zlabel(z-axis);title(waterfall of peaks);subplot(1,2,2);contour3(x,y,z,12,k);xlabel(x-axis),ylabel(y-axis),zlabel(z-axis);title(contour3 of peaks);subplot(2,2,1);mesh(peaks);view(-37.5,30);title(azimuth=-37.5,elevation=30)sub
19、plot(2,2,2);mesh(peaks);view(0,90);title(azimuth=0,elevation=90)subplot(2,2,3);mesh(peaks);view(90,0);title(azimuth=90,elevation=0)subplot(2,2,4);mesh(peaks);view(-7,-10);title(azimuth=-7,elevation=-10)z=peaks(20);colormap(copper);subplot(1,3,1);surf(z);subplot(1,3,2);surf(z);shading flat;subplot(1,3,3);surf(z);shading interp;x=0:0.1:2*pi;x,y=meshgrid(x);z=sin(y).*cos(x);I,J=find(z0.2);for ii=1:length(I) z(I(ii),J(ii)=NaN;endsurf(x,y,z);
限制150内