11. numerical differentiation and integration 11.3 better numerical integration, 11.4 gaussian...

40
11. Numerical Differentiation and Int egration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB’s Metho ds Natural Language Processing Lab Dept. of Computer Science and Engineering, Korea Univertity CHOI Won-Jong ([email protected] ) Woo Yeon-Moon([email protected]) Kang Nam-Hee([email protected])

Upload: alan-booth

Post on 18-Dec-2015

251 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

11. Numerical Differentiation and Integration11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB’s Methods

Natural Language Processing LabDept. of Computer Science and Engineering, Korea Univertity

CHOI Won-Jong ([email protected])Woo Yeon-Moon([email protected])Kang Nam-Hee([email protected])

Page 2: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

2

Contents

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

Page 3: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

3

11.3.1 Composite Trapezoid Rule11.3.2 Composite Simpson’s Rule

CHOI WonJong ([email protected])

Page 4: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

4

11.3.1 Composite Trapezoid Rule

CHOI WonJong ([email protected])

Page 5: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

5

11.3 BETTER NUMERICAL INTEGRATION

Composite integration(복합적분 ) : Applying one of the lower order methods presented in the previous section repeatedly on several sub intervals.

Page 6: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

6

11.3.1 Composite Trapezoid Rule

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.

1

11 1

1 1

( ) ( ) ( ) [ ( ) ( )] [ ( ) ( )]2 2

[ ( ) 2 ( ) ( )] [ ( ) 2 ( ) ( )]2 4

b x b

a a x

h hf x dx f x dx f x dx f a f x f x f b

h b af a f x f b f a f x f b

2

b ah

Page 7: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

7

11.3.1 Composite Trapezoid Rule

If we divide the interval into n subintervals, we get

1

1

1 1

1 1

( ) ( ) ( )

[ ( ) ( )] [ ( ) ( )]2 2

[ ( ) 2 ( ) 2 ( ) ( )]2

n

b x b

a a x

n

n

f x dx f x dx f x dx

h hf a f x f x f b

b af a f x f x f b

n

b ah

n

MATLAB CODE

Page 8: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

8

11.3.1 Composite Trapezoid Rule

Example 11.9

n=1 n=2 n=3

n=4 n=20 n=100

Page 9: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

9

11.3.1 Composite Trapezoid Rule

Example 11.9

2

1

1[log | | ]

1 2[log | 2 | ] [log |1| ] log 0.69314718055995

1

b baa

dx x Cx

dx C Cx

Page 10: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

10

11.3.2 Composite Simpson’s Rule

CHOI WonJong ([email protected])

Page 11: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

11

11.3.2 Composite Simpson’s Rule

Example 11.10

Page 12: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

12

11.3.2 Composite Simpson’s Rule

Applying the same idea of subdivision of intervals to Simpson’s rule and requiring that n be even gives the composite Simpson rule.

[a,b] 를 two subintervals [a,x2], [x2, b] 로 나눈다면 ,

2 ,2 4

b a b ax h

2

2

1 2 2 3

( ) ( ) ( )

[ ( ) 4 ( ) ( )] [ ( ) 4 ( ) ( )]3 3

b x b

a a xf x dx f x dx f x dx

h hf a f x f x f x f x f b

Page 13: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

13

11.3.2 Composite Simpson’s Rule

In general, for n even, we have h=(b-a)/n, and Simpson’s rule is

b ah

n

1 2 3 4 2 1( ) [ ( ) 4 ( ) 2 ( ) 4 ( ) 2 ( ) 2 ( ) 4 ( ) ( )]3

b

n na

hf x dx f a f x f x f x f x f x f x f b

Page 14: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

14

11.3.2 Composite Simpson’s Rule

Example 11.10

Page 15: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

15

11.3.2 Composite Simpson’s Rule

Example 11.11 Length of Elliptical Orbit

2 2 2 2

3( ) cos( ), ( ) sin( )

4

( ') ( ') 0.25 16sin ( ) 9cos ( )b b

a a

x r r y r r

L x y dr r r dr

Page 16: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

16

11.3.2 Composite Simpson’s Rule

Example 11.11 Length of Elliptical Orbit

2 2 2 2

3( ) cos( ), ( ) sin( )

4

( ') ( ') 0.25 16sin ( ) 9cos ( )b b

a a

x r r y r r

L x y dr r r dr

days 0 10 20 30 40 50 60 70 80 90 100r = [0.00 1.07 1.75 2.27 2.72 3.14 3.56 4.01 4.53 5.22 6.28]

Using Composite Simpson’s Rule and the length between day 0 and 10 (n=20) is 0.88952. (Trapezoid=0.889567, Text=0.8556)Using Composite Simpson’s Rule and the length between day 60 and 70 (n=20) is 0.382108. (Trapezoid=0.382109, Text=0.3702)The former is 2.3279 times faster than the latter.

Page 17: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

17

11.3.3 Extrapolation Methods for Quadrature

Woo Yeon-Moon([email protected])

Page 18: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

18

Richardson Expolation

Truncation error(절단 오차 )• ( , ) ( , )I I f h E f h

21 1

1

( ) [ ( ) 2 ( ) ... 2 ( ) ( )]2

bj

n jja

hf x dx f a f x f x f b c h

2

1 1[ ( ) 2 ( ) ... 2 ( ) ( )]2 n

hf a f x f x f b ch

41 2 2 3[ ( ) 4 ( ) 2 ( )] [ ( ) 4 ( ) ( )]

3 3

h hf a f x f x f x f x f b ch

사다리꼴

simpson

Page 19: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

19

Richardson Expolation

To obtain an estimate that is more accurate• using two or more subintervals (h를 줄임 )

- 그러나 , 세부구간의 수가 일정한 범위를 넘어서면 round-off error가 커지게 된다 .

Richardson Extrapolation간격이 다른 2개의 식을 구한 결과를 대수적으로 정리함으로써보다 정확한 값을 산출

계산오차

세부 구간의 수

simpson

trapezoid

Page 20: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

20

Richardson Extrapolation

Richardson Extrapolation using the trapezoid rule

(if h_2 = ½ h_1)

2 21 1 2 2( ) ( )T TI I h ch I h ch

2 14 ( ) ( )

3

I h I hI

2 12 2

1

2

( ) ( )( )

1

I h I hI I h

h

h

Simpson rules

Page 21: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

21

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..

2

0

1

1 1 1 1 3[ (1) (2)] [ ] 0.75

2 2 1 2 4

dxI f f

x

1

1 1 1 2 1 17[ (1) 2 (1.5) (2)] [ ] 0.7083

4 4 1 1.5 2 24I f f f

1[4 ( ) ( )]

3 2

hA A A h

1 0

1[4 ] [4(0.7083) 0.7500]/ 3 0.6944

3I I I

Page 22: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

22

Example 11.12 Integral of 1/x

Form a table of the approximations

0.6944 ≠0.693147

Ⅰ Ⅱ

h=1 0.75000.6944

h=1/2 0.7083

0

1

20 1

0.75 0.6944 0.0556

0.7083 0.6944 0.0139

(2)

E

E

E E

2( ) ( )E h O h

Page 23: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

23

Romberg Integration

Approximate an ErrorTrapezoid rules : Richardson extrapolation :

continued ( using simpson rules)4 4

1 1 2 2( ) ( )S SI I h ch I h ch

2 116 ( ) ( )

15

I h I hI

2 12 4

1

2

( ) ( )( )

1

I h I hI I h

h

h

2( )O h4( )O h

Page 24: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

24

Romberg Integration

Improving the result by Richardson extrapolation

Romberg integration : iterative procedure using Richardson extrapolation

k means the improving level(= )

2 4 6 8 101 2 3 4 5E c h c h c h c h c h

4 ( / 2) ( )( )

4 1

k

k

I h I hI h

2

degree of the error

1st 2nd 3rd

Page 25: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

25

Example 11.12 Integral of 1/x using Romberg Integration

Trapezoid rule

For k=0, I_0 = 0.75 For k=1, I_1 = 0.7083 For k=2, I_2 = 0.6941

To apply Richardson extrapolation

2

1 1

1

1( ) [ ( ) 2 ( ) ... 2 ( ) ( )]

2

b

n

a

hf x dx dx f a f x f x f b

x

Ⅰ Ⅱ

h=1 0.75000.69440.69330.6943

h=1/2 0.7083

h=1/4 0.6970

h=1/8 0.6941

1( ) 4 ( ) ( )

3 2

hA h A A h

Page 26: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

26

Example 11.12 Integral of 1/x using Romberg Integration

second level of extrapolation

1( ) 16 ( ) ( )

15 2

hC h B B h

Ⅰ Ⅱ Ⅲ

h=1 0.75000.69440.6933

h=1/2 0.7083 [16(0.6933)-0.6944]/15

h=1/4 0.6970

Page 27: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

27

Example 11.12 Integral of 1/x using Romberg Integration

five levels of extrapolation to find values for 2

1

1dx

x0.750

00.694

40.693

20.693

10.693

10.693

1

0.7083

0.6933

0.6931

0.6931

0.6931

0.6970

0.6932

0.6931

0.6931

0.6941

0.6931

0.6931

0.6934

0.6931

0.6932

Page 28: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

28

Matlab function for Romberg Integration

Page 29: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

29

11.4 Gaussian Quadrature

Kang Nam-Hee ([email protected])

Page 30: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

30

11.4.1 Gaussian Quadrature on [-1,1]

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 x1 ,… 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 2n-1

Page 31: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

31

11.4.1 Gaussian Quadrature on [-1,1]

Gaussian Quadrature Formular (cont.)

n=2

n=3

Page 32: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

32

11.4.1 Gaussian Quadrature on [-1,1]

Example 11.13 integral of exp(-x2) Using G.Q

n Xi ci

2

3

4

±0.557753

0

±0.77459

±0.861136

±0.339981

1

8/9

5/9

0.34785

0.652145

Table 11.2 parameters of Gaussian quadrature

Page 33: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

33

Gaussian-Legendre Polynomials

11.4.1 Gaussian Quadrature on [-1,1]

Page 34: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

34

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

11.4.2 Gaussian Quadrature on [a,b]

Page 35: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

35

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

11.4.2 Gaussian Quadrature on [a,b]

Page 36: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

36

Example 11.14 integral of exp(-x2) 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

11.4.2 Gaussian Quadrature on [a,b]

Page 37: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

37

Example 11.14 (cont) So we can get

Apply Gaussian Quadrature to the integral with n = 2

11.4.2 Gaussian Quadrature on [a,b]

Page 38: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

38

Matlab function for Gaussian Quadrature

11.4.2 Gaussian Quadrature on [a,b]

Page 39: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

39

11.5 MATLAB’s Methods

Woo Yeon-Moon([email protected])

Page 40: 11. Numerical Differentiation and Integration 11.3 Better Numerical Integration, 11.4 Gaussian Quadrature, 11.5 MATLAB ’ s Methods Natural Language Processing

40

11.5 MATLAB’s Methods p=polyfit(x,y,n) – find the coefficients of the p

olynomial of degree n polyder(p) - calculates the derivative of polynom

ials diff(x) - x = [1 2 3 4 5];

y = diff(x)y = 1 1 1 1

traps(x,y) Q=quad(‘f’,xmin,xmax) (simpson rules) Q=quad8(‘f’,xmin,xmax) (Newton-Cotes eight-panel

rule)