数值分析上机题(matlab版).doc
《数值分析上机题(matlab版).doc》由会员分享,可在线阅读,更多相关《数值分析上机题(matlab版).doc(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、数值剖析上机讲演姓名:许泽玮学号:180422第一章一、标题精确值为。1) 体例按从年夜到小的次序,盘算SN的MATLAB次序。2) 体例按从小到年夜的次序,盘算SN的MATLAB次序。3) 按两种次序分不盘算,并指出无效位数。体例次序时用单精度4) 经过本次上机题,你清楚了什么?二、MATLAB次序clearN=input(PleaseInputanN(N1):);AccurateValue=single(0-1/(N+1)-1/N+3/2)/2);SN1=single(0);fora=2:N;SN1=SN1+1/(a2-1);endSN2=single(0);fora=2:N;SN2=SN
2、2+1/(N-a+2)2-1);endfprintf(N=%d)n,N);disp()fprintf(Theexactvalueoftheinputis%fn,AccurateValue);fprintf(fromlargetosmall%fn,SN1);fprintf(fromsmalltolarge%fn,SN2);disp()三、求解后果PleaseInputanN(N1):102ThevalueofSnusingdifferentalgorithms(N=100)AccurateCalculation0.740049fromlargetosmall0.740049fromsmallto
3、large0.740050PleaseInputanN(N1):104ThevalueofSnusingdifferentalgorithms(N=10000)AccurateCalculation0.749900fromlargetosmall0.749852fromsmalltolarge0.749900PleaseInputanN(N1):106ThevalueofSnusingdifferentalgorithms(N=1000000)AccurateCalculation0.749999fromlargetosmall0.749852fromsmalltolarge0.749999四
4、、后果剖析无效位数n次序102104106从年夜到小633从小到年夜566从上述后果可知,差别的算法对偏差的传达是有妨碍的,在盘算时选一种好的算法能够使后果更为精确。从以上的后果能够看到从年夜到小的次序招致年夜数吃小数的景象,轻易发生较年夜的偏差,求跟运算从小数到年夜数算所失掉的后果才比拟精确。第二章一、标题1给定初值及允许偏差,体例牛顿法解方程f(x)=0的MATLAB次序。2给定方程,易知其有三个根a) 由牛顿办法的部分收敛性可知存在事先,Newton迭代序列收敛于根x2*。试断定尽能够年夜的。b)试取假定干初始值,不雅看事先Newton序列的收敛性以及收敛于哪一个根。3经过本上机题,你清
5、楚了什么?二、MATLAB次序文件search.m%寻寻最年夜的delta值%clear%flag=1;k=1;x0=0;whileflag=1delta=k*10-6;x0=delta;k=k+1;m=0;flag1=1;whileflag1=1&m=103x1=x0-fx(x0)/dfx(x0);ifabs(x1-x0)=10-6flag=0;endendfprintf(Themaximundeltais%fn,delta);文件fx.m%界说函数f(x)functionFx=fx(x)Fx=x3/3-x;文件dfx.m%界说导函数df(x)functionFx=dfx(x)Fx=x2-1
6、;文件Newton.m%Newton法求方程的根%clear%ef=10-6;%给定允许偏差10-6k=0;x0=input(PleaseinputinitialvalueXo:);disp(kXk);fprintf(0%fn,x0);flag=1;whileflag=1&k=103x1=x0-fx(x0)/dfx(x0);ifabs(x1-x0)efflag=0;endk=k+1;x0=x1;fprintf(%d%fn,k,x0);end三、求解后果后果为:Themaximumdeltais0.774597即得最年夜的为0.774597,Newton迭代序列收敛于根=0的最年夜区间为-0.7
7、74597,0.774597。在区间上各输入假定干个数,盘算后果如下:区间上取-1000,-100,-50,-30,-10,-8,-7,-5,-3,-1.5PleaseinputinitialvalueXo:-3kXk0-3.0000001-2.2500002-1.8692313-1.7458104-1.7322125-1.7320516-1.732051PleaseinputinitialvalueXo:-1.5kXk0-1.5000001-1.8000002-1.7357143-1.7320624-1.7320515-1.732051PleaseinputinitialvalueXo:-8
8、kXk0-8.0000001-5.4179892-3.7393793-2.6849344-2.0782465-1.8029286-1.7360237-1.7320648-1.7320519-1.732051PleaseinputinitialvalueXo:-7kXk0-7.0000001-4.7638892-3.3223183-2.4355334-1.9529155-1.7646306-1.7329317-1.7320518-1.732051PleaseinputinitialvalueXo:-5kXk0-5.0000001-3.4722222-2.5241803-1.9960684-1.7
9、766185-1.7336746-1.7320537-1.7320518-1.732051后果表现,以上初值迭代序列均收敛于-1.732051,即根。在区间即区间-1,-0.774597上取-0.774598,-0.8,-0.85,-0.9,-0.99,盘算后果如下:PleaseinputinitialvalueXo:-0.774598kXk0-0.77459810.7746052-0.77464530.7748844-0.77632450.7850496-0.84064171.35018781.99383091.775963101.733628111.732053121.732051131.
10、732051PleaseinputinitialvalueXo:-0.8kXk0-0.80000010.9481482-5.6253703-3.8726254-2.7661975-2.1213676-1.8182927-1.7378228-1.7320799-1.73205110-1.732051PleaseinputinitialvalueXo:0.85kXk00.8500001-1.4753752-1.8194443-1.7379694-1.7320815-1.7320516-1.732051PleaseinputinitialvalueXo:-0.9kXk0-0.90000012.557
11、89522.01291531.78166241.73404951.73205461.73205171.732051PleaseinputinitialvalueXo:-0.99kXk0-0.990000132.505829221.691081314.49152149.70723856.54090664.46496673.13384082.32607591.902303101.752478111.732403121.732051131.732051盘算后果表现,迭代序列部分收敛于-1.732051,即根,部分收敛于1.730251,即根。在区间即区间-0.774597,0.774597上,由se
12、arch.m的运转进程阐明,在全部区间上均收敛于0,即根。PleaseinputinitialvalueXo:0.774598kXk00.7745981-0.77460520.7746453-0.77488440.7763245-0.78504960.8406417-1.3501878-1.9938309-1.77596310-1.73362811-1.73205312-1.73205113-1.732051PleaseinputinitialvalueXo:0.8kXk00.8000001-0.94814825.62537033.87262542.76619752.12136761.8182
13、9271.73782281.73207991.732051101.732051PleaseinputinitialvalueXo:0.85kXk00.8500001-1.4753752-1.8194443-1.7379694-1.7320815-1.7320516-1.732051PleaseinputinitialvalueXo:0.9kXk00.9000001-2.5578952-2.0129153-1.7816624-1.7340495-1.7320546-1.7320517-1.732051PleaseinputinitialvalueXo:0.99kXk00.9900001-32.5
14、058292-21.6910813-14.4915214-9.7072385-6.5409066-4.4649667-3.1338408-2.3260759-1.90230310-1.75247811-1.73240312-1.73205113-1.732051在区间即区间0.774597,1上取0.774598,0.8,0.85,0.9,0.99,盘算后果如下:盘算后果表现,迭代序列部分收敛于-1.732051,即根,部分收敛于1.730251,即根。PleaseinputinitialvalueXo:4kXk04.00000012.84444422.16372431.83428141.74
15、000751.73210561.73205171.732051PleaseinputinitialvalueXo:3kXk03.00000012.25000021.86923131.74581041.73221251.73205161.732051PleaseinputinitialvalueXo:1.5kXk01.50000011.80000021.73571431.73206241.73205151.732051区间上取100,60,20,10,7,6,4,3,1.5,盘算后果如下:后果表现,以上初值迭代序列均收敛于1.732051,即根。综上所述:(-,-1)区间收敛于-1.73205,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数值 分析 上机 matlab
限制150内