45134583 quadrature

19
7/27/2019 45134583 Quadrature http://slidepdf.com/reader/full/45134583-quadrature 1/19 Numerical Integration/Quadrature We just finished with differentiation, so let’s look now to integration. Remember that an integral is associated with the area under a curve. We may approach the computation of an integral as a sum: b a  f (  x)dx Q[  f ] =  M = 0 w  f (  x ) = w 0  f (  x 0 )+ w 1  f (  x 1 )+ w 2  f (  x 2 )+ ... + w  M  f (  x  M ) where a = x 0 <  x 1 < ... <  x  M = b and b a  f (  x)dx = Q[  f ]+  E [  f ] If we integrate by representing (  x) as a polynomial:  f (  x) P  N (  x) = a  N  x  N + a  N 1  x  N 1 + ... + a 1  x + a 0 then the truncation error [  f ] = Kf (  N +1) (c). This process leads to the Newton-Cotes formulas.

Upload: dr-mohammed-azhar

Post on 14-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 1/19

Numerical Integration/Quadrature

We just finished with differentiation, so let’s look now to integration. Remember that an

integral is associated with the area under a curve. We may approach the computation

of an integral as a sum:

Z      b

a

 f ( x)dx ≈ Q[ f ] = M 

∑k =0

wk  f ( xk ) = w0 f ( x0) + w1 f ( x1) + w2 f ( x2) + . . . + w M  f ( x M )

where a = x0 < x1 < . . . < x M  = b and

Z      b

a f ( x)dx = Q[ f ] + E [ f ]

If we integrate by representing f ( x) as a polynomial:

 f ( x) ≈ P N ( x) = a N  x N + a N −1 x

 N −1 + . . . + a1 x + a0

then the truncation error E [ f ] = K f ( N +1)(c).

This process leads to the Newton-Cotes formulas.

Page 2: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 2/19

0 2 4 6 8 10 120

5

10

Interpolation for Trapezoidal Rule

0 2 4 6 8 10 120

5

10

Interpolation for Simpson′s Rule

0 2 4 6 8 10 120

5

10

Interpolation for Simpson′s 3/8 Rule

5

10

Interpolation for the n=4 Newton−Cotes Formula

Page 3: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 3/19

Newton-Cotes FormulasAssume xk  = x0 + h ·k  and f k  = f ( xk ). Then:

I.

Z     

 x1

 x0

 f ( x) dt  =h

2( f 0 + f 1)−

h3

12 f (2)(c) Trapezoidal rule

II.

Z       x2

 x0

 f ( x) dt  =h

3( f 0 +4 f 1 + f 2)−

h5

90 f (4)(c) Simpson’s rule

III.

Z       x3

 x0  f ( x) dt  =

3h

8 ( f 0 +3 f 1 +3 f 2 + f 3)−

3h5

80 f (4)

(c) Simpson’s 3/8 rule

IV.

Z       x4

 x0

 f ( x) dt  =2h

45(7 f 0 +32 f 1 +12 f 2 +32 f 3 +7 f 4)−

8h7

945 f (6)(c) n = 4

How do we get these formulas? Lagrange interpolation:

 f ( x) ≈ P M ( x) = M 

∑k =0

 f k  L M ,k ( x)

Z       x M 

 x0

 f ( x) dx ≈

Z       x M 

 x0

P M ( x) dx =Z       x M 

 x0

∑k =0

 f k  L M ,k ( x)

dx =

 M 

∑k =0

 f k 

Z      x M 

 x0

 L M ,k ( x) dx

As a result,R    x M 

 x0f 

( x

)dx ≈ ∑ M 

k =0w

k  f 

k where the weights w

k  =

R    x M 

 x0L

 M ,k ( x

)dx.

Page 4: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 4/19

Example: Simpson’s Rule

P2( x) = f 0( x− x1)( x− x2)

( x0− x1)( x0− x2)+ f 1

( x− x0)( x− x2)

( x1− x0)( x1− x2)+ f 2

( x− x0)( x− x1)

( x2− x0)( x2− x1)

Let’s integrate our interpolant to find an approximation of the integral:

Z       x2

 x0 f ( x) dx ≈ f 0

Z       x2

 x0( x−

 x1)( x−

 x2)( x0− x1)( x0− x2)dx + f 1

Z       x2

 x0( x−

 x0)( x−

 x2)( x1− x0)( x1− x2)dx

+ f 2

Z       x2

 x0

( x− x0)( x− x1)

( x2− x0)( x2− x1)dx

Let’s evaluate the integrals using even spacing and a change of variables: t  = ( x−

 x0)/h, dt = dx/h, x1 = x0 + h and x2 = x0 +2h:Z       x2

 x0

 f ( x) dx =Z      2

0 f (t ) h dt  ≈ f 0

Z      2

0

h2(t −1)(t −2)

(−h)(−2h)h dt + f 1

Z      2

0

h2(t )(t −2)

(h)(−h)h dt 

+ f 2

Z      2

0

h2(t )(t −1)

(2h)(h)h dt 

Page 5: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 5/19

Z       x2

 x0

 f ( x) dx ≈

h f 0

2

Z      2

0

(t 2−3t +2) dt −h f 1

Z      2

0

(t 2−2t ) dt +h f 2

2

Z      2

0

(t 2− t ) dt 

=h f 0

2

t 3

3−

3t 2

2+2t 

2

0

−h f 1

t 3

3− t 2

2

0

+

h f 2

2

t 3

3−

t 2

2

2

0

=h f 0

2 8

3

12

2

+4−h f 18

3

−4+h f 2

2 8

3

4

2=

h

3( f 0 +4 f 1 + f 2)

which gives us Simpson’s rule.

If we wish to solve over a large interval, we can combine the trapezoidal rule orSimpson’s rule into composite formulas:

Z       x4

 x0

 f ( x) dx =

Z       x1

 x0

 f ( x) dx +

Z       x2

 x1

 f ( x) dx +

Z       x3

 x2

 f ( x) dx +

Z       x4

 x3

 f ( x) dxComposite

Trapezoidal ruleZ       x4

 x0

 f ( x) dx =Z       x2

 x0

 f ( x) dx +Z       x4

 x2

 f ( x) dx Composite Simpson’s rule

Page 6: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 6/19

Composite FormulasSuppose we want to integrate

R    ba f ( x) dx. Divide the interval [a, b] into M subintervals

[ xk , xk +1] such that xk  = a + h · k . Integrate using trapezoidal rule:

Z      b

a f ( x) dx =

 M 

∑k =1

Z       xk 

 xk −1

 f ( x) dx ≈ M 

∑k =1

h

2[ f ( xk −1) + f ( xk )]

=h

2[ f 0 +2 f 1 +2 f 2 + . . . +2 f  M −1 + f  M ] =

h

2( f 0 + f  M ) + h

 M −1

∑k =1

 f k 

   Composite Trapezoidal Rule

We can use the same approach with Simpson’s rule as long as the number of intervals

is a multiple of 2 (say, 2 M  with h = (b−a)/(2 M ).):

Z      b

a f ( x) dx =

 M 

∑k =1

Z       x2k 

 x2k −

2

 f ( x) dx ≈ M 

∑k =1

h

3[ f ( x2k −2) +4 f ( x2k −1) + f ( x2k )]

=h

3[ f 0 +4 f 1 +2 f 2 +4 f 3 +2 f 4 + . . . +2 f  M −2 +4 f  M −1 + f  M ]

=h

3( f 0 + f  M ) +

2h

3

 M −1

∑k =1

 f 2k +4h

3

 M 

∑k =1

 f 2k −1

   Composite Simpson’s Rule

Page 7: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 7/19

Error AnalysisWith the trapezoidal rule, we approximate the function f ( x) using linear interpolation

between successive points and then integrating the interpolant. The true function

may be written:

 f ( x) = P( x) + E ( X ) = f 0 + xf 1−  f 0

 x1− x0+

( x− x0)( x− x1)

2f (2)(c)

Integrating and changing variables to t  = x− x0:

Z     

 x1

 x0

 f ( x) dx =h

2( f 0 + f 1) +

Z     

 x1

 x0

( x− x0)( x− x1)2

f (2)(c) dx

=h

2( f 0 + f 1) +

f (2)(c)

2

Z      h

0t (t −h) dt 

=h

2( f 0 + f 1) +f (2)(c)

2 t 3

3 −ht 2

2

h

0

=

h

2( f 0 + f 1)−

h3 f (2)(c)

12

As a result, the composite trapezoidal rule is accurate locally to O(h3) even though

the approximation to the function is just linear.

Page 8: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 8/19

However, we are really interested in the global error over the whole interval [a, b], not

 just a single sub-interval [ xk −1, xk ]. (In going from the 2nd to the 3rd step, we use the

identity Mh = b−a.)

Z      b

a f ( x) dx =

 M 

∑k =1

Z       xk 

 xk −1

 f ( x) dx = M 

∑k =1

h

2( f k −1 + f k )−

h3 f (2)(c)

12

=h

2( f 0 +2 f 1 + . . . +2 f  M −1 + f  M )−

h3 f (2)(c)12

 M 

∑k =1

1

=h

2( f 0 +2 f 1 + . . . +2 f  M −1 + f  M )−

h2(b−a)

12f (2)(c)

Therefore, the global error for composite trapezoidal rule is O(h2) while the local error

is O(h3).

Similarly, the global error for composite Simpson’s rule is:−h4(b−a)

180f (4)(c).

Page 9: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 9/19

Example

Let’s put the composite formulas to work:

Z      ln(2)

0exp( x) dx = 1

 N  Trapezoidal – O(h2) Simpson – O(h4) n = 4 – O(h6)

4 1.00250110798165 1.00000499159078 1.00000005641290

8 1.00062551160333 1.00000031281055 1.00000000089187

16 1.00015639257365 1.00000001956376 1.00000000001398

32 1.00003909906062 1.00000000122294 1.00000000000022

Page 10: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 10/19

Numerical Integration and Recursion

We would like to improve our the quality of our numerical integration without the com-

plication of deriving higher order schemes.

One approach is to recursively refine the intervals over which we integrate, i.e. from

2h to h to h/2 to h/4, etc. To start, let xk  = a + k ·h with

a = x0 < x1 < x2 < . . . < x2 M −2 < x2 M −1 < x2 M  = b

and consider composite trapezoidal rule with a spacing of 2h:

Z     b

a f 

( x

)dx

≈T 

( f ,2h

) =

2h

2

 M 

∑k =1 [ f 

(2k −2

) +f 

(2k 

)]

=2h

2[( f 0 + f 2) + ( f 2 + f 4) + . . . + ( f 2 M −2 + f 2 M )]

=2h

2[( f 0 +2 f 2 +2 f 4 + . . . +2 f 2 M −2 + f 2 M ]

Page 11: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 11/19

Now, consider composite trapezoidal with a spacing of h:Z     b

a f ( x) dx ≈ T ( f , h) =

h

2

2 M 

∑k =1

[ f (k −1) + f (k )]

=h

2[( f 0 +2 f 1 +2 f 2 + . . . +2 f 2 M −1 + f 2 M ]

Notice that T ( f , h) may be rearranged to give:

=h

2[ f 0 +2 f 2 +2 f 4 + . . . +2 f 2 M −2 + f 2 M ] +

h

2[2 f 1 +2 f 3 + . . . +2 f 2 M −1]

T ( f , h) =T ( f ,2h)

2+ h

 M 

k =1

 f 2k −1

This method allows you to go from a spacing of h to h/2 without having to repeat

the work that you have already done. Let’s look next to combining successive O(h2)

approximations to give an O(h4) approximation.

Page 12: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 12/19

Recursive Simpson’s Rule

If [a, b] is broken up into intervals of length h, then

S ( f , h) =4T ( f , h)−T ( f ,2h)

3

so that you can compute Simpson’s rule using two trapezoidal rule computations.

Why?:

Z     b

a f ( x) dx≈ T ( f , h) = h

2( f 0 +2 f 1 +2 f 2 + . . . +2 f 2 M −1 + f 2 M )

4T ( f , h) = h (2 f 0 +4 f 1 +4 f 2 + . . . +4 f 2 M −1 +2 f 2 M )Z     b

a f ( x) dx≈ T ( f ,2h) =

2h

2( f 0 +2 f 2 +2 f 4 + . . . +2 f 2 M −2 + f 2 M )

3

Z     b

a  f ( x) dx≈ 4T ( f , h)−T ( f ,2h) = h ( f 0 +4 f 1 +2 f 2 + . . . +2 f 2 M −2 +4 f 2 M −1 + f 2 M )   Simpson’s Rule

Z     b

a f ( x) dx≈ S ( f , h) =

4T ( f , h)−T ( f ,2h)

3

Therefore, we can compute a numerical approximation that is O(h4) by combining

successive approximations using trapezoidal rule, an O(h2) method!

Page 13: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 13/19

Romberg Integration

Romberg integration allows us to recursively reduce the error in integration from

O(h2k ) to O(h2k +2) without deriving higher order quadrature formulas.

It can be shown that:Z     b

a f ( x) dx = T ( f , h) + E T ( f , h) where E T ( f , h) = a1h2 + a2h4 + a3h6 + . . .

Then consider two Trapezoidal rule approximations with spacings 2h and h:

2h step

Z     b

a f ( x) dx = T ( f ,2h) + a1 4h2 + a2 16h4 + a3 64h6 + . . .

h step

Z     b

a f ( x) dx = T ( f , h) + a1 h2 + a2 h4 + a3 h6 + . . .

Multiplying second equation by four and subtracting the first equation yields:

3

Z     b

a f ( x) dx = 4T ( f , h)−T ( f ,2h) + a2 12h4 + a3 60h6 + . . .

Z     b

a f ( x) dx =

4T ( f , h)−T ( f ,2h)

3+ a2 4h4 + a3 20h6 + . . .

= S ( f , h) + O(h

4

)

Page 14: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 14/19

Can we continue to improve accuracy in this way?

Suppose we are given a quadrature scheme R(

h,

k −1)

of accuracy O(

h2k 

):

 R(2h, k −1) ≈ Q =Z     b

a f ( x) dx

 R(h, k −1) ≈ Q

Then, the error can be expanded in a series as follows:

Q = R(h, k −1) + c1h2k + c2h2k +2 + . . .

Q = R(2h, k −1) + c1 4k h2k + c2 4

k +1h2k +2 + . . .

Using Richardson extrapolation, we can find:

Z     b

a f ( x) dx = Q =

4k  R(h, k −1)−

 R(2h, k −1)

4k −1    R(h,k )

+O(h2k +2)

Therefore, with two successive approximations of O(h2k ) accuracy, we can generate

an approximation of order O(h2k +2).

Page 15: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 15/19

We can compute successively better approximations using:

 R(h, k ) =4k  R(h, k −1)− R(2h, k −1)

4k −1

= R(h, k −1) + R(h, k −1)− R(2h, k −1)

4k −1

Romberg integration leads to the following tables:

R(h,0)

R(h/2,0) → R(h/2,1)

R(h/4,0) → R(h/4,1) → R(h/4,2)

R(h/8,0)

→R(h/8,1)

→R(h/8,2)

→R(h/8,3)

R(h/16,0) → R(h/16,1) → R(h/16,2) → R(h/16,3) → R(h/16,4)... ... ... ... . . .

Trapezoid Simpson’s O(h6) O(h8) O(h10)

Page 16: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 16/19

Example

Let’s put the Romberg to work, starting with h = b−a.Z     ln(2)

0exp( x) dx = 1

 N  R(ln(2)/ N ,0) R(ln(2)/ N ,1) R(ln(2)/ N ,2) R(ln(2)/ N ,3)

1 1.03972077083992

2 1.00998945715423 1.00007901925900

4 1.00250110798165 1.00000499159078 1.00000005641290

8 1.00062551160333 1.00000031281055 1.00000000089187 1.00000000001058

Note that:

 R(h,1) =4 R(h,0)− R(2h,0)

3R(h,2) =

16 R(h,1)− R(2h,1)

15

 R(h,3) =64 R(h,2)− R(2h,2)

63

Page 17: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 17/19

Gaussian Quadrature

Instead of evaluating a function at equally spaced points and combining those values

to approximate an integral (as in the Newton-Cotes formulas), try to choose the points

optimally to maximize the order of accuracy of the scheme.

Z     b

a

 f ( x) dx

 N 

∑k =1

ck  f ( xk )

We would like our formula to be exact for polynomials up to as high as degree as

possible. We have N coefficients ci and N points xi ∈ [a, b]. This gives us 2 N degrees

of freedom which can be used to exactly interpolate and integrate polynomials of

degree up to (2 N −1).

Let’s try the case with N  = 2 to demonstrate the derivation and power of the method.

Consider [a, b] = [−1,1] for simplicity:

Z     1

−1

 f ( x) dx≈ c1 f ( x1) + c2 f ( x2)

Page 18: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 18/19

We would like this to be an exact representation for polynomials of degree as high as

three. Assume the function is a cubic polynomial:

 f ( x) = a0 + a1 x + a2 x2 + a3 x3

This implies that:

Z     1

−1 f ( x) dx =

Z     1

−1

a0 + a1 x + a2 x

2 + a3 x3

dx

= c1a0 + a1 x1 + a2 x

2

1 + a3 x

3

1+ c2a0 + a1 x2 + a2 x

2

2 + a3 x

3

2a0

c1 + c2−

Z     1

−1dx

+ a1

c1 x1 + c2 x2−

Z     1

−1 x dx

+ a2

c1 x

21 + c2 x

22−

Z     1

−1 x2 dx

+a3

c1 x

31 + c2 x

32−

Z     1

−1 x3 dx

= 0

Since a0, a1, a2 and a3 are arbitrary, then their coefficients must all be zero. Thisimplies:

c1 + c2 =Z     1

−1dx = 2 c1 x1 + c2 x2 =

Z     1

−1 x dx = 0

c1 x2

1+ c

2 x2

2=

Z     1

−1 x2 dx =

2

3c1 x3

1+ c

2 x3

2=

Z     1

−1 x3 dx = 0

Page 19: 45134583 Quadrature

7/27/2019 45134583 Quadrature

http://slidepdf.com/reader/full/45134583-quadrature 19/19

Some algebra leads to:

c1 = 1 c2 = 1 x1 =−

√ 3

3 x2 =

√ 3

3

Therefore:

Z     1

−1 f ( x) dx≈ f 

−√ 3

3

+ f 

√ 3

3

These points and coefficients can be derived using the Legendre polynomials andare readily available in tables in our book (up to N=5) and elsewhere. These formulas

can be very powerful. They can allow you to exact integrate a polynomial in less time

than it would take to compute the analytical/exact solution.

Trick: If you are integrating over an interval other than [−1,1], change variables.Example: x ∈ [a, b]. Let t  =

2( x−a)(b−a)

−1 so that x ∈ [a, b]←→ t ∈ [−1,1].

Z     b

a f ( x) dx =

Z     1

−1 f 

(b−a)(t +1)

2+ a

b−a

2dt