资源描述:
《数值分析新课件教学作者教学专用 NA07b.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、§2复合求积/*CompositeQuadrature*/Haven’twehadenoughformulae?What’supnow?Ohcomeon,youdon’tseriouslyconsiderh=(ba)/2acceptable,doyou?Whycan’tyousimplyrefinethepartitionifyouhavetobesopicky?Don’tyouforgettheoscillatorynatureofhigh-degreepolynomials!Uh-oh高次插值有Runge现象,故采用分段低次插值分段低次合成的Newton-Cotes复合求积公式。
2、复合梯形公式:在每个上用梯形公式:=Tn/*中值定理*/§2CompositeQuadrature复化Simpson公式:44444=Sn注:为方便编程,可采用另一记法:令n’=2n为偶数,这时,有§2CompositeQuadrature收敛速度与误差估计:定义若一个积分公式的误差满足且C0,则称该公式是p阶收敛的。~~~例:计算解:其中=3.138988494其中=3.141592502运算量基本相同例:用复化梯形公式、复化Simpson公式和复化Cotes公式计算要使精度要求达到问N各取多少?HW:p.2731,3,4,5,6§2CompositeQuadratureQ:给
3、定精度,如何取n?例如:要求,如何判断n=??上例中若要求,则即:取n=409通常采取将区间不断对分的方法,即取n=2k上例中2k409k=9时,T512=3.14159202S4=3.141592502注意到区间再次对分时可用来判断迭代是否停止。§2CompositeQuadratureLab13.CompositeTrapezoidalRuleUsetheCompositeTrapezoidalrulewithagivenn>0toapproximateagivenintegral.YouaresupposedtowriteafunctiondoubleCTR(intn,dou
4、blea,doubleb,double(*f)())toapproximatetheintegralfromatobofthefunctionfusingthetrapezoidalruleonnequal-lengthsubintervals.InputThereisnoinputfile.Instead,youmusthandinyourfunctionina*.hfile.Theruleofnamingthe*.hfileisthesameasthatofnamingthe*.cor*.cppfiles.OutputForeachtestcase,youaresupposedtor
5、eturntheapproximationoftheintegral.§2CompositeQuadratureSampleJudgeProgram#include#include#include"98115001_13.h"doublef1(doublex){return(1.0/(1.0+sin(x)*sin(x)));}doublef2(doublex){return(x*log(x));}voidmain(){FILE*outfile=fopen("out.txt","w");intn;doublea,b;a=0.0;b=1.0;n=10;fpr
6、intf(outfile,"%lf",CTR(n,a,b,f1));a=1.0;b=2.0;n=4;fprintf(outfile,"%lf",CTR(n,a,b,f2));fclose(outfile);}SampleOutput0.8090930.639900§3龙贝格积分/*RombergIntegration*/例:计算已知对于=106须将区间对分9次,得到T512=3.14159202由来计算I效果是否好些?考察=3.141592502=S4一般有:Romberg序列Romberg算法:<?<?<?………………T1=)0(0TT8=)3(0TT4=)2
7、(0TT2=)1(0TS1=)0(1TR1=)0(3TS2=)1(1TC1=)0(2TC2=)1(2TS4=)2(1T§3RombergIntegrationLab14.RombergIntegrationUseRombergintegrationtoapproximateagivenintegral.YouaresupposedtowriteafunctiondoubleRomberg(doublea,doubleb