Homework4.docx
- 文档编号:28333284
- 上传时间:2023-07-10
- 格式:DOCX
- 页数:14
- 大小:53.63KB
Homework4.docx
《Homework4.docx》由会员分享,可在线阅读,更多相关《Homework4.docx(14页珍藏版)》请在冰豆网上搜索。
Homework4
Homework4
Acanintheshapeofarightcircularcylinderistobeconstructedtocontain1000cm3.Thecirculartopandbottomofthecanmusthavearadiusof0.25cmmorethantheradiusofthecansothattheexcesscanbeusedtoformasealwiththeside.Thesheetofmaterialbeingformedintothesideofcanmustalsobe0.25cmlongerthanthecircumferenceofthecansothatasealcanbeformed.Find,towithin10-4,theminimalamountofmaterialneededtoconstructthecan.
Solution:
Theareaofthiscanisaboutthebelowformula
S=
Andthevolumecanbewriteas
V=
h
AndV=1000,wecancombinethistwoformulas
S(r)=
TofindtheminimumofS,wemustfindthezeropointofderivative.
First,weneedtogetknowaboutthisfunction,sowecanuseMATLABtolookforitsgraph.
Wecanseefromthisgraphthatthisfunctiondecreaseatfirstbutincreasesmonotonicallyfrom0to100.Sowhenthisderivativeequals0,thevalueoffunctionisthesmallest.Andforseekingmoreaccurately,wechangethefootstep.
Wecanseethatthesolutionisbetween5and6.
Thus,wecanstartourprogrambyusingmethodsasfollows:
Beforeallprograms,wefirstdefinethisfunctionanditsderivate.
functiony=f(x)
y=4*pi*(x+0.25)-2000/x^2-500/(pi*x^3);
end
functions=df(x)
s=4*pi+6000/x^3+2000/(pi*x^4);
end
Andtheareaofmaterial
functiony=s(x)
y=2*pi*(x+0.25)^2+2000/x+250/(pi*x^2);
end
1BisectionMethod
functionp=zqh2f(a,b,TOL,N)
i=1;
FA=f(a);
whilei<=N
p=a+(b-a)/2;
FP=f(p);
ifFP==0||(b-a)/2 fprintf('Theprocedurewassuccessfulafter%diterations',i) return end i=i+1; ifsign(FA)*sign(FP)>0 a=p; FA=FP; else b=p; end end fprintf('Methodfailedafter%diterations.',N) end Sowecangettheansweronthecommandwindow >>x=zqh2f(5,6,10^-4,50) Theprocedurewassuccessfulafter14iterations x= 5.3638 >>s(x) ans= 573.6490 2Newton’sMethod functionp=new(p0,TOL,N) i=1; whilei<=N p=p0-f(p0)/df(p0); ifabs(p-p0) fprintf('Theprocedurewassuccessfulafter%diterations',i) return end i=i+1; p0=p; end fprintf('Methodsucceededafter%diterations.',i) end functiony=f(x) y=4*pi*(x+0.25)-2000/x^2-500/(pi*x^3); end Sowecangettheansweronthecommandwindow >>x=new(5.5,10^-4,50) Theprocedurewassuccessfulafter6iterations x= 5.3639 >>s(x) ans= 573.6490 3SecantMethod functionp=zqhsec(p0,p1,TOL,N) i=2; q0=f(p0); q1=f(p1); whilei<=N p=p1-q1*(p1-p0)/(q1-q0); ifabs(p-p1) fprintf('Theprocedurewassuccessfulafter%diterations',i-1) return end i=i+1; p0=p1; q0=q1; p1=p; q1=f(p); end fprintf('Methodfailedafter%diterations.',N) end >>x=zqhsec(5,6,10^-4,50) Theprocedurewassuccessfulafter4iterations x= 5.3639 >>s(x) ans= 573.6490 4MethodofFalsePosition functionp=zqhFP(p0,p1,TOL,N) i=2; q0=f(p0); q1=f(p1); whilei<=N p=p1-q1*(p1-p0)/(q1-q0); ifabs(p-p1) fprintf('Themethodsucceededafter%diterations',i-1) return end i=i+1; q=f(p); ifq*q1<0 p0=p1; q0=q1; end p1=p; q1=q; end fprintf('Methodfailedafter%diterations',N) end >>x=zqhFP(5,6,10^-4,50) Themethodsucceededafter5iterations x= 5.3639 >>s(x) ans= 573.6490 5Muller’sMethod functionp=muller(p0,p1,p2,TOL,N) h1=p1-p0; h2=p2-p1; o1=(f(p1)-f(p0))/h1; o2=(f(p2)-f(p1))/h2; d=(o2-o1)/(h2+h1); i=3; whilei<=N b=o2+h2*d; D=(b^2-4*f(p2)*d)^.5; ifabs(b-D) E=b+D; else E=b-D; end h=-2*f(p2)/E; p=p2+h; ifabs(h) fprintf('Themethodsucceededafter%diterations',i-2) return end p0=p1; p1=p2; p2=p; h1=p1-p0; h2=p2-p1; o1=(f(p1)-f(p0))/h1; o2=(f(p2)-f(p1))/h2; d=(o2-o1)/(h2+h1); i=i+1; end fprintf('Methodfailedafter%diterations',N) end >>x=muller(5,5.5,6,10^-4,50) Themethodsucceededafter3iterations x= 5.3639 >>s(x) ans= 573.6490 Theresultcanbesummarizedasfollows: Method Bisection Newton’s Secant MethodofFalsePosition Muller Initialinput 56 5.5 56 56 55.56 Numberofiterations 14 6 4 5 3 r 5.3638 5.3639 5.3639 5.3639 5.3639 S 573.6490 573.6490 573.6490 573.6490 573.6490 Wecanseethatallmethodsgettherightanswer,however,it’sbecause Ihavegavesomeaccurateinitialinput,butinfact,itseemsimpossibletoseekfortheaccurateinitialguessabouttherealproblems,sowecanchangetheinitialguess. Method Bisection Newton’s Secant MethodofFalsePosition Muller Initialinput 1100 1 1100 1100 150100 Numberofiterations 20 14 failed failed 44 r 5.3639 5.3639 failed failed 5.3639 S 573.6490 573.6490 failed failed 573.6490 Method Bisection Newton’s Secant MethodofFalsePosition Muller Initialinput 10100 10 10100 10100 1050100 Numberofiterations failed 20 37 58 11 r failed 5.5638 5.5639 5.3643 5.3639 S failed 573.6490 573.6490 573.6490 573.6490 Method Bisection Newton’s Secant MethodofFalsePosition Muller Initialinput 50 50 50100 50100 175100 Numberofiterations failed failed failed failed 23 r failed failed failed failed 5.3639 S failed failed failed failed 573.6490 SowecanconcludethatMuller’smethodperformedwellcomparingwithothermethods. Asequenceconvergeswithrateif =C,forsomefinitenonzeroconstantC. Andwecantakethelogarithmofthis, ln -r =lnC ln -r =lnC Combinethistwoformulas,wecangettheC C= /ln . Thus,nowwecancalculatetherateofconvergenceofthesemethods. Anexample: [m,n]=size(t); fori=1: n-1 E(i)=norm(t(i)-t(n),inf); end forj=1: n-3 ratew(j)=log(E(j+2)/E(j+1))/log(E(j+1)/E(j)); end [r,t]=new(5,TOL,ITER_max); Method Bisection Newton’s Secant MethodofFalsePosition Muller 1 12.9557727 0.50290755 Inf Inf Inf 2 -0.6569398 1.37796699 -6.902630032 -6.904234927 -3.749273 3 -0.6153895 1.19964438 -0.233047526 -0.233139472 -0.354789 4 1.60420236 1.07575008 2.735474494 0.737597777 1.1663 5 0.188049 1.02830821 -0.996504932 0.820872915 1.3336679 6 6.39329123 1.03270313 -0.003496286 0.871196322 0.5711671 7 -0.5183499 1.12430688 293.0388991 0.904640953 2.6134839 8 -1.2678488 -0.982197711 0.928136772 1.4523304 9 1.63579036 -0.017833374 0.945223662 2.210862 10 -0.564575 55.41324306 0.957928826 1.7028477 11 -1 -0.977759576 0.967514815 12 -0.022314426 0.974819451 13 44.25184599 0.980425851 14 -0.969958453 0.984754232 15 -0.030232323 0.988114905 16 32.55685727 0.990740836 17 -0.957104149 0.992808853 18 -0.043432001 0.994454219 19 22.5702687 0.995781083 20 -0.933540696 0.996870232 21 -0.068227894 0.997784967 22 14.30701432 0.998575634 23 -0.883677468 0.999283147 24 -0.123955278 0.999941779 25 7.904257453 1.000581397 26 -0.753554402 1.001229315 27 -0.29973831 1.00191189 28 3.564601712 1.002655975 29 -0.307098009 1.003490354 30 -2.018977475 1.004447245 31 1.622817733 1.005564026 32 1.065575756 1.006885325 33 1.833419663 1.00846569 34 1.593124794 1.010373148 35 1.616710475 1.012694116 36 1.015540397 37 1.01905945 38 1.023449961 39 1.028986286 40 1.036058386 41 1.045240146 42 1.057412959 43 1.074005077 44 1.097497392 45 1.132622697 46 1.189708459 47 1.29662631 48 1.566476855 Thus,wecanapproximatethatBisectionmethodislinearlyconvergent, Secant,FalsePositionmethodandtheMuller’smethodaresuperlinearconvergent.However,Newton’smethodshouldquadraticallycoverage,butit’snotforthistime,maybesomefaulthasexistedinmycodes.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Homework4
