Numerical Integration Basic Numerical Integration We want to find integration of functions of...

Post on 18-Dec-2015

228 views 2 download

Tags:

Transcript of Numerical Integration Basic Numerical Integration We want to find integration of functions of...

USC

Numerical Integration Basic Numerical Integration

We want to find integration of functions of various forms of the equation known as the Newton Cotes integration formulas.

Trapezoidal Rule Simpson’s Rule

1/3 Rule 3/8 Rule

Midpoint Gaussian Quadrature

USC

Basic Numerical Integration• Weighted sum of function values

)x(fc)x(fc)x(fc

)x(fcdx)x(f

nn1100

i

n

0ii

b

a

x0 x1 xnxn-1x

f(x)

USC0

2

4

6

8

10

12

3 5 7 9 11 13 15

Numerical IntegrationIdea is to do integral in small parts, like the way you first learned integration - a summation

Numerical methods just try to make it faster and more accurate

USC

Numerical Integration Newton-Cotes Closed Formulae -- Use

both end points Trapezoidal Rule : Linear Simpson’s 1/3-Rule : Quadratic Simpson’s 3/8-Rule : Cubic Boole’s Rule : Fourth-order

Newton-Cotes Open Formulae -- Use only interior points midpoint rule

USC

Trapezoid Rule Straight-line approximation

)x(f)x(f2

h

)x(fc)x(fc)x(fcdx)x(f

10

1100i

1

0ii

b

a

x0 x1x

f(x)

L(x)

USC

Trapezoid Rule Lagrange interpolation

010 1

0 1 1 0

0 1

( ) ( ) ( )

dx a x , b x , , d ;

h

0( ) (1 ) ( ) ( ) ( )

1

x xx xL x f x f x

x x x x

x alet h b a

b a

x aL f a f b

x b

USC

Trapezoid Rule

Integrate to obtain the rule

1

0

1 1

0 0

1 12 2

0 0

( ) ( ) ( )

( ) (1 ) ( )

( ) ( ) ( ) ( ) ( )2 2 2

b b

a af x dx L x dx h L d

f a h d f b h d

hf a h f b h f a f b

USC

Example:Trapezoid RuleEvaluate the integral Exact solution

Trapezoidal Rule

926477.5216)1x2(e4

1

e4

1e

2

xdxxe

1

0

x2

4

0

x2x24

0

x2

dxxe4

0

x2

%12.357926.5216

66.23847926.5216

66.23847)e40(2)4(f)0(f2

04dxxeI 84

0

x2

USC

Simpson’s 1/3-RuleApproximate the function by a parabola

)x(f)x(f4)x(f3

h

)x(fc)x(fc)x(fc)x(fcdx)x(f

210

221100i

2

0ii

b

a

x0 x1x

f(x)

x2h h

L(x)

USC

Simpson’s 1/3-Rule

1 xx

0 xx

1 xxh

dxd ,

h

xx ,

2

abh

2

ba x ,bx ,ax let

)x(f)xx)(xx(

)xx)(xx(

)x(f)xx)(xx(

)xx)(xx( )x(f

)xx)(xx(

)xx)(xx()x(L

2

1

0

1

120

21202

10

12101

200

2010

21

)x(f2

)1()x(f)1()x(f

2

)1()(L 21

20

USC

Simpson’s 1/3-Rule

1

1

23

2

1

1

3

1

1

1

23

0

1

12

1

0

21

1

10

1

1

b

a

)2

ξ

3

ξ(

2

h)f(x

)3

ξ(ξ)hf(x)

2

ξ

3

ξ(

2

h)f(x

)dξ1ξ(ξ2

h)f(x)dξξ1()hf(x

)dξ1ξ(ξ2

h)f(xdξ)(Lhf(x)dx

)f(x)4f(x)f(x3

hf(x)dx 210

b

a

Integrate the Lagrange interpolation

USC

Simpson’s 3/8-RuleApproximate by a cubic polynomial

)x(f)x(f3)x(f3)x(f8

h3

)f(xc)f(xc)f(xc)f(xc)x(fcdx)x(f

3210

33221100i

3

0ii

b

a

x0 x1x

f(x)

x2h h

L(x)

x3h

USC

Simpson’s 3/8-Rule

)x(f)xx)(xx)(xx(

)xx)(xx)(xx(

)x(f)xx)(xx)(xx(

)xx)(xx)(xx(

)x(f)xx)(xx)(xx(

)xx)(xx)(xx(

)x(f)xx)(xx)(xx(

)xx)(xx)(xx()x(L

3231303

210

2321202

310

1312101

320

0302010

321

)x(f)x(f3)x(f3)x(f8

h33

a-bh ; L(x)dxf(x)dx

3210

b

a

b

a

USC

Example: Simpson’s RulesEvaluate the integral Simpson’s 1/3-Rule

Simpson’s 3/8-Rule

dxxe4

0

x2

4 2

0

4 8

(0) 4 (2) (4)3

20 4(2 ) 4 8240.411

35216.926 8240.411

57.96%5216.926

x hI xe dx f f f

e e

4 2

0

3 4 8(0) 3 ( ) 3 ( ) (4)

8 3 3

3(4/3)0 3(19.18922) 3(552.33933) 11923.832 6819.209

85216.926 6819.209

30.71%5216.926

x hI xe dx f f f f

USC

Midpoint RuleNewton-Cotes Open Formula

)(f24

)ab()

2

ba(f)ab(

)x(f)ab(dx)x(f3

m

b

a

a b x

f(x)

xm

USC

Two-point Newton-Cotes Open Formula

Approximate by a straight line

)(f108

)ab()x(f)x(f

2

abdx)x(f

3

21

b

a

x0 x1x

f(x)

x2h h x3h

USC

Three-point Newton-Cotes Open Formula

Approximate by a parabola

)(f23040

)ab(7

)x(f2)x(f)x(f23

abdx)x(f

5

321

b

a

x0 x1x

f(x)

x2h h x3h h x4

USC

Better Numerical Integration

Composite integration Composite Trapezoidal Rule Composite Simpson’s Rule

Richardson Extrapolation Romberg integration

USC

Apply trapezoid rule to multiple segments over integration limits

0

1

2

3

4

5

6

7

3 5 7 9 11 13 15

Two segments

0

1

2

3

4

5

6

7

3 5 7 9 11 13 15

Four segments

0

1

2

3

4

5

6

7

3 5 7 9 11 13 15

Many segments

0

1

2

3

4

5

6

7

3 5 7 9 11 13 15

Three segments

USC

Composite Trapezoid Rule

)x(f)x(f2)2f(x)f(x2)f(x2

h

)f(x)f(x2

h)f(x)f(x

2

h)f(x)f(x

2

h

f(x)dxf(x)dxf(x)dxf(x)dx

n1ni10

n1n2110

x

x

x

x

x

x

b

a

n

1n

2

1

1

0

x0 x1x

f(x)

x2h h x3h h x4

n

abh

USC

Composite Trapezoid RuleEvaluate the integral dxxeI

4

0

x2

%66.2 95.5355

)4(f)75.3(f2)5.3(f2

)5.0(f2)25.0(f2)0(f2

hI25.0h,16n

%50.10 76.5764)4(f)5.3(f2 )3(f2)5.2(f2)2(f2)5.1(f2

)1(f2)5.0(f2)0(f2

hI5.0h,8n

%71.39 79.7288)4(f)3(f2

)2(f2)1(f2)0(f2

hI1h,4n

%75.132 23.12142)4(f)2(f2)0(f2

hI2h,2n

%12.357 66.23847)4(f)0(f2

hI4h,1n

USC

Composite Trapezoid Example

2

1 1

1dx

x

x f(x)1.00 0.50001.25 0.44441.50 0.40001.75 0.36362.00 0.3333

USC

Composite Trapezoid Rule with Unequal Segments

Evaluate the integral h1 = 2, h2 = 1, h3 = 0.5, h4 = 0.5

dxxeI4

0

x2

%45.14 58.5971 45.3 2

0.5

5.33e 2

0.532

2

120

2

2

)4()5.3(2

)5.3()3(2

)3()2(2

)2()0(2

)()()()(

87

76644

43

21

4

5.3

5.3

3

3

2

2

0

ee

eeee

ffh

ffh

ffh

ffh

dxxfdxxfdxxfdxxfI

USC

Composite Simpson’s Rule

x0 x2x

f(x)

x4h h xn-2h xn

n

abh

…...

Piecewise Quadratic approximations

hx3x1 xn-1

USC

)x(f)x(f4)x(f2

)4f(x)x(f2)f(x4

)2f(x)f(x4)2f(x)f(x4)f(x3

h

)f(x)4f(x)f(x3

h

)f(x)f(x4)f(x3

h)f(x)f(x4)f(x

3

h

f(x)dxf(x)dxf(x)dxf(x)dx

n1n2n

12ii21-2i

43210

n1n2n

432210

x

x

x

x

x

x

b

a

n

2n

4

2

2

0

Composite Simpson’s RuleMultiple applications of Simpson’s rule

USC

Composite Simpson’s RuleEvaluate the integral n = 2, h = 2

n = 4, h = 1

dxxeI4

0

x2

%70.8 975.5670

e4)e3(4)e2(2)e(403

1

)4(f)3(f4)2(f2)1(f4)0(f3

hI

8642

%96.57 411.8240e4)e2(403

2

)4(f)2(f4)0(f3

hI

84

USC

Composite Simpson’s Example

2

1 1

1dx

x

x f(x)1.00 0.50001.25 0.44441.50 0.40001.75 0.36362.00 0.3333

USC

Composite Simpson’s Rule with Unequal Segments

Evaluate the integral h1 = 1.5, h2 = 0.5

dxxeI4

0

x2

%76.3 23.5413

4)5.3(433

5.03)5.1(40

3

5.1

)4(2)5.3(4)3(3

)3(2)5.1(4)0(3

)()(

87663

2

1

4

3

3

0

eeeee

fffh

fffh

dxxfdxxfI

USC

Richardson ExtrapolationUse trapezoidal rule as an example

subintervals: n = 2j = 1, 2, 4, 8, 16, ….

j2

1jjn1n10

b

ahc)x(f)x(f2)f(x2)f(x

2

hf(x)dx

)()()()(

)()()()(

)()()()()(

)()()(

)()(

bfxf2xf2af2

hI2j

bfxf2xf2af16

hI83

bfxf2xf2xf2af8

hI42

bfxf2af4

hI21

bfaf2

hI10

Formulanj

1n1jjj

713

3212

11

0

USC

Richardson ExtrapolationFor trapezoidal rule

kth level of extrapolation

)h(B)2

h(B16

15

1)h(C

)2

h(b)

2

h(BA

hb)h(BA

hb)h(B h4

c)h(A)

2

h(A4

3

1A

)2

h(c)

2

h(c)

2

h(AA

hchc)h(AA

hc)h(Adx)x(fA

42

42

42

42

42

21

42

21

21

b

a

14

)h(Ch/2)(C4)h(D

k

k

USC

255

II256

63

II64

15

II16

3

II4I16h

II8h

III4h

IIII2h

IIIIIh

hOhOhOhOhO

4k3k2k1k0k

sBoolesSimpsonTrapezoid

3j31j2j21j1j11j0j01j

04

1303

221202

31211101

4030201000

108642

,,,,,,,,

,

,,

,,,

,,,,

,,,,,

/

/

/

/

)()()()()(

''

3, 2,1,k ;14

II4I

k

k,jk,1jk

k,j

Romberg IntegrationAccelerated Trapezoid Rule

USC

Romberg IntegrationAccelerated Trapezoid Rule

926477.5216dxxeI4

0

x2

%00050.0%00168.0%0053.0%0527.0%66.2

95.535525.0h

68.521976.57645.0h

20.521775.525679.72881h

01.521714.522998.56702.121422h

95.521684.522468.549941.82407.238474h

)h(O)h(O)h(O)h(O)h(O

4k3k2k1k0k

s'Booles'SimpsonTrapezoid

108642

USC

Romberg Integration Example

2

1 1

1dx

x

x f(x)1.00 0.50001.25 0.44441.50 0.40001.75 0.36362.00 0.3333

USC

Gaussian Quadratures Newton-Cotes Formulae

use evenly-spaced functional values

Gaussian Quadratures select functional values at non-uniformly

distributed points to achieve higher accuracy change of variables so that the interval of

integration is [-1,1] Gauss-Legendre formulae

USC

Gaussian Quadrature on [-1, 1]

Choose (c1, c2, x1, x2) such that the method yields “exact integral” for f(x) = x0, x1, x2, x3

)x(fc)x(fc)x(fc)x(fcdx)x(f nn2211i

1

1

n

1ii

)f(xc)f(xc

f(x)dx :2n

2211

1

1

x2x1-1 1

USC

Gaussian Quadrature on [-1, 1]

Exact integral for f = x0, x1, x2, x3

Four equations for four unknowns

)f(xc)f(xcf(x)dx :2n 2211

1

1

3

1x

3

1x

1c1c

xcxc0dxx xf

xcxc3

2dxx xf

xcxc0xdx xf

cc2dx1 1f

2

1

2

1

322

31

1

1 133

222

21

1

1 122

221

1

1 1

2

1

1 1

)3

1(f)

3

1(fdx)x(fI

1

1

USC

Gaussian Quadrature on [-1, 1]

Choose (c1, c2, c3, x1, x2, x3) such that the method yields “exact integral” for f(x) = x0, x1, x2, x3,x4, x5

)x(fc)x(fc)x(fcdx)x(f :3n 332211

1

1

x3x1-1 1x2

USC

Gaussian Quadrature on [-1, 1]

533

522

511

1

1

55

433

422

411

1

1

44

333

322

311

1

1

33

233

222

211

1

1

22

332211

1

1

321

1

1

0

5

2

0

3

2

0

21

xcxcxcdxxxf

xcxcxcdxxxf

xcxcxcdxxxf

xcxcxcdxxxf

xcxcxcxdxxf

cccxdxf

5/3

0

5/3

9/5

9/8

9/5

3

2

1

3

2

1

x

x

x

c

c

c

USC

Gaussian Quadrature on [-1, 1]

Exact integral for f = x0, x1, x2, x3, x4, x5

)5

3(f

9

5)0(f

9

8)

5

3(f

9

5dx)x(fI

1

1

USC

Gaussian Quadrature on [a, b]

Coordinate transformation from [a,b] to [-1,1]

t2t1a b

1

1

1

1

b

adx)x(gdx)

2

ab)(

2

abx

2

ab(fdt)t(f

bt 1xat1x2

abx

2

abt

USC

Example: Gaussian QuadratureEvaluate

Coordinate transformation

Two-point formula

33.34%)( 543936.3477376279.3468167657324.9

e)3

44(e)

3

44()

3

1(f)

3

1(fdx)x(fI 3

44

3

441

1

926477.5216dtteI4

0

t2

1

1

1

1

4x44

0

t2 dx)x(fdxe)4x4(dtteI

2dxdt ;2x22

abx

2

abt

USC

Example: Gaussian QuadratureThree-point formula

Four-point formula

4.79%)( 106689.4967

)142689.8589(9

5)3926001.218(

9

8)221191545.2(

9

5

e)6.044(9

5e)4(

9

8e)6.044(

9

5

)6.0(f9

5)0(f

9

8)6.0(f

9

5dx)x(fI

6.0446.04

1

1

%)37.0( 54375.5197 )339981.0(f)339981.0(f652145.0

)861136.0(f)861136.0(f34785.0dx)x(fI1

1