文档详情

实验三 MATLAB的图形绘制和程序设计.doc

发布:2016-03-31约2.18千字共6页下载文档
文本预览下载声明
实验三 MATLAB的图形绘制和程序设计 一、实验目的 1.学习 MATLAB 图形绘制的基本方法; 2.熟悉和了解 MATLAB图形绘制程序编辑的基本指令; 3. 熟悉 MATLAB 程序编辑与设计环境; 4. 掌握各种编程语句语法规则及程序设计方法 二、实验内容 1.在同一图形窗口中绘制的函数曲线(标记两条曲线的颜色、线型和数据点),添加标题和网格线,并分别应用text、gtext、legend指令进行相应的文字标注。(参考例2-17) t=0:pi/36:2*pi; y1=sin(2*t); y2=cos(2*t); plot(x,y1,b:.) hold on plot(x,y2,k:*) legend(y1=sin(2*t),y2=con(2*t)) gtext(y1=sin(2*t)) gtext(y2=con(2*t)) text(1,0.5,(1,0.5)) xlabel(x),ylabel(y) title(同一窗口下显示sin(),cos()曲线) grid 在两个窗口中分别绘制,并对坐标进行标注、添加标题和网格线。 t=0:pi/36:2*pi; y1=sin(2*t); figure(1); plot(x,y1,r:.); title(y1=sin(t)) grid; xlabel(x);ylabel(y1); y2=cos(2*t); figure(2); plot(x,y1,k:*); title(y2=cos(t)) grid; xlabel(x);ylabel(y2); 将一个图形窗口分割为四个显示窗口,分别绘制的图形。 x=0:pi/36:2*pi; y1=sin(2*t); subplot(221); plot(x,y1,r:.); title(y1=sin(t)) grid;xlabel(x);ylabel(y1); y2=cos(2*t); subplot(222); plot(x,y2,k:*); title(y2=cos(t)) grid;xlabel(x);ylabel(y2); y3=y1+y2; subplot(223); plot(x,y3,b:o); title(y3=y1+y2) grid;xlabel(x);ylabel(y3); y4=y1-y2; subplot(224); plot(x,y4,g:+); title(y4=y1-y2) grid;xlabel(x);ylabel(y4); 设方程组为,试绘制由变量x,y,确定的三维曲线,添加标题、横纵坐标标注和网格线。 t=0:pi/36:6*pi; x=sin(t); y=cos(t); z=t; plot3(x,y,z); xlabel(x),ylabel(y),zlabel(z); title(x,y,z确定的三维曲线) grid 运行课本的例2—19和2—20并记录程序及结果。 2-19 %计算出1~4的乘法表 for n=1:4 for m=1:n r(n,m)=m*n end end 运行结果: r = 1 0 0 0 2 4 0 0 3 6 9 0 4 8 12 16 2-20 %计算2000以内的fibnacci数 f(1)=1 f(2)=1 i=1 while f(i)+f(i+1)2000 f(i+2)=f(i)+f(i+1) i=i+1 end 运行结果: i = 16 f = Columns 1 through 7 1 1 2 3 5 8 13 Columns 8 through 14 21 34 55 89 144 233 377 Columns 15 through 17 610 987 1597 分别用for和while循环结构编写程序,求的值。 (1) for i=0:63 K=K+2^i; i=i+1; end K 运行结果: K = 1.8447e+019 clc K=0; i=0; while(ilt;=63) K=K+2^i; i=i+1; end K = 1.8447e+019 收获体会
显示全部
相似文档