11 Numerical Differentiation and Integration 11 3 Better
11. Numerical Differentiation and Integration 11. 3 Better Numerical Integration, 11. 4 Gaussian Quadrature, 11. 5 MATLAB’s Methods Natural Language Processing Lab Dept. of Computer Science and Engineering, Korea Univertity CHOI Won-Jong (wjchoi@nlp. korea. ac. kr) Woo Yeon-Moon(wooym@nlp. korea. ac. kr) Kang Nam-Hee(nhkang@nlp. korea. ac. kr)
Contents l l l 11. 3 BETTER NUMERICAL INTEGRATION § 11. 3. 1 Composite Trapezoid Rule § 11. 3. 2 Composite Simpson’s Rule § 11. 3. 3 Extrapolation Methods for Quadrature 11. 4 GAUSSIAN QUADRATURE § 11. 4. 1 Gaussian Quadrature on [-1, 1] § 11. 4. 2 Gaussian Quadrature on [a, b] 11. 5 MATLAB’s Methods 2
11. 3. 1 Composite Trapezoid Rule 11. 3. 2 Composite Simpson’s Rule CHOI Won. Jong (wjchoi@nlp. korea. ac. kr) 3
11. 3. 1 Composite Trapezoid Rule CHOI Won. Jong (wjchoi@nlp. korea. ac. kr) 4
11. 3 BETTER NUMERICAL INTEGRATION l Composite integration(복합적분) : Applying one of the lower order methods presented in the previous section repeatedly on several sub intervals. 5
11. 3. 1 Composite Trapezoid Rule l. If we divide the interval of integration, [a, b], into two or more subintervals and use the trapezoid rule on each subintervals, we obtain the composite trapezoid rule. 6
11. 3. 1 Composite Trapezoid Rule l. If we divide the interval into n subintervals, we get l. MATLAB CODE 7
11. 3. 1 Composite Trapezoid Rule l. Example 11. 9 n=1 n=2 n=4 n=20 n=3 n=100 8
11. 3. 1 Composite Trapezoid Rule l. Example 11. 9 9
11. 3. 2 Composite Simpson’s Rule CHOI Won. Jong (wjchoi@nlp. korea. ac. kr) 10
11. 3. 2 Composite Simpson’s Rule l. Example 11. 10 n=2 n=10 n=4 n=20 11
11. 3. 2 Composite Simpson’s Rule l Applying the same idea of subdivision of intervals to Simpson’s rule and requiring that n be even gives the composite Simpson rule. l n이 even일 경우 Simpson’s 1/3 법칙 : 2차다항식 l n이 odd일 경우 Simpson’s 3/8법칙 : 3차 다항식(교재에서 다루지 않는 부분) l [a, b]를 two subintervals [a, x 2], [x 2, b]로 나눈다면, 12
11. 3. 2 Composite Simpson’s Rule l. In general, for n even, we have h=(b-a)/n, and Simpson’s rule is 13
11. 3. 2 Composite Simpson’s Rule l. Example 11. 10 n=2 n=10 n=4 n=20 14
11. 3. 2 Composite Simpson’s Rule l. Example 11. 11 Length of Elliptical Orbit 15
11. 3. 2 Composite Simpson’s Rule l. Example ldays lr 11. 11 Length of Elliptical Orbit 0 10 20 30 40 50 60 70 80 90 [0. 00 1. 07 1. 75 2. 27 2. 72 3. 14 3. 56 4. 01 4. 53 5. 22 100 = 6. 28] l. Using Composite Simpson’s Rule and the length between day 0 and 10 (n=20) is 0. 88952. (Trapezoid=0. 889567, Text=0. 8556) l. Using Composite Simpson’s Rule and the length between day 60 and 70 (n=20) is 0. 382108. (Trapezoid=0. 382109, Text=0. 3702) l. The former is 2. 3279 times faster than the latter. 16
11. 3. 3 Extrapolation Methods for Quadrature Woo Yeon-Moon(wooym@nlp. korea. ac. kr) 17
Richardson Expolation l Truncation error(절단 오차) • 사다리꼴 simpson 18
Richardson Expolation l To obtain an estimate that is more accurate • using two or more subintervals (h를 줄임) - 그러나, 세부구간의 수가 일정한 범위를 넘어서면 round-off error가 커지게 된다. 계 산 오 차 trapezoid simpson 세부 구간의 수 l Richardson Extrapolation 간격이 다른 2개의 식을 구한 결과를 대수적으로 정리함으로써 보다 정확한 값을 산출 19
Richardson Extrapolation l Richardson Extrapolation using the trapezoid rule (if h_2 = ½ h_1) Simpson rules 20
Example 11. 12 Integral of 1/x § start with one subinterval (h=1) § two subintervals (h=1/2) § to apply Richardson extrapolation § exact value of the integral is ln(2)=0. 693147. . 21
Example 11. 12 Integral of 1/x l Form a table of the approximations Ⅰ h=1/2 l Ⅱ 0. 7500 0. 7083 0. 6944 ≠ 0. 693147 l 22
Romberg Integration l Approximate an Error l truncation rules : l Richardson extrapolation : l continued ( using simpson rules) 23
Romberg Integration l l l Improving the result by Richardson extrapolation 1 st 2 nd 3 rd Romberg integration : iterative procedure using Richardson extrapolation k means the improving level(= ) 24
Example 11. 12 Integral of 1/x using Romberg Integration l Trapezoid rule § For k=0, I_0 = 0. 75 § For k=1, I_1 = 0. 7083 § For k=2, I_2 = 0. 6941 l To apply Richardson extrapolation Ⅰ h=1 0. 7500 h=1/2 0. 7083 h=1/4 0. 6970 h=1/8 0. 6941 Ⅱ 0. 6944 0. 6933 0. 6943 25
Example 11. 12 Integral of 1/x using Romberg Integration lsecond level of extrapolation Ⅰ h=1 0. 7500 h=1/2 0. 7083 h=1/4 0. 6970 Ⅱ Ⅲ 0. 6944 0. 6933 [16(0. 6933)-0. 6944]/15 26
Example 11. 12 Integral of 1/x using Romberg Integration l five levels of extrapolation to find values for 0. 7 500 0. 6 944 0. 6 932 0. 6 931 0. 7 083 0. 6 931 0. 6 970 0. 6 932 0. 6 931 0. 6 941 0. 6 931 0. 6 934 0. 6 931 0. 6 932 27
Matlab function for Romberg Integration 28
11. 4 Gaussian Quadrature Kang Nam-Hee (nhkang@nlp. korea. ac. kr) 29
11. 4. 1 Gaussian Quadrature on [-1, 1] q Gaussian Quadrature Formular § Get the definite integration of f(x) on [-1, 1] using linear combinations of coefficient ck and evaluated function value f(xk) at the point xk § Appropriate values of the points xk and ck depend on the choice of n § By choosing the quadrature point x 1 , … xn as the n zeros of the nth-degree Gauss-Legendre polynomial, and by using the appropriate coefficients, the integration formular is exact for polynomials of degree up to 2 n-1 30
11. 4. 1 Gaussian Quadrature on [-1, 1] q Gaussian Quadrature Formular (cont. ) § n=2 § n=3 31
11. 4. 1 Gaussian Quadrature on [-1, 1] q Example 11. 13 integral of exp(-x 2) Using G. Q § n Xi ci 2 3 ± 0. 557753 0 ± 0. 77459 ± 0. 861136 ± 0. 339981 1 8/9 5/9 0. 34785 0. 652145 4 Table 11. 2 parameters of Gaussian quadrature 32
11. 4. 1 Gaussian Quadrature on [-1, 1] q Gaussian-Legendre Polynomials 33
11. 4. 2 Gaussian Quadrature on [a, b] q Extends Gaussian Quadrature for f(t) on [a, b] by Transformation f(t) on [a, b] to f(x) on [-1, 1] § For the given integral § change interval of t by using next formular § so the interval 34
11. 4. 2 Gaussian Quadrature on [a, b] q Extends Gaussian Quadrature for f(t) on [a, b] (cont. ) § f(t) rewrite for variable x remark the factor (b-a)/2 (∵td convert to dx) § Apply f(x) to the integral 35
11. 4. 2 Gaussian Quadrature on [a, b] q Example 11. 14 integral of exp(-x 2) on [0, 2] using G. Q with n = 2 § Consider again the integral § Transform f(t) on [0, 2] to f(x) on [-1, 1] using next formular 36
11. 4. 2 Gaussian Quadrature on [a, b] q Example 11. 14 (cont) § So we can get § Apply Gaussian Quadrature to the integral with n = 2 37
11. 4. 2 Gaussian Quadrature on [a, b] q Matlab function for Gaussian Quadrature 38
11. 5 MATLAB’s Methods Woo Yeon-Moon(wooym@nlp. korea. ac. kr) 39
11. 5 MATLAB’s Methods l l l p=polyfit(x, y, n) – find the coefficients of the polynomial of degree n polyder(p) - calculates the derivative of polynomials diff(x) - x = [1 2 3 4 5]; y = diff(x) y = 1 1 traps(x, y) Q=quad(‘f’, xmin, xmax) (simpson rules) Q=quad 8(‘f’, xmin, xmax) (Newton-Cotes eightpanel rule) 40
- Slides: 40