《中南大学matlab课后习题.pdf》由会员分享,可在线阅读,更多相关《中南大学matlab课后习题.pdf(56页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、MATLAB程序设计上机练习课后题电科1202班 行晓慧 学号1404120229电科1202班 羊月妹 学号1404120304电科1202班 周悦 学号1404120316第一章-实验内容1.打开软件,按照步骤:F ile-S et P ath-A dd F o lder-save在盘中建立一个名为mat lab的工作目录,然后在命令窗口运行help命令查询所设置的工作目录,观察结果。2.源代码例 1-1x=0:0.5:36 0*pi/18 0;plo t(x,sin(x),x,co s(x);例 1-2P=3,7,9,0,-23;x=ro o ts(p)例 1-3qu ad(x.*lo
2、g(l+x),0,1)syms xint(x*lo g(l+x),0,1)例 1-4 a=2,-3,1;8,3,2:45,1,-9;b=4;2;17;x=inv(a)*b syms x y zx,y,z=so lve(2*x-3*y+z-4,8*x+3*y+2*z-2,45*x+y-9*zT 7)M A T LA B 的主要优点:编程效率高;用户使用方便;扩展能力强,交互性好;移植性和开发性好;语句简单,内涵丰富;高效方便的矩阵和数组运算;方便的绘图功能。3.利用M A T LA B 的帮助功能,查询了解到i n v、plo t、m a x、ro u nd等函数的功能与用法如下:I nv取矩阵
3、的逆。P lo t绘制平面图I N V M atrix inverse.P LO T Linear plo t.M ax 求 最 大值 help ro u nd 四舍五入M A X Largest co mpo nent.R O U N D R o u nd to wards nearest integer.4.x=0:pi/10:2*pi;y=sin(x);y 的图形如图:纵轴是y 的值,x 是 将 0:2pi】分为20等分思考练习:1.启动M A T LA B系统有3种常见方法:(1)使用W indo ws“开始”菜单。(2)运行M A T LA B系统启动程序matlab.exe。(3)
4、利用快捷方式。要退出M A T LA B系统,也有3种常见方法:(1)在M A T LA B主窗口 F ile菜单中选中E xit M A T LA B命令。(2)在M A T LA B命令窗口输入E xit或Q u it命令。(3)单击M A T LA B主窗口的“关闭”按钮。2.mat lab的主要功能数值计算、符号计算、优化工具、数据分析和可视化功能、工具箱和非线性动态系统建模和仿真3.如果一个M A T LA B命令包含的字符很多,需要分成多行输入,只要同时按下s h i f t和E n t e r键即可。4 .L o o k f o r 与 h e l p 的区别:在所有M文件中找“
5、关键词,比如:l o o k f o r m a x,而h e l p是显示mat l ab内置的帮 助 信 息,比 如h e l p i n vo5.在M at l ab环境下,同名变量与M文件的执行问题:%可 以 调 用,为 了 避 开 当 前 工 作 间(W o r k s p ace ),采 用 函 数 调 用 方式 f un ct i o n r un f ac(f n ame)r un f n ame%保存为 r un f ac.mr un f ac(f ac)第二章实验指导1.(1)w=s q r t(2)*(1+0.3 4 2 4 5*1 0*(-6)w=1.4 1 4 2(2
6、)a=3.5;b=5;c=-9.8;x=(2*p i*a+(b+c)/(p i+a*b*c)-e xp(2)/(t an(b+c)+a)x=0.9 82 9(3)a=3.3 2;b=-7.9;y=2*p i*a*2*(l-p i/4)*b-(0.83 3 3 p i/4)*a)y=-1 2 8.4 2 7 1(4)t=2,l-3 i;5,-0.6 5;z=0.5*e xp(2*t)*l o g(t+s q r t(l+t*t)z=1.0e+004 *0.004 8+0.0002 i 0.004 8-0.003 4 i1.589 9 2.009 0-1.3 580i2.(1)(2)(3)A=-l
7、,5,-4;0,7,8;3,6 1,7 ;B=8,3,-1;2,5,3,;-3,2,0;Y 1=A+6*BY 1=4 72 3-1 01 23 72 6-1 57 37 Y 2=A*A-B+1Y 2=-1 8-2 1 61 82 353 31 1 02 286 852 6 Y 3=A*BY 3=1 41 41 6-1 0512 11 2 53 2 81 80 Y 4=A.*BY 4=-81 5403 52 4-91 2 20 Y 5=A/BY 5=1.2 2 3 4-0.9 2 552.9 7 87-0.9 4 6 82.3 51 1-0.9 57 44.6 1 7 03.87 2 31 3.
8、89 3 6 Y 6=B AY 6=-0.51 06-8.6 1 7 0-1.1 2 7 70.7 3 4 01 7.57 4 51.8085-0.883 0-2 1.2 1 2 80.4 04 3 Y 7=A,B Y 7=-15-48 3-10782 5 336 17-3 2 0 Y 8=A(1,3 ,:);B*2 Y 8=-15-436 177 33 711 73 71 3-2 0193.A=2 3,1 0,-0.7 7 8,0;4 1,-4 5,6 5,5;3 2,5,0,3 2 ;6,-9.54,54,3.1 4 ;k=f i n d(A=1 0&A=2 5)A(k)B=A(1:3,:
9、)C=A(:,1:2)D=A(2:4,3:4)E=B*CE=9 0&n=80&n=7 0&n=6 0&n aa=n (m);e l s e i f n(m)bb=n (m);e n de n dmax 二 ami n=b法2n=l,5,56,4,3,4 7 6,4 5,6,3,7 6,4 5,6,4,3,6,4,2 3,7 6,9 08,6 ;mi n=mi n(n)max=max(n)4b=-3.0:0.1:3.0;f o r n=l:6 1a=b(n);y(n)=(e xp (0.3*a)-e xp(-0.3*a)/2*s i n(a+0.3)+l o g(0.3+a)/2);e n dy
10、5yl=0;y2=l;n=i n p ut (请输入n的值:);f o r i=l:nyl=yl+1/1 2;y2=y2*(4*i*i)/(2*i-l)*(2*i+l);e n dyiy261,1,1;2,2,2,2,2,2;3,3,3,3,3,3;4,4,4,4,4,4;5,5,5,5,5,5;6,6,6,6,6,6 ;n二i n p ut (请输入n的值:);i f n=0di s p(A(n ,:);e l s e i f n 0di s p(l as t e r r);e l s e di s p(A(6 ,:);di s p(l as t e r r);e n d7 (1)f=;f
11、o r n=l:4 0f (n)=n+1 0*l o g(n 2+5);e n dy=f(4 0)/(f(3 0)+f(2 0)(2)f=;a=0;f o r n=l:4 0f(n)=a+n*(n+1);a=f(n);e n dy=f(4 0)/(f(3 0)+f(2 0)8y=0;m=i n p ut C 输入 m 的值:);n=i n p ut(,输入 n 值:);f o r i=l:ny=y+i m;e n dyf un ct i o n s=s h i 8 1(n,m)s=0;f o r i=l:ns=s+i m;e n ds h i 8 1(1 00,l)+s h i 8 1(50,
12、2)+s h i 8_ l(1 0,1/2)思考练习1用 M A TL A B 语言编写的程序,称为M文件。为建立新的M文件,启动M A T L A B文本编辑器有3 种方法:(1)菜单操作。从 M A T L A B主窗口的F i l e 菜单中选择N e w菜单项,再选择M-f i l e 命令,屏幕上将出现M A T L A B文本编辑器窗口。(2)命令操作。在 M A T L A B命令窗口输入命令e d i t,启动M A T L A B文本编辑器后,输入M文件的内容并存盘。(3)命令按钮操作。单击M A T L A B主窗口工具栏上的N e wM-F i l e 命令按钮,启动M
13、A T L A B文本编辑器后,输入M文件的内容并存盘。打开已有的M文件,也有3 种方法:(1)菜单操作。从 M A T L A B主窗口的F i l e 菜单中选择O pe n命令,则屏幕出现O pe n对 话框,在 O pe n对话框中选中所需打开的M文件。在文档窗口可以对打开的M文件进行编辑修改,编辑完成后,将 M文件存盘。(2)命令操作。在 M A T L A B命令窗口输入命令:e d i t文件名,则打开指定的M文件。(3)命令按钮操作。单击M A T L A B主窗口工具栏上的O pe n F i l e 命令按钮,再从弹出的对话框中选择所需打开的M文件。2N=l,2,3,4,5
14、;2.*NN./21./Nl./N.23s=f i x(100*ra nd(l,2 0)*9/10+10)y=sum(s)/2 0j=0;f or i=l:2 0i f s(i)f unc ti on f =Ba i d uZd(sh u,Z,n)%UN T I T L E D2 S umma ry of th i s f unc ti on g oe s h e re%De ta i l e d e xpl a na ti on g oe s h e reswi tc h Zc a se si n,f=si n(sh u);c a se c osf=c os(sh u);c a se l o
15、g)f=l og(sh u);c a se zh i sh uf 二 s noth e rwi sed i sp(,e rror,)e nde nd第四章实验指导1(1)x=-10:0.05:10;y=x-x.3./6;pl ot(x,y)(2)x=-10:0.5:10;e zpl ot(J x 2+2*y 2-6 4?,-8,8 );g ri d on;2、t=-pi:pi/10:pi;y=l./(l+e xp(-t);sub pl ot(2,2,1);b a r(t,y);ti tl e(,I 6 Dl f!4(t,y);a xi s(-pi,pi,0,1);sub pl ot(2,2,2
16、);sta i rs(t,y,b );ti tl e(,X I Y I!4(t,y);a xi s(-pi,pi,0,1);sub pl ot(2,2,3);ste m(t,y,k);ti tl e(,,E I%(t,y);a xi s(-pi,pi,0,1);sub pl ot 2,4);l og l og(t,y,y);ti tl e H O E yX 0 e l!4(t,y);3、(1)t=0:pi/50:2*pi;r=5.*c os(t)+4;pol a r(t,r);ti tl e()rh o=5*c os th e ta+4,);(2)t=-pi/3:pi/50:pi/3;r=5.
17、*(si n(t).2)./c os(t);pol a r(t,r);4(1)t=0:pi/50:2*pi;x=e xp(-t./2 0).*c os(t);y=e xp(-t./2 0).*si n(t);z=t;pl ot3(x,y,z);g ri d on;(2)x,y=me sh g ri d(-5:5);z二ze ros(11)+5;me sh(x,y,z);sh a d i ng i nte rp;5、x,y,z=sph e re (2 0);surf (x,y,z);a xi s of f;sh a d i ng i nte rp;m=movi e i n(2 0);f or i
18、=l:2 0a xi s(-i,i,-i,i,-i,i )m(:i)=g e tf ra me;e ndmovi e(m,4);思考练习:1、在同一坐标轴绘制多条二维曲线的方法:(1)利用pl ot函数,输入参数是矩阵形式;(2)利用pl ot函数,其里面的参数是多组向量对。2、(1)x=-5:0.1:5;y=(l./(2*pi).*e xp(-(xZ2)/2);pl ot(x,y);(2)t=-2*pi:0.l:2*pi;x=t.*si n(t);y=t.*c os(t);pl ot(x,y);g ri d on;3、t=0:pi/1000:pi;x=si n(3.*t).*c os(t);
19、yl=si n(3.*t).*si n(t);y2=2.*x-0.5;pl ot(x,yl,k,x,y2);h ol d on;k=f i nd(a b s(yl-y2)0.5)n=n+1;endendny=n/3 0 0 0 05、p=4 5,7 4,5 4,5 5,1 4;7 8,9 8,4 5,7 4,1 2;8 7,9 8,8 5,5 2,6 5 M,S =max(p)N,H=min(p)junzhi=mean(p,1)fangcha=std(p,1,1)zong=sum(p,2);M ax,wei=max(zong)M in,wei=min(zong)zcj,xsxh=sort(zo
20、ng,descend,)6 、x=1:1 0:1 0 1 ;y=0,1.0 4 1 4,1.3 2 2 2,1.4 9 1 4,1.6 1 2 8,1.7 0 7 6,1.7 8 5 3,1.8 5 1 3,1.9 0 8 5,1.9 5 9 0,2.0 0 4 3 ;p,s=polyfit(x,y,5)a=l:5:1 0 1;yl=polyval(p,a);plot(x,y,:o,a,yl,-*)第六章实验指导1、A=l/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6 ;p=0.9 5,0.6 7,0.5 2 ;x=A pA=l/2,1/3,1/4;1/3,1/4,1/5
21、;1/4,1/5,1/6 ;p=0.9 5,0.6 7,0.5 3 ;x=A pcond(A)x=1.2 0 0 00.6 0 0 00.6 0 0 0 x=3.0 0 0 0-6.6 0 0 06.6 0 0 0ans=1.3 5 3 3 e+0 0 32 (1)function fx二funxl(x)fx=x 4 1+x 3+l;%建立函数文件xl=fzero(funxl,-1)xl=-0.9 5 2 5(2)function fx=funx2(x)fx=x-sin(x)/x;%建立函数文件x2=fzero(funx2,0.5)x2 =0.8 7 6 7(3)function q=fun3
22、(p)x=p(l);y=p(2);z=p(3);q(l)=sin(x)+y 2+log(z)-7;q(2)=3*x+2-y-z5 3+1;q(3)=x+y+z-5;%建立函数文件options=optimset(Display,off);x=fsolve(fun3,1,1,1 *,options)q=fun3(x)x=0.5 9 9 12.3 9 5 92.0 0 5 0q=1.0 e-0 1 0 *0.2 2 1 3 0.3 8 0 4 0.0 0 0 93 (1)function yp=fun4(t,y)yp=-(l.2+sin(1 0*t)*y;%建立函数文件t0=0;tf=5;y0=l
23、;t,y=ode2 3(fun4,tO,tf,yO);tyans=Columns 1 through 1 000.0 6 6 70.1 3 7 50.2 0 0 30.2 6 9 50.3 5 2 80.4 3 6 20.5 0 3 3 0.Columns 1 10.6 9 1 35 6 6 3 0.6 3 6 9through 2 00.7 4 5 70.8 0 8 10.8 7 3 80.9 5 9 11.0 2 7 71.0 9 6 31.1 6 0 0 1.Columns 211.3 7 1 42 2 4 6 1.3 0 8 2through 3 01.4 3 4 71.5 0 0 1
24、1.5 8 4 21.6 5 3 01.7 2 1 91.7 8 5 81.8 5 0 1 1.9 3 1 9 1.9 9 5 3Columns 3 1 through 4 02.0 5 8 7 2.1 2 3 62.2 0 5 32.2 7 4 52.3 4 3 82.4 0 8 02.4 7 1 92.5 5 0 1 2.6 1 4 0 2.6 7 7 9Columns 4 1 through 5 02.7 4 1 9 2.8 1 9 32.9 0 4 62.9 6 8 53.0 3 2 33.0 9 5 93.1 7 2 13.2 3 6 4 3.3 0 0 7 3.3 6 4 2Col
25、umns 5 1 through 6 03.4 3 9 5 3.5 3 2 83.5 9 6 53.6 6 0 23.7 2 3 83.7 9 9 83.8 6 4 23.9 2 8 6 3.9 9 2 0 4.0 6 7 1Columns 6 1 through 7 04.1 4 0 8 4.2 1 4 44.2 8 0 04.3 4 3 24.4 1 5 94.4 8 1 24.5 4 6 54.6 0 9 4 4.6 8 1 2 4.7 5 6 7Columns 7 1 through 7 44.8 3 2 2 4.8 9 9 0 4.9 6 2 0 5.0 0 0 0ans=Colum
26、ns 1 through 1 01.0 0 0 0 0.9 0 3 5 0.7 8 2 2 0.6 8 2 30.5 9 8 40.5 4 0 20.5 1 8 20.5 1 0 6 0.4 9 7 6 0.4 6 5 6Columns 1 1 through 2 00.4 2 8 0 0.3 8 4 40.3 3 5 50.2 9 3 60.2 5 9 50.2 4 6 90.2 4 2 10.2 3 8 2 0.2 2 9 0 0.2 0 5 4Columns 2 1 through 3 00.1 8 1 9 0.1 5 8 50.1 3 8 70.1 2 2 50.1 1 6 40.1
27、1 4 00.1 1 2 20.1 0 8 0 0.0 9 7 4 0.0 8 6 4Columns 3 1 through 4 00.0 7 5 3 0.0 6 5 80.0 5 8 10.0 5 4 90.0 5 3 70.0 5 2 90.0 5 1 10.0 4 6 6 0.0 4 1 5 0.0 3 6 1Columns 4 1 through 5 00.0 3 1 6 0.0 2 7 80.0 2 5 80.0 2 5 30.0 2 4 90.0 2 4 10.0 2 2 10.0 1 9 7 0.0 1 7 2 0.0 1 5 0Columns 5 1 through 6 00.
28、0 1 3 2 0.0 1 2 20.0 1 1 90.0 1 1 70.0 1 1 40.0 1 0 40.0 0 9 30.0 0 8 1 0.0 0 7 1 0.0 0 6 2Columns 6 1 through 7 00.0 0 5 8 0.0 0 5 60.0 0 5 50.0 0 5 40.0 0 5 00.0 0 4 50.0 0 3 90.0 0 3 4 0.0 0 3 0 0.0 0 2 7Columns 7 1 through 7 40.0 0 2 6 0.0 0 2 6 0.0 0 2 5 0.0 0 2 5(2)function yp=fun5(t,y)yp=cos(
29、t)-y/(l+t 2);%建立函数文件t0=0;tf=5;y0=l;t,y=ode2 3(fun5,tO,tf,yO);tyans=Columns 1 through 1 00 0.5 0 0 00.8 0 1 61.1 0 3 31.4 0 7 71.7 5 3 72.2 3 0 12.5 2 1 5 2.8 1 2 9 2.9 7 2 7Columns 1 1 through 1 83.1 3 2 6 3.3 0 0 13.5 0 9 13.7 5 4 94.0 3 7 54.3 6 3 74.7 5 8 45.0 0 0 0ans=Columns 1 through 1 01.0 0
30、0 0 1.0 1 4 61.0 3 6 31.0 4 5 01.0 1 6 20.9 1 5 70.6 4 5 10.4 1 2 2 0.1 4 3 7 -0.0 1 2 2Columns 1 1 through 1 8-0.1 6 9 9 -0.3 3 3 0-0.5 2 7 3-0.7 3 2 7-0.9 2 3 3-1.0 6 4 9-1.1 0 4 0-1.0 5 3 44 function fx=mymin(x)fx=-(l+x/2)/(l+x/4);x=fminb nd(mymin,0,2);-mymin(x)ans-%建立函数文件1.2 0 7 15 function f=fu
31、n6(x)f=-(sqrt(x(l)+(4 0 0-x(1)*1.l+(sqrt(x(2)+(4 0 0-x(l)*l.l-x(2)*l.1+sqrt(3)+(40 0-x(l)*l.1-x(2)*1.l-x(3)*l.l+sqrt(x(x4);%建立函数文件options=optimset(Display,off,);x,fval=fmincon(fun6,0,0,0 ,a,b,lb,ub)-fval思考练习1 (1)A二 3,5;3,7,4;1,-7,1 ;B=1 0,3,5丁 ;Cl=inv(A)*BC2=A B L,U=lu(A);x=U(L B)Cl=-1.8 0 6 0-0.5 3
32、 7 33.0 4 4 8C2 =-1.8 0 6 0-0.5 3 7 33.0 4 4 8x=-1.8 0 6 0-0.5 3 7 33.0 4 4 8(2)A=6,5,-2,5;9,-l,4,-l;3,4,2,-2;3,-9,0,2 ;B=-4,1 3,1,1 1 ;Cl=inv(A)*BC2=A B L,U=lu(A);x=U(L B)Cl=0.6 6 6 7-1.0 0 0 01.5 0 0 00.0 0 0 0C2 =0.6 6 6 7-1.0 0 0 01.5 0 0 0-0.0 0 0 0 x=0.6 6 6 7-1.0 0 0 01.5 0 0 0-0.0 0 0 02 (1)
33、function fx=funxl(x)fx=3*x+sin(x)-exp(x);%建立函数文件xl=fzero(funxl,1.5)xl=1.8 9 0 0(2)function fx=funx2(x)fx=x-l/x+5;%建立函数文件xl=fzero(funx2,1)xl=0.1 9 2 6(3)function q=fun3(p)x=p(l);y=P (2);q(l)=x-2+-2-9;q(2)=x+yT;%建立函数文件options=optimset(Display,off,);x=fsolve(fun3,3,0 J,options)q=fun3(x)X=2.5 6 1 6-1.5
34、6 1 6q=1.0 e-0 1 3 *0.5 6 8 4 0.0 0 4 43 (1)function ydot=vdpol(t,y);ydot(1)=(2-3*y(2)-2*t*y(1)./(1+t*2);ydot(2)=y(1);ydot=ydot ;%建立函数文件t0=0;tf=5;y0=0,1 ;t,y=ode4 5(vdpol,tO,tf,yO);t,yans=001.0 0 0 00.0 0 0 1-0.0 0 0 11.0 0 0 00.0 0 0 1-0.0 0 0 11.0 0 0 00.0 0 0 2-0.0 0 0 21.0 0 0 00.0 0 0 2-0.0 0 0
35、 21.0 0 0 00.0 0 0 5-0.0 0 0 51.0 0 0 00.0 0 0 7-0.0 0 0 71.0 0 0 00.0 0 1 0-0.0 0 1 01.0 0 0 00.0 0 1 2-0.0 0 1 21.0 0 0 00.0 0 2 5-0.0 0 2 51.0 0 0 00.0 0 3 7-0.0 0 3 71.0 0 0 00.0 0 5 0-0.0 0 5 01.0 0 0 00.0 0 6 2-0.0 0 6 21.0 0 0 00.0 1 2 5-0.0 1 2 50.9 9 9 90.0 1 8 8-0.0 1 8 80.9 9 9 80.0 2 5 1
36、-0.0 2 5 00.9 9 9 70.0 3 1 3-0.0 3 1 30.9 9 9 50.0 6 2 7-0.0 6 2 40.9 9 8 00.0 9 4 1-0.0 9 2 90.9 9 5 60.1 2 5 5-0.1 2 2 60.9 9 2 20.1 5 6 9-0.1 5 1 30.9 8 7 90.2 7 1 7-0.2 4 3 90.9 6 5 00.3 8 6 4-0.3 1 2 70.9 3 2 80.5 0 1 1-0.3 5 5 40.8 9 4 30.6 1 5 8-0.3 7 3 80.8 5 2 30.7 4 0 8-0.3 7 2 10.8 0 5 40
37、.8 6 5 8-0.3 5 4 20.7 5 9 90.9 9 0 8-0.3 2 6 30.7 1 7 31.1 1 5 8-0.2 9 3 20.6 7 8 51.2 4 0 8-0.2 5 8 40.6 4 4 11.3 6 5 8-0.2 2 4 00.6 1 3 91.4 9 0 8-0.1 9 1 50.5 8 8 01.6 1 5 8-0.1 6 1 60.5 6 5 91.7 4 0 8-0.1 3 4 50.5 4 7 51.8 6 5 8-0.1 1 0 30.5 3 2 21.9 9 0 8-0.0 8 8 90.5 1 9 82.1 1 5 8-0.0 7 0 20.
38、5 0 9 92.2 4 0 8-0.0 5 3 80.5 0 2 12.3 6 5 8-0.0 3 9 60.4 9 6 32.4 9 0 8-0.0 2 7 30.4 9 2 12.6 1 5 8-0.0 1 6 70.4 8 9 42.7 4 0 8-0.0 0 7 50.4 8 7 92.8 6 5 80.0 0 0 40.4 8 7 52.9 9 0 80.0 0 7 10.4 8 8 03.1 1 5 80.0 1 2 80.4 8 9 23.2 4 0 80.0 1 7 70.4 9 1 13.3 6 5 80.0 2 1 80.4 9 3 63.4 9 0 80.0 2 5 3
39、0.4 9 6 63.6 1 5 80.0 2 8 20.4 9 9 93.7 4 0 80.0 3 0 60.5 0 3 63.8 6 5 80.0 3 2 50.5 0 7 53.9 9 0 80.0 3 4 10.5 1 1 74.1 1 5 80.0 3 5 40.5 1 6 04.2 4 0 80.0 3 6 40.5 2 0 54.3 6 5 80.0 3 7 10.5 2 5 14.4 9 0 80.0 3 7 60.5 2 9 84.6 1 5 80.0 3 8 00.5 3 4 54.7 1 1 90.0 3 8 10.5 3 8 24.8 0 7 90.0 3 8 20.5
40、 4 1 84.9 0 4 00.0 3 8 20.5 4 5 55.0 0 0 00.0 3 8 10.5 4 9 2(2)function ydot=vdpoll(t,y);ydot(1)=cos(t)-y(3)./(3+sin(t)+5*y(1).*cos(2*t)/(t+l).2)-y(2);ydot(2)=y(1);ydot(3)=y(2);ydot二ydot ;%建立函数文件t0=0;tf=5;y0=l;0;2 ;t,y=ode4 5(vdpoll,tO,tf,yO);t,yans=01.000002.00000.00011.00030.00012.00000.00011.0005
41、0.00012.00000.00021.00080.00022.00000.00021.00110.00022.00000.00051.00240.00052.00000.00071.00380.00072.00000.00101.00510.00102.00000.00121.00640.00122.00000.00251.01320.00252.00000.00371.01990.00382.00000.00501.02670.00502.00000.00621.03350.00632.00000.01251.06800.01292.00010.01881.10300.01972.0002
42、0.02511.13860.02682.00030.03131.17490.03402.00050.06271.36470.07392.00220.09411.56770.11992.00520.12551.78220.17242.00980.15692.00580.23192.01610.21952.46830.37172.03480.28202.93340.54052.06320.34453.37640.73792.10300.40703.77370.96172.15600.53204.34851.47402.30680.65704.56362.03462.52520.78204.4084
43、2.59802.81550.90703.94363.12283.17441.02113.34073.53963.55531.13522.64293.88183.97961.24931.90924.14184.43811.36341.17894.31764.92151.48840.40724.41635.46841.6134-0.32774.42106.02181.7384-1.02914.33596.56991.8634-1.70764.16477.10201.9884-2.37803.90947.60752.1134-3.05293.57008.07592.2384-3.74253.1454
44、8.49652.3634-4.45232.63358.85862.4884-5.18322.03169.15112.6 1 3 4-5.9 2 8 61.3 3 7 29.3 6 2 62.7 3 8 4-6.6 7 4 70.5 4 9 39.4 8 1 52.8 6 3 4-7.3 9 9 3-0.3 3 0 79.4 9 6 12.9 8 8 4-8.0 7 3 0-1.2 9 8 49.3 9 5 33.1 1 3 4-8.6 5 8 9-2.3 4 5 29.1 6 8 33.2 3 8 4-9.1 1 8 1-3.4 5 7 88.8 0 6 13.3 6 3 4-9.4 1 1
45、2-4.6 1 7 98.3 0 1 83.4 8 8 4-9.5 0 1 5-5.8 0 2 47.6 5 0 83.6 1 3 4-9.3 6 0 4-6.9 8 3 76.8 5 1 63.7 3 8 4-8.9 6 9 6-8.1 3 1 85.9 0 6 23.8 6 3 4-8.3 2 3 5-9.2 1 5 44.8 2 1 03.9 8 8 4-7.4 2 8 1-1 0.2 0 2 63.6 0 6 34.1 1 3 4-6.3 0 0 5-1 1.0 6 3 02.2 7 5 84.2 3 8 4-4.9 6 5 0-1 1.7 6 8 90.8 4 7 14.3 6 3
46、4-3.4 5 1 2-1 2.2 9 6 5-0.6 5 9 14.4 8 8 4-1.7 9 2 1-1 2.6 2 5 7-2.2 1 9 04.6 1 3 4-0.0 2 0 0-1 2.7 4 0 1-3.8 0 6 74.7 3 8 41.8 3 3 4-1 2.6 2 7 4-5.3 9 4 54.8 6 3 43.7 3 8 3-1 2.2 7 9 3-6.9 5 3 64.8 9 7 64.2 6 3 7-1 2.1 4 2 8-7.3 7 0 54.9 3 1 74.7 9 0 2-1 1.9 8 8 2-7.7 8 2 54.9 6 5 95.3 1 7 4-1 1.8
47、1 5 7-8.1 8 8 85.0 0 0 05.8 4 4 5-1 1.6 2 5 2-8.5 8 9 04.function fx=mymin(x)fx=-sin(x)-cos(x.2);%建立函数文件x=fminb nd(mymin,0,pi);-mymin(x)ans=1.5 2 8 25.function fx=mymax(x);fx=-(9*x+4*x.-3-1 2*x/2);%建立函数文件 x,y1 =fminb nd(mymax,0,1.5);-ylans=2.0 0 0 0第七章数值积分与数值微分实验指导1 (1)format long fx=inline(,sin(x).
48、/x*);I,n=quadl(fx,0,2,le-1 0)I=1.6 0 5 4 1 2 9 7 6 7 9 3 5 8 31 9(2)format long fx=inlineC 1./(x-0.3).2+0.0 1)-1./(x-0.9).*2+0.0 4)-6*);I,n=quad(fx,0,1,le-1 0)I=1 1.7 0 0 5 7 5 4 9 6 2 8 9 5 2 2n=9 8 521)glob al ki;ki=0;i=db lquad(fxy,0,1,0,1)ki(2 )f=inline(,ab s(cos(x+y),x,y);I=db lquad(f,0,pi,0,pi
49、)I=6.2 8 3 1 8 8 9 3 7 7 2 3 2 6 33X=0.3:0.2:l.5;F=0.3 8 9 5,0.6 5 9 8,0.9 1 4 7,1.1 6 1 1,1.3 9 7 1,1.6 2 1 2,1.8 3 2 5 ;trapz(X,F)ans=1.3 7 2 9 8 0 0 0 0 0 0 0 0 0 04.p=0:pi/5:2*pi;for n=l:3nDX=diff(sin(p),n)endColumns 1 through 70.5 8 7 7 8 5 2 5 2 2 9 2 4 7 3 0.3 6 3 2 7 1 2 6 4 0 0 2 6 8 0 0.0
50、0 0 0 0 0 0 0 0 0 0 0 0 0 0-0.3 6 3 2 7 1 2 6 4 0 0 2 6 8 0 -0.5 8 7 7 8 5 2 5 2 2 9 2 4 7 3 -0.5 8 7 7 8 5 2 5 2 2 9 2 4 7 3 -0.3 6 3 2 7 1 2 6 4 0 0 2 6 8 1Columns 8 through 1 0-0.0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 6 3 2 7 1 2 6 4 0 0 2 6 8 0 0.5 8 7 7 8 5 2 5 2 2 9 2 4 7 3n=2DX =Columns 1 through