MATLAB 数据和函数的可视化综合例题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

0
0.5
1
1.5
2
2.5
3
温州大学本科生课程――《工程中的数值计算》
6. 三维线图指令plot3
【例10】简单例题。
Á´ ±Ê¯ ¦
1 1 0.5
t=(0:0.02:2)*pi; x=sin(t); y=cos(t); z=cos(2*t); plot3(x,y,z,'b-',x,y,z,'bd'),view([-82,58]),box on,legend('链','宝石')
温州大学本科生课程――《工程中的数值计算》
11.特殊图形和高维可视化
面域图area 【例15】面域图指令area 。该指令的特点是:在图上绘制 多条曲线时,每条曲线(除第一条外)都是把“前”条曲 线作基线,再取值绘制而成。因此,该指令所画的图形, 能醒目地反映各因素对最终结果的贡献份额。注意:(1) area的第一输入宗量是单调变化的自变量。第二输入宗量 是“各因素”的函数值矩阵,且每个“因素”的数据取列 向量形式排放。第三输入宗量是绘图的基准线值,只能取 标量。当基准值为0(即以x轴为基准线)时,第三输入宗 量可以缺省。(2)本例第<4>条指令书写格式x' , Y' , 强 调沿列方向画各条曲线的事实。
1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1
0
1
2
3
4
5
6
7
温州大学本科生课程――《工程中的数值计算》
【例2】用图形表示连续调制波形 及其包络线。
1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1
y sin(t ) sin(9t )
-2 -3 -4 -6 -4 -2 0 x
y
2
4
6
温州大学本科生课程――《工程中的数值计算》
2. 坐标、刻度和分格线控制
【例4】观察各种轴控制指令的影响。演示采用长轴为 3.25,短轴为1.15的椭圆。注意:采用多子图表现时,图 形形状不仅受“控制指令”影响,而且受整个图面“宽高 比”及“子图数目”的影响。
40
30
20
10
0 4 2 0 -2 -4 -4 0 -2 2 4
温州大学本科生课程――《工程中的数值计算》
8. 透视、镂空和裁切
【例12】透视演示
[X0,Y0,Z0]=sphere(30); X=2*X0;Y=2*Y0;Z=2*Z0; surf(X0,Y0,Z0); shading interp hold on,mesh(X,Y,Z),colormap(hot),hold off hidden off axis equal,axis off
0 1 2 3 4 5 6
温州大学本科生课程――《工程中的数值计算》
• 【例7】利用hold绘制离散信号通过零阶保持器后 产生的波形。
t=2*pi*(0:20)/20; y=cos(t).*exp(-0.4*t); stem(t,y,'g'); hold on stairs(t,y,'r') hold off
温州大学本科生课程――《工程中的数值计算》
3. 图形标识
【例6】本例非常简单,专供试验标识用。
1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1
¬sin(t)Õ Õ Õ ó
clf t=0:pi/50:2*pi; y=sin(t);plot(t,y); axis([0,2*pi,-1.2,1.2]) text(pi/2,1,'\fontsize{16}\leftarrow\itsin(t)\fontname{隶书}极大值')
温州大学本科生课程――《工程中的数值计算》
数据和函数的可视化
视觉是人们感受世界、认识自然的最重要依靠。数据可 视化的目的在于:通过图形,从一堆杂乱的离散数据中观察 数据间的内在关系,感受由图形所传递的内在本质。
温州大学本科生课程――《工程中的数值计算》
1. plot的基本调用格式
【例1】简单例题 t=(0:pi/50:2*pi)'; k=0.4:0.1:1; Y=cos(t)*k; plot(t,Y)
1.05 1

0.95
­
ò Õ± Õ¨ÕÕ
ts = 9.6133
6.2832
12.5664
18.8496

clf;t=6*pi*(0:100)/100;y=1-exp(-0.3*t).*cos(0.7*t); tt=t(find(abs(y-1)>0.05));ts=max(tt); plot(t,y,'r-','LineWidth',3) axis([-inf,6*pi,0.6,inf]) set(gca,'Xtick',[2*pi,4*pi,6*pi],'Ytick',[0.95,1,1.05,max(y)]) grid on title('\it y = 1 - e^{ -\alphat}cos{\omegat}') text(13.5,1.2,'\fontsize{12}{\alpha}=0.3') text(13.5,1.1,'\fontsize{12}{\omega}=0.7') hold on;plot(ts,0.95,'bo','MarkerSize',10);hold off cell_string{1}='\fontsize{12}\uparrow'; cell_string{2}='\fontsize{16} \fontname{隶书}镇定时间'; cell_string{3}='\fontsize{6} '; cell_string{4}=['\fontsize{14}\rmt_{s} = ' num2str(ts)]; text(ts,0.85,cell_string) xlabel('\fontsize{14} \bft \rightarrow') ylabel('\fontsize{14} \bfy \rightarrow')
% <1> % <2> % <3> % <4>
% <5> % <6>
温州大学本科生课程――《工程中的数值计算》
【例3】采用模型 画一组椭圆。
x2 y2 1 2 2 a 25 a
A set of Ellipses
4 3 2 1 0 -1
th = [0:pi/50:2*pi]'; a = [0.5:.5:4.5]; X = cos(th)*a; Y = sin(th)*sqrt(25-a.^2); plot(X,Y),axis('equal'),xlabel('x'), ylabel('y') title('A set of Ellipses')
温州大学本科生课程――《工程中的数值计算》
Normal and Grid on 4 2 0 -2 -4 -2 2
Equal 4 2 0 -2 0 -2 -4 -2
Square
0 Image and Box off 2
2
-2
0
2
0 Tight
2
Image and Fill 1 0.5 2
0
0 -0.5
0
0.5
1
1.5
2
2.5
3
t=(0:pi/100:pi)'; y1=sin(t)*[1,-1]; y2=sin(t).*sin(9*t); t3=pi*(0:9)/9; y3=sin(t3).*sin(9*t3); plot(t,y1,'r:',t,y2,'b',t3,y3,'bo') axis([0,pi,-1,1])
-5 0 0.5 1 1.5 2 2.5 3 3.5 0 4
温州大学本科生课程――《工程中的数值计算》
5. 多子图
【例9】演示subplot指令对图形窗的分割。
1 0.5 0 -0.5 -1 1 0.5 0 -0.5 -1
0 1
1
2
3
0
1
2
3
0.5
0
-0.5
-1
clf;t=(pi*(0:1000)/1000)'; y1=sin(t);y2=sin(10*t);y12=sin(t).*sin(10*t); subplot(2,2,1),plot(t,y1);axis([0,pi,-1,1]) subplot(2,2,2),plot(t,y2);axis([0,pi,-1,1]) subplot('position',[0.2,0.05,0.6,0.45]) plot(t,y12,'b-',t,[y1,-y1],'r:');axis([0,pi,-1,1])
0
-2 -1 0 1
-1 -1 0 1
-2 -1 0 1
温州大学本科生课程――《工程中的数值计算》
【例5】通过绘制二阶系统阶跃响应,综合演示图形标识。 本例比较综合,涉及的指令较广。请耐心读、实际做、再 看例后说明,定会有匪浅收益。
y = 1 - e -a .7
0 0 -0.5 -1 -0.5 1 0.5 0 -0.5 -1 -1
0.5
温州大学本科生课程――《工程中的数值计算》
7. 三维网线图和曲面图
【例11】用曲面图表现函数
zx y
2
2
clf x=-4:4; y=x; [X,Y]=meshgrid(x,y); Z=X.^2+Y.^2; surf(X,Y,Z); hold on,colormap(hot) stem3(X,Y,Z,'bo')
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
0
1
2
3
4
5
6
7
温州大学本科生课程――《工程中的数值计算》
4.双纵坐标图
【例8】画出函数 y x sin x 和积分 s 0 ( x sin x)dx 区间[0,4]上的曲线。
x
5

4
s=
x
0
xsinxdx
0
y=xsinx
2
clf dx=0.1; x=0:dx:4; y=x.*sin(x); s=cumtrapz(y)*dx; %梯形法求累计积分 plotyy(x,y,x,s),text(0.5,0,'\fontsize{14}\ity=xsinx') sint='{\fontsize{16}\int_{\fontsize{8}0}^{ x}}'; text(2.5,3.5,['\fontsize{14}\its=',sint,'\fontsize{14}\itxsinxdx'])
温州大学本科生课程――《工程中的数值计算》
10. 裁剪
【例14】表现切面
clf, x=[-8:0.05:8]; y=x; [X,Y]=meshgrid(x,y); ZZ=X.^2-Y.^2; ii=find(abs(X)>6|abs(Y)>6); ZZ(ii)=zeros(size(ii)); surf(X,Y,ZZ),shading interp;colormap(copper) light('position',[0,-15,1]);lighting phong material([0.8,0.8,0.5,10,0.5])
温州大学本科生课程――《工程中的数值计算》
9. 图形的镂空
【例13】演示:如何利用“非数”NaN,对图形进行剪 切处理。
t=linspace(0,2*pi,100); r=1-exp(-t/2).*cos(4*t); [X,Y,Z]=cylinder(r,60); ii=find(X<0&Y<0); Z(ii)=NaN; surf(X,Y,Z);colormap(spring),shading interp light('position',[-3,-1,3],'style','local') material([0.5,0.4,0.3,10,0.3])
t=0:2*pi/99:2*pi; x=1.15*cos(t);y=3.25*sin(t); % subplot(2,3,1),plot(x,y),axis normal,grid on, title('Normal and Grid on') subplot(2,3,2),plot(x,y),axis equal,grid on,title('Equal') subplot(2,3,3),plot(x,y),axis square,grid on,title('Square') subplot(2,3,4),plot(x,y),axis image,box off,title('Image and Box off') subplot(2,3,5),plot(x,y),axis image fill,box off title('Image and Fill') subplot(2,3,6),plot(x,y),axis tight,box off,title('Tight')
相关文档
最新文档