§2复合求积/ Composite Quadrature 高次插值有 Runge现象,故采用分段低次插值 →分段低次合成的 Newton-Cotes复合求积公式 >复合梯形公式:h b-a xk=a+kh(k=0,…,n) 在每个x1x上用梯形公式 88 (sc:3pmP如野yx),k= k-1 e oscllator ∫/么gP=7岛+2)+/b k=1 ∑∫(5k R=∑ h f"(5k=-(b-a /中值定理* 12 h (b-a)f"(95),5∈(a,b)
§2 复合求积 /* Composite Quadrature */ Haven’t we had enough formulae? What’s up now? Oh come on, you don’t seriously consider h=(b−a)/2 acceptable, do you? Why can’t you simply refine the partition if you have to be so picky? Don’t you forget the oscillatory nature of highdegree polynomials! Uh-oh 高次插值有Runge 现象,故采用分段低次插值 分段低次合成的 Newton-Cotes 复合求积公式。 ➢ 复合梯形公式: , x a k h (k 0, ... ,n) n b a h k = + = − = 在每个 [xk−1 , xk ] 上用梯形公式: f x f x k n x x f x dx k k x x k k k k [ ( ) ( )], 1, ... , 2 ( ) 1 1 1 + = − − − − = + + − = 1 1 ( ) 2 ( ) ( ) 2 n k k f a f x f b h = − + b a n k k k f x f x h f x dx 1 1 [ ( ) ( )] 2 ( ) = Tn ( ) ( ), ( , ) 12 ( ) ( ) 12 ( )] 12 [ ] [ 2 1 2 1 3 b a f a b h n f b a h f h R f n k n k k k = − − = − = − − = = /*中值定理*/
8 2 Composite Quadrature >复化 Simpson公式:h=b-a,x4=a+kh(k=0,,m f(x)daf(xx)+4f(x+f(akI k k+1 ∫(x)k=/(+2(x+2(xm)+(=n R[/b-a/h)4 5) 180(2 注:为方便编程,可采用另一记法:令n’=2n为偶数 这时n=b=a=B,x1=a+kM,有 Sn=,Uf(a)+4∑f(x)+2∑f(xk)+f() odd k even k
§2 Composite Quadrature ➢ 复化 Simpson 公式: , x a k h (k 0, ... ,n) n b a h k = + = − = [ ( ) 4 ( ) ( )] 6 ( ) 1 2 1 1 + + + + + k k k x x f x f x f x h f x dx k k xk 2 1 k+ x xk+1 4 4 4 4 4 [ ( ) 4 ( ) 2 ( ) ( )] 6 ( ) 1 0 1 0 1 2 1 − = − = + + + + + n k n k k k b a f a f x f x f b h f x dx = Sn ( ) 180 2 [ ] (4) 4 f b a h R f − = − 注:为方便编程,可采用另一记法:令 n’ = 2n 为偶数, 这时 h x a k h ,有 n b a h k = = + − = , 2 [ ( ) 4 ( ) 2 ( ) ( )] 3 + + + = odd k even k n k k f a f x f x f b h S
8 2 Composite Quadrature >收敛速度与误差估计: 定义若一个积分公式的误差满足hm刚c<a且C≠0, 则称该公式是p阶收敛的。 TnNOCh', s,o(h), cn och) 例:计算z 1+x 运算量基 本相同 解:16/(0)+2∑f(x)+/1)其中x= 3.138988494 S10+2()+2+0其中x 3.141592502
§2 Composite Quadrature ➢ 收敛速度与误差估计: 定义 若一个积分公式的误差满足 且C 0, 则称该公式是 p 阶收敛的。 = → C h R f p h [ ] lim 0 ( ) , ( ) , ( ) 2 4 6 Tn ~ O h Sn ~ O h Cn ~ O h 例:计算 dx + x = 1 0 1 4 2 解: = + + = (0) 2 ( ) (1) 16 1 7 1 8 T f f x f k k 8 k x 其中 k = = 3.138988494 = (0) + 4 ( ) + 2 ( ) + (1) 24 1 odd even 4 S f f x f x f k k 8 k x 其中 k = = 3.141592502 运算量基 本相同
82 Composite Quadrature Q:给定精度,如何取n? 例如:要求|Ⅰ-Tn|<E,如何判断n=? HW: p74 R∫]= (b-a)f"(5 ∑Ir5)川#2 h ∫"(x)x 12 Ja 上例中若要求-r<10,则|R/=h|r()-r(0)=b2<10 →h<0.00244949即:取n=409 通常采取将区间不断对分的方法,即取n=k 上例中2k≥409→k=9时,T5 可用来判断迭代 是否停止 注意到区间再次对分时R2f≈ 1592504R, L
§2 Composite Quadrature Q: 给定精度 ,如何取 n ? 例如:要求 | I −Tn | ,如何判断 n = ? ( ) ( ) 12 [ ] 2 b a f h R f = − − ? = = − n k f k h h 1 2 [ ( ) ] 12 [ ( ) ( )] 12 ( ) 12 2 2 f b f a h f x dx h b a − = − − 上例中若要求 ,则 6 | | 10− I −Tn 6 2 2 10 6 | (1) (0)| 12 | [ ]| − − = h f f h R f n h 0.00244949 即:取 n = 409 通常采取将区间不断对分的方法,即取 n = 2k 上例中2 k 409 k = 9 时,T512 = 3.14159202 注意到区间再次对分时 [ ] 4 1 2 [ ( ) ( )] 12 1 [ ] 2 2 R f h R f f b f a n n − − 4 2 1 − − n n I T I T ( ) 3 1 T2n T2n Tn I − − 可用来判断迭代 是否停止。 HW: p.174 #2
8 2 Composite Quadrature Lab 13. Composite Trapezoidal rule Use the Composite Trapezoidal rule with a given n>0 to approximate a given integral f(x)dx You are supposed to write a function double Ctr( int n, double a, double b, double("Do) to approximate the integral from a to b of the function f using the trapezoidal rule on n equal-length subintervals. Input There is no input file. Instead, you must hand in your function in a*.h file. The rule of naming the *. h file is the same as that of naming the *. c or cpp files. Output For each test case, you are supposed to return the approximation of the integral
§2 Composite Quadrature Lab 13. Composite Trapezoidal Rule Use the Composite Trapezoidal rule with a given n > 0 to approximate a given integral . You are supposed to write a function double CTR ( int n, double a, double b, double (*f)( ) ) to approximate the integral from a to b of the function f using the trapezoidal rule on n equal-length subintervals. Input There is no input file. Instead, you must hand in your function in a *.h file. The rule of naming the *.h file is the same as that of naming the *.c or *.cpp files. Output For each test case, you are supposed to return the approximation of the integral. b a f ( x) dx