Chapter 18 Numerical Integration of Functions. Numerical Integration Tabulated data – the...

36
Chapter 18 Chapter 18 Numerical Numerical Integration of Integration of Functions Functions

Transcript of Chapter 18 Numerical Integration of Functions. Numerical Integration Tabulated data – the...

Chapter 18Chapter 18

Numerical Integration Numerical Integration of Functionsof Functions

Numerical IntegrationNumerical Integration Tabulated data – the accuracy of the integral

is limited by the number of data points Continuous function – we can generate as

many f(x) as required to attain the required accuracy

Richardson extrapolation and Romberg integration

Gauss Quadratures

Round-off errors may limit the precision of lower-order Newton-Cotes composite integration formula

Use Romberg Integration for efficient integration

More efficient methods to achieve better accuracy have been developed

Romberg integration - uses Richardson extrapolation

Idea behind Richardson extrapolation -improve the estimate by eliminating the leading term of truncation error at coarser grid levels

Romberg IntegrationRomberg Integration

The exact integral can be represented as

This is true for any h = (ba)/n

Use trapezoidal rule as an example

hEhII

2211 hEhIhEhII

2

2

21

2

12

h

h

hE

hE fh

12

abE

)(

Richardson ExtrapolationRichardson Extrapolation

Composite Trapezoidal RuleComposite Trapezoidal Rule• Evaluate the integral dxxeI

4

0

x2

%..)().().(

).().()(.,

%..)().(

)().()().(

)().()(.,

%..)()(

)()()(,

%..)()()(,

%..)()(,

662 9553554f753f253f2

50f2250f20f2

hI250h16n

5010 7657644f53f2

3f252f22f251f2

1f250f20f2

hI50h8n

7139 7972884f3f2

2f21f20f2

hI1h4n

75132 23121424f2f20f2

hI2h2n

12357 66238474f0f2

hI4h1n

Truncation error for trapezoidal rule

Substitute into the exact integral

Which leads to

2

2

121 h

h hEhE

)()()()( 22

2

2

121 hEhI

h

hhEhII

2

21

212 hh1

hIhIhE

)/(

)()(

Richardson ExtrapolationRichardson Extrapolation

Plugging back into I = I(h) + E(h)

If h2 = h1/2, then

)()(

/)( 122

21

2 hIhI1hh

1hII

)()(

)()()(

12

1222

hI3

1hI

3

4I

hIhI12

1hII

Richardson ExtrapolationRichardson Extrapolation

Combine two O(h2) estimates to get an O(h4) estimate

Can also combine two O(h4) estimates to get an O(h6) estimate

Combine two O(h6) estimates to get an O(h8) estimate

lm12 I15

1I

15

16hI

15

1hI

15

16I )()(

lm12 I63

1I

63

64hI

63

1hI

63

64I )()(

Richardson ExtrapolationRichardson Extrapolation

Im and Il are more and less accurate estimates, respectively

General form is called Romberg Integration

j: level of accuracy - j+1 is more accurate (more segments)

k: level of integration - k=1 is the original trapezoidal rule estimate (O(h2)), k=2 is improved (O(h4)), k=3 corresponds to O(h6), etc.

14

II4I

1k

1kj1k1j1k

kj

,,

,

Romberg IntegrationRomberg Integration

255

II256

63

II64

15

II16

3

II4I16h

II8h

III4h

IIII2h

IIIIIh

hOhOhOhOhO

5k4k3k2k1k

sBoolesSimpsonTrapezoid

4j41j3j31j2j21j1j11j

15

2414

332313

42322212

5141312111

108642

,,,,,,,,

,

,,

,,,

,,,,

,,,,,

/

/

/

/

)()()()()(

''

3, 2,k 14

II4I

1k

1kj1k1j1k

kj

;,,,

Romberg IntegrationRomberg Integration• Accelerated Trapezoidal Rule

Romberg IntegrationRomberg Integration

9264775216dxxeI4

0

x2 .

Accelerated Trapezoid Rule

%.%.%.%.%.

..

...

...

....

.....

)()()()()(

''

0005000016800053005270662

955355250h

68521976576450h

2052177552567972881h

0152171452299856702121422h

9552168452246854994182407238474h

hOhOhOhOhO

5k4k3k2k1k

sBoolesSimpsonTrapezoid

108642

Romberg IntegrationRomberg Integration

Accelerated trapezoidal Rule

» intg = romberg(‘example1’,0,pi,0.00001,2)I = 0.0000 0.0000 -5.5122 0.0000 -5.1677 0 -3.8758 0 0» intg = Romberg(‘example1’,0,pi,0.00001,3)I = 0.0000 0.0000 -5.5122 -4.9221 0.0000 -5.1677 -4.9313 0 -3.8758 -4.9461 0 0 -4.6785 0 0 0» intg = romberg(‘example1’,0,pi,0.00001,4)I = 0.0000 0.0000 -5.5122 -4.9221 -4.9349 0.0000 -5.1677 -4.9313 -4.9348 0 -3.8758 -4.9461 -4.9348 0 0 -4.6785 -4.9355 0 0 0 -4.8712 0 0 0 0» intg = romberg(‘example1’,0,pi,0.00001,6)I = 0.0000 0.0000 -5.5122 -4.9221 -4.9349 -4.9348 -4.9348 0.0000 -5.1677 -4.9313 -4.9348 -4.9348 -4.9348 0 -3.8758 -4.9461 -4.9348 -4.9348 -4.9348 0 0 -4.6785 -4.9355 -4.9348 -4.9348 0 0 0 -4.8712 -4.9348 -4.9348 0 0 0 0 -4.9189 -4.9348 0 0 0 0 0

-4.9308 0 0 0 0 0

dxx2x

0

2 )sin(

CVEN 302-501CVEN 302-501

Homework No. 12Homework No. 12

• Chapter 17

• Problem 17.3 (25), 17.5 (25)– Hand Calculation

• Chapter 18

• Problem 18.2 (25), 18.4 (25)

• Due on Monday, 11/17/2008 at the beginning of the Due on Monday, 11/17/2008 at the beginning of the periodperiod

Assume

a and b are limits of integration Trapezoidal rule should give exact results

for constant and linear functions

bfcafcI 10

Gauss QuadratureGauss Quadrature

b

a dxxfI )(

Trapezoidal rule gives exact solution

for constant and linear functions

Now instead of trapezoidal, which has fixed end points (a,b), let them float

4 unknowns - x0 ,x1 ,c0 ,c1

4 equations - constant, linear (had before in trapezoidal rule), quadratic, cubic

Integrate from -1 to 1 to simplify math

)()()( 1100

1

1xfcxfc dxxfI

Gauss QuadratureGauss Quadrature

Trapezoidal vs. Gauss-QuadratureTrapezoidal vs. Gauss-Quadrature

Exact for constant and linear functions

Exact for constant, linear, quadratic and cubic functions

The idea is that if we evaluate the function at certain points (non-uniformly distributed), and sum with certain weights, we will get accurate integral

Evaluation points and weights are tabulated

Gauss QuadratureGauss Quadrature

Gauss-Legendre QuadratureGauss-Legendre Quadrature

Choose (c0 , c1 , x0 , x1) to yield highest possible accuracy

Gauss QuadraturesGauss Quadratures Newton-Cotes Formulas use evenly-spaced functional values

Gauss Quadratures (Gauss-Legendre formulas)

change of variables so that the interval of integration is [1,1]

select functional values at non-uniformly distributed points to achieve higher accuracy

To go to [1,1] from other limits [a,b] - use linear transformation

Change from a x b to 1 xd 1

Coordinate transformation

Gauss Quadrature on Gauss Quadrature on [[aa, , bb]]

2aba

2baa

1aab

1aaa

xaax

1

0

10

10

d10

/)(

/)(

)(

)(

dx2

ab

2

bax

Gauss Quadrature on Gauss Quadrature on [[aa, , bb]] Coordinate transformation from [a,b] to [1,1]

t2t1a b

1

1 dd

1

1 dd

b

adxxgdx

2

ab

2

bax

2

abfdxxf )())(()(

bx 1x

ax1x2

bax

2

abx

d

d

d

Gauss Quadrature on Gauss Quadrature on [[1, 1]1, 1]

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

)()()()()( nn1100i

1

1

n

1ii xfcxfcxfcxfcdxxf

)()(

)(

1100

1

1

xfcxfc

dxxf :2n

x1x0-1 1

Gauss Quadrature on Gauss Quadrature on [[1, 1]1, 1]

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

Four equations for four unknowns

)()()( 1100

1

1xfcxfcdxxf :2n

3

1x

3

1x

1c

1c

xcxc0dxx xf

xcxc3

2dxx xf

xcxc0xdx xf

cc2dx1 1f

1

0

1

0

311

30

1

1 033

211

20

1

1 022

110

1

1 0

1

1

1 0

)3

1(f)

3

1(fdx)x(fI

1

1

Gauss Quadrature on Gauss Quadrature on [[1, 1]1, 1]

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

)()()()(: 221100

1

1xfcxfcxfcdxxf 3n

x2x0-1 1x1

Gauss Quadrature on Gauss Quadrature on [[1, 1]1, 1]• Exact integral for f = x0, x1, x2, x3, x4, x5

3/5x

0x

3/5x

5/9c

8/9c

5/9c

xcxcxc0dxx xf

xcxcxc0dxx xf

xcxcxc0dxx xf

xcxcxc3

2dxx xf

xcxcxc0xdx xf

ccc2dx1 1f

2

1

0

2

1

0

522

51

1

1 1500

55

422

41

1

1 1400

44

322

31

1

1 1300

33

222

21

1

1 1200

22

221

1

1 100

2

1

1 10

)5

3(f

9

5)0(f

9

8)

5

3(f

9

5dx)x(fI

1

1

Example: Gauss QuadratureExample: Gauss QuadratureEvaluate

Coordinate transformation

Two-point formula

33.34%)( 543936347737627934681676573249

e3

44e

3

44

3

1g

3

1gdxxgI 3

44

3

441

1 dd

...

)()()()()(

4 2

05216.926477xI xe dx

1

1 dd

1

1 d4x4

d

4

0

x2

ddd

dxxgdxe4x4dxxeI

2dxdx 2x22

bax

2

abx

d )()(

;

Example: Gauss QuadratureExample: Gauss Quadrature Three-point formula

Four-point formula

4.79%)( 1066894967

14268985899

53926001218

9

82211915452

9

5

e60449

5e4

9

8e6044

9

5

60g9

50g

9

860g

9

5dxxgI

6044604

1

1 dd

.

).().().(

).()().(

).()().()(

..

%).(.

).().(.

).().(.)(

370 543755197

3399810g3399810g6521450

8611360g8611360g347850dxxgI1

1 dd

9324695140 x1713245.0c

6612093860 x3607616.0c

2386191860 x4679139.0c

2386191860x4679139.0c

6612093860x3607616.0c

f9324695140x1713245.0c6

9061798460 x2369269.0c

5384693100 x4786287.0c

0000000000 x5688889.0c

5384693100x4786287.0c

f9061798460x2369269.0c5

8611363120 x3478548.0c

3399810440 x6521452.0c

3399810440x6521452.0c

f8611363120x3478548.0c4

774596669.0 x5555556.0c

000000000.0 x8888889.0c

f774596669.0x5555556.0c3

577350269.0 x0000000.1cf

Error Truncation

577350269.0x

Arguments Function

0000000.1c

Factors Weighting

2

Points

55

44

23

22

11

(12)00

44

33

22

11

(10)00

33

22

11

(8)00

22

11

(6)00

11

(4)00

.

.

.

.

.

)(.

.

.

.

.

)(.

.

.

.

)(.

)(

)(

Gauss-Legendre Formulas

Gauss QuadratureGauss Quadrature

Gauss QuadratureGauss Quadrature» I=Gauss_quad(‘example1’,0,pi,2);t = -0.5774 -0.7746 -0.8611 -0.9062 0.5774 0 -0.3400 -0.5385 0 0.7746 0.3400 0 0 0 0.8611 0.5385 0 0 0 0.9062c = 1.0000 0.5556 0.3479 0.2369 1.0000 0.8889 0.6521 0.4786 0 0.5556 0.6521 0.5689 0 0 0.3479 0.4786 0 0 0 0.2369tt = -0.5774 0.5774cd = 1 1» II = -8.6878» Q=quad8(‘example1’,0,pi)Q = -4.9348

k = 2

Exact Q = -4.9348

dxx2sinx0

2 )(

» I=Gauss_quad(‘example1’,0,pi,5);t = -0.5774 -0.7746 -0.8611 -0.9062 0.5774 0 -0.3400 -0.5385 0 0.7746 0.3400 0 0 0 0.8611 0.5385 0 0 0 0.9062c = 1.0000 0.5556 0.3479 0.2369 1.0000 0.8889 0.6521 0.4786 0 0.5556 0.6521 0.5689 0 0 0.3479 0.4786 0 0 0 0.2369tt = -0.9062 -0.5385 0 0.5385 0.9062cd = 0.2369 0.4786 0.5689 0.4786 0.2369» II = -4.9333

Gauss Quadraturek = 5

Exact Q = -4.9348

dxx2sinx0

2 )(

Adaptive QuadratureAdaptive Quadrature Composite Simpson’s 1/3 rule requires the use

of equally spaced points Use adaptive refinement in regions of relatively

abrupt changes Estimate truncation error between two levels

of refinement Automatically adjust the step size so that small

steps are taken in regions of sharp variations while larger steps are used elsewhere

MATLAB functions: quad and quadl

MATLAB Integration MethodsMATLAB Integration Methods

trapz(x,y) * Composite trapezoid rule

q = quad(‘func’,xmin,xmax) * Adaptive Simpson’s rule (p 439), more efficient for low accuracies or non-

smooth functions

q =quadl(‘func’,xmin, xmax) * Labatto quadrature – more efficient for high accuracies and smooth functions (p439)