数值分析上机题(matlab版)(东南大学)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

数值分析上机报告第一章一、题目精确值为)11123(21NN。1)编制按从大到小的顺序11131121222NSN,计算SN的通用程序。2)编制按从小到大的顺序1211)1(111222NNSN,计算SN的通用程序。3)按两种顺序分别计算64210,10,10SSS,并指出有效位数。(编制程序时用单精度)4)通过本次上机题,你明白了什么?二、通用程序clearN=input('PleaseInputanN(N1):');AccurateValue=single((0-1/(N+1)-1/N+3/2)/2);Sn1=single(0);fora=2:N;Sn1=Sn1+1/(a^2-1);endSn2=single(0);fora=2:N;Sn2=Sn2+1/((N-a+2)^2-1);endfprintf('ThevalueofSnusingdifferentalgorithms(N=%d)\n',N);disp('____________________________________________________')fprintf('AccurateCalculation%f\n',AccurateValue);fprintf('Caculatefromlargetosmall%f\n',Sn1);fprintf('Caculatefromsmalltolarge%f\n',Sn2);disp('____________________________________________________')三、求解结果四、结果分析有效位数n顺序100100001000000从大到小633从小到大566可以得出,算法对误差的传播又一定的影响,在计算时选一种好的算法可以使结果更为精确。从以上的结果可以看到从大到小的顺序导致大数吃小数的现象,容易产生较大的误差,求和运算从小数到大数算所得到的结果才比较准确。PleaseInputanN(N1):10^2ThevalueofSnusingdifferentalgorithms(N=100)____________________________________________________AccurateCalculation0.740049Caculatefromlargetosmall0.740049Caculatefromsmalltolarge0.740050____________________________________________________PleaseInputanN(N1):10^4ThevalueofSnusingdifferentalgorithms(N=10000)____________________________________________________AccurateCalculation0.749900Caculatefromlargetosmall0.749852Caculatefromsmalltolarge0.749900____________________________________________________PleaseInputanN(N1):10^6ThevalueofSnusingdifferentalgorithms(N=1000000)____________________________________________________AccurateCalculation0.749999Caculatefromlargetosmall0.749852Caculatefromsmalltolarge0.749999____________________________________________________第二章一、题目(1)给定初值0x及容许误差,编制牛顿法解方程f(x)=0的通用程序。(2)给定方程03)(3xxxf,易知其有三个根3,0,3321xxxa)由牛顿方法的局部收敛性可知存在,0当),(0x时,Newton迭代序列收敛于根x2*。试确定尽可能大的。b)试取若干初始值,观察当),1(),1,(),,(),,1(),1,(0x时Newton序列的收敛性以及收敛于哪一个根。(3)通过本上机题,你明白了什么?二、通用程序三、求解结果文件fx.m%%定义函数f(x)functionFx=fx(x)Fx=x^3/3-x;文件dfx.m%%定义导函数df(x)functionFx=dfx(x)Fx=x^2-1;文件Newton.m%%Newton法求方程的根%%clear%%ef=10^-6;%给定容许误差10^-6k=0;x0=input('PleaseinputinitialvalueXo:');disp('kXk');fprintf('0%f\n',x0);flag=1;whileflag==1&&k=10^3x1=x0-fx(x0)/dfx(x0);ifabs(x1-x0)efflag=0;endk=k+1;x0=x1;fprintf('%d%f\n',k,x0);end文件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=10^3x1=x0-fx(x0)/dfx(x0);ifabs(x1-x0)10^-6flag1=0;endm=m+1;x0=x1;endifflag1==1||abs(x0)=10^-6flag=0;endendfprintf('Themaximundeltais%f\n',delta);1.运行search.m文件结果为:Themaximumdeltais0.774597即得最大的δ为0.774597,Newton迭代序列收敛于根*2x=0的最大区间为(-0.774597,0.774597)。2.运行Newton.m文件在区间(,1),(1,),(,),(,1),(1,)上各输入若干个数,计算结果如下:区间(,1)上取-1000,-100,-50,-30,-10,-8,-7,-5,-3,-1.5PleaseinputinitialvalueXo:-10000kXk0-10000.0000001-6666.6667332-4444.4445893-2962.9632094-1975.3090315-1316.8730256-877.9158567-585.2779978-390.1864709-260.12602210-173.41991111-115.61711812-77.08384513-51.39788014-34.27822915-22.87161816-15.27694917-10.22845918-6.88478019-4.68877220-3.27480721-2.40771422-1.93975023-1.76125924-1.73276225-1.73205126-1.732051PleaseinputinitialvalueXo:-100kXk0-100.0000001-66.6733342-44.4588913-29.6542634-19.7920165-13.2284476-8.8696517-5.9892318-4.1073249-2.91075510-2.20018911-1.84868712-1.74223513-1.73213914-1.73205115-1.732051PleaseinputinitialvalueXo:-50kXk0-50.0000001-33.3466722-22.2511253-14.8641054-9.9544585-6.7039606-4.5710137-3.2005208-2.3645159-1.91970310-1.75640511-1.73254812-1.73205113-1.732051PleaseinputinitialvalueXo:-30kXk0-30.0000001-20.0222472-13.3815443-8.9711294-6.0560005-4.1505036-2.9375247-2.2150468-1.8547149-1.74323610-1.73215811-1.73205112-1.732051PleaseinputinitialvalueXo:-10kXk0-10.0000001-6.7340072-4.5905703-3.2128404-2.3716535-1.9229816-1.7571757-1.7325808-1.7320519-1.732051结果显示,以上初值迭代序列均收敛于-1.732051,即根*1x。PleaseinputinitialvalueXo:-8kXk0-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.7766185-1.7336746-1.7320537-1.7320518-1.732051PleaseinputinitialvalueXo:-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.732051在区间(1,)即区间(-1,-0.774597)上取-0.774598,-0.8,-0.85,-0.9,-0.99,计算结果如下:计算结果显示,迭代序列局部收敛于-1.732051,即根*1x,局部收敛于1.730251,即根*3x。PleaseinputinitialvalueXo:-0.774598kXk0-0.77459810.7746052-0.77464530.7748844-0.77632450.7850496-0.84064171.35018781.99383091.775963101.733628111.732053121.732051131.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.55789522.01291531.78166241.73404951.73205461.73205171.732051Pleasein

1 / 22
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功