实验三 MATLAB图形基础.docx
- 文档编号:27918551
- 上传时间:2023-07-06
- 格式:DOCX
- 页数:21
- 大小:2.04MB
实验三 MATLAB图形基础.docx
《实验三 MATLAB图形基础.docx》由会员分享,可在线阅读,更多相关《实验三 MATLAB图形基础.docx(21页珍藏版)》请在冰豆网上搜索。
实验三MATLAB图形基础
MATLAB实验报告(三)
----MATLAB图形基础
学院:
班级:
姓名:
学号:
实验三:
MATLAB图形基础
一、实验名称:
MATLAB图形基础
二、实验目的:
1.掌握MATLAB的交互式绘图的操作方法。
2.学会MATLAB的二维指令绘图的方法。
3.了解MATLAB的三维图形绘制的基本操作。
4.掌握图形的保存和输出的基本操作及方法。
三、实验仪器、材料及软件:
电脑、MATLAB软件
四、实验原理:
数据的可视仅仅是MATLAB图形的一部分,利用MATLAB的图形基础知识来完成二维图形及其三维图形的绘制,可把计算数据的特征更好的表现出来。
五、实验内容:
>>logo
>>logo
>>randn('state',27)
>>startprice=50;
>>fracreturns1=0.0015*randn(200,1)+0.0003;
>>x1=[startprice;1+fracreturns1];
>>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
NameSizeBytesClass
L51x5120808doublearray
fracreturns1200x11600doublearray
fracreturns2200x11600doublearray
l11x18doublearray
l21x18doublearray
prices1201x11608doublearray
prices2201x11608doublearray
s1x18doublearray
startprice1x18doublearray
t201x11608doublearray
x1201x11608doublearray
x2201x11608doublearray
>>x=0:
pi/1000:
2*pi;
>>y=exp(-0.5*x).*sin(2*pi*x+pi/4);
>>plot(x,y)
>>B=pascal(6)
B=
111111
123456
136101521
1410203556
15153570126
162156126252
>>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);
>>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*x1).*sin(2*pi*x1);
>>plot(x,y1,'g:
',x,y2,'b--',x1,y3,'rp');
>>title('曲线及其包络线');
>>xlabel('independentvariableX');
>>ylabel('independentvariableY');
>>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*exp(-0.5*x).*sin(2*pi*x);
>>plot(x,y1,'b:
');
>>axis([0,2*pi,-2,2]);
>>holdon;
>>plot(x,y2,'k');
>>gridon;
>>boxoff;
>>holdoff;
M文件
@functiontex_examp
alpha=-0.5;
beta=3;
A=50;
t=0:
0.01:
10;
y=A*exp(alpha*t).*sin(beta*t);
plot(t,y);
title('\fontname{隶书}\fontsize{16}\fontname{Impact}{Impact}')
xlabel('^{上标}and_{下标}')
ylabei('Some\bf粗体\rmandsome\it{斜体}')
txt={'y={\itAe}^{\alphax}sin(\beta\itt)',...
['\itA\rm','='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(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=sin(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,t);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);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,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');
M文件
@functiony=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]);
>>title('相量图');
>>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('Linein3-DSpace');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)'
ans=
8
13
18
23
28
ans=
2220181614
>>
x=0:
0.1:
2*pi;[x,y]=meshgrid(x);z=sin(y).*cos(x);
>>x=0:
0.1:
2*pi;[x,y]=meshgrid(x);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);
>>x=0:
0.1:
2*pi;[x,y]=meshgrid(x);z=sin(y).*cos(x);surf(x,y,z);xlabel('x-axis'),ylabel('y-axis'),zlabel('z-axis');title('surf');
>>
>>x=0:
0.1:
2*pi;[x,y]=meshgrid(x);z=sin(y).*cos(x);
>>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-axis');title('plot3');
[x,y]=meshgrid(-10:
0.5:
10);
>>z=sin(sqrt(x.^2+y.^2))./sqrt(x.^2+y.^2+eps);
>>subplot(2,2,1);
>>meshc(x,y,z);
>>title('meshc(x,y,z)');
>>subplot(2,2,2);
>>meshz(x,y,z);
>>title('meshz(x,y,z)');
>>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]=cylinder(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(30);
>>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');
>>
subplot(1,2,1);
>>[x,y,z]=peaks;
>>waterfall(x,y,z);
>>xlabel('x-axis'),ylabel('y-axis');zlabel('z-axis');
>>title('waterfallofpeaks');
>>subplot(1,2,2);
>>contour3(x,y,z,12,'k');
>>xlabel('x-axis'),ylabel('y-axis');zlabel('z-axis');
>>title('contour3ofpeaks');
>>subplot(2,2,1);mesh(peaks);
>>view(-37.5,30);
>>title('azimuth=37.5,elevation=30')
>>subplot(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);shadingflat;
>>subplot(1,3,3);surf(z);shadinginterp;
>>x=0:
0.1:
2*pi;[x,y]=meshgrid(x);z=sin(y).*cos(x);
>>[I,J]=find(z>0.2);
>>forii=1:
length(I)
z(I(ii),J(ii))=NaN;
end
>>surf(x,y,z);
>>surf(peaks(30))
>>saveas(gcf,'peakfile','m')
>>peakfile
>>open('peakfile.fig')
>>
六、实验结论:
用MATLAB做二维图形和三维图形更清晰直观和方便。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验三 MATLAB图形基础 实验 MATLAB 图形 基础
![提示](https://static.bdocx.com/images/bang_tan.gif)