22.07.2014 Views

Lecture 4 - Computer Science Department - University of Kentucky

Lecture 4 - Computer Science Department - University of Kentucky

Lecture 4 - Computer Science Department - University of Kentucky

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CS321<br />

Numerical Analysis<br />

<strong>Lecture</strong> 4<br />

Numerical Integration<br />

Pr<strong>of</strong>essor Jun Zhang<br />

<strong>Department</strong> <strong>of</strong> <strong>Computer</strong> <strong>Science</strong><br />

<strong>University</strong> <strong>of</strong> <strong>Kentucky</strong><br />

Lexington, KY 40206‐0046<br />

October 1, 2010


Definite Integral<br />

A definite integral has an interval for integration. For a fixed integration<br />

interval, the result is a number<br />

π<br />

2<br />

∫ sin x dx = 1<br />

0<br />

An indefinite integral does not have an integration interval. The result<br />

<strong>of</strong> an indefinite integral (antiderivative) is a class <strong>of</strong> functions<br />

∫<br />

sin x dx = − cos x + C<br />

Numerical integration is for computing definite integrals<br />

Fundamental Theorem <strong>of</strong> Calculus:<br />

∫<br />

b<br />

a<br />

x<br />

∫ a<br />

F'(<br />

t<br />

) dt = F<br />

( x<br />

) − F<br />

( a<br />

)<br />

a<br />

F'(<br />

x)<br />

dx = F(<br />

b)<br />

− F(<br />

a)<br />

2


Numerical Integration


Partition<br />

The definite integral <strong>of</strong> a function can be viewed as the area under a<br />

curve. This point <strong>of</strong> view lends us means to compute dfii definite integral<br />

Let P be a partition <strong>of</strong> the interval <strong>of</strong> [a,b] as<br />

P<br />

{ a = x < x < x < < x < x b}<br />

= 0 1 2 L n −1 n =<br />

We have n subintervals as [x i ,x i+1 ]. Let m i be the greatest lower bound <strong>of</strong><br />

(a nonnegative function) f(x) on [x i ,x i+1 ] as<br />

m<br />

i<br />

{ f ( x)<br />

: x ≤ x ≤ x }<br />

= i<br />

inf i<br />

+<br />

and M i as the least upper bound on the same subinterval<br />

M<br />

i<br />

{ f ( x)<br />

: x ≤ x ≤ x }<br />

= i<br />

sup i<br />

+<br />

1<br />

1<br />

4


Partition


Lower and Upper Sums<br />

The lower sums and upper sums <strong>of</strong> f corresponding to the given partition<br />

P is<br />

n−11<br />

L(<br />

f ; P)<br />

= m x − x<br />

U<br />

(<br />

f<br />

;<br />

P<br />

) =<br />

∑<br />

i=<br />

0<br />

n−1<br />

∑<br />

=<br />

i=<br />

0<br />

i<br />

M<br />

( )<br />

i+<br />

1<br />

( x<br />

x<br />

)<br />

i+ 1 −<br />

If we consider the definite integral <strong>of</strong> a nonnegative f as the area under<br />

the curve, we have<br />

L ( f ; P)<br />

f ( x)<br />

dx ≤ U(<br />

f ; P)<br />

for all partitions P<br />

∫<br />

≤ b a<br />

i<br />

i<br />

i<br />

If f is continuous on [a,b], then the above inequality defines the definite<br />

integral. The integral also exists it if f is monotone (ith (either increasing i or<br />

decreasing) on [a,b]<br />

6


Upper and Lower Bounds


Riemann‐Integrable Functions<br />

If the greatest lower bound equals the least upper bound for all partitions <strong>of</strong><br />

[a,b], i.e.,<br />

inf U(<br />

f ; P)<br />

= sup L(<br />

f , P)<br />

Then f is said to be Riemann‐integrable<br />

P<br />

Every continuous function defined on a closed and bounded interval <strong>of</strong> the<br />

real line is Riemann‐integrable<br />

We have<br />

lim<br />

n→∞<br />

L(<br />

f ; P<br />

n<br />

)<br />

= ∫<br />

b<br />

a<br />

P<br />

f ( x)<br />

dx =<br />

lim U(<br />

f ; P<br />

n→∞<br />

where P 0 , P 1 ,.., P n ,… are a sequence <strong>of</strong> partitions such that the length <strong>of</strong> the<br />

largest subinterval in P n converges to 0 as n → ∞<br />

We can construct nested (refined) partitions<br />

n<br />

)<br />

8


Computation<br />

1.) need a procedure to evaluate f(x)<br />

2.) determine a partition (how many subintervals) <strong>of</strong> the interval [a,b]<br />

3.) compute m i and M i on each subinterval<br />

4.) compute the sums L(f; P) and U(f; P)<br />

5.) an approximate value is obtained<br />

b<br />

a<br />

[ U( f ; P) L( f P)<br />

]<br />

1<br />

∫ f ( x)<br />

dx ≈ + ;<br />

2<br />

6.) the error <strong>of</strong> this approximation is bounded by<br />

[ U ( f<br />

;<br />

P<br />

) L<br />

( f<br />

;<br />

P<br />

)<br />

]<br />

1<br />

−<br />

2<br />

9


Trapezoid Rule<br />

A strategy that is better than estimating both the upper and the lower<br />

bounds <strong>of</strong> the area beneath the curve is to use trapezoids<br />

The interval [a,b] is first divided into subintervals [x i ,x i+1 ], 0 ≤ i ≤ n –1. A<br />

typical trapezoid has the subinterval [x i,x i+1 1] as its base, and the two<br />

vertical sides are f(x i ) and f(x i+1 ). The area is given by the base times the<br />

average height. The basic trapezoid rule for the subinterval [x i ,x i+1 ] is<br />

x i<br />

[ f (x ) + f (x )<br />

](x<br />

− x )<br />

∫ + 1<br />

f (x) dx ≈ 1<br />

i i+<br />

1 i+<br />

x<br />

2<br />

1<br />

i<br />

The total area under the curve is<br />

b<br />

∫ f ( x)<br />

dx ≈ T(<br />

f ; P)<br />

= ∑ − a<br />

i=<br />

n<br />

1<br />

A i<br />

0<br />

i<br />

=<br />

−1<br />

1<br />

1 n ∑ ( xi+<br />

1 − xi<br />

)[ f ( xi<br />

) + f ( xi+<br />

1)]<br />

2 i=<br />

0<br />

10


Trapezoid Rule


Uniform Spacing<br />

The lengths <strong>of</strong> the subintervals in a partition can be different. For fast<br />

computation, a uniform partition <strong>of</strong> the interval may be advantageous<br />

Let n be the number <strong>of</strong> subintervals, then h = (b – a)/n is the uniform<br />

interval spacing. The nodal points are x i = a + i h, i = 0, 1,…, n. Hence<br />

the composite trapezoid rule is<br />

n<br />

∑ − 1<br />

h<br />

T(<br />

f ; P)<br />

= [ f ( xi ) + f ( x + 1<br />

2<br />

)] i<br />

2 i=0 0<br />

Note that the end point <strong>of</strong> an interval is the starting point <strong>of</strong> the next<br />

interval. This fact can save almost half <strong>of</strong> the computation,<br />

∫<br />

b<br />

a<br />

f<br />

( x)<br />

dx<br />

≈<br />

⎧<br />

h⎨<br />

⎩<br />

n−1<br />

∑<br />

i=<br />

1<br />

f<br />

( x<br />

) +<br />

1<br />

⎫<br />

[ f ( x0 ) + f ( )] ⎬<br />

2<br />

⎭<br />

i x n<br />

12


Trapezoid Rule with Uniform Spacing


Error Analysis (1)<br />

If f”(x) exists and is continuous on [a,b], the error <strong>of</strong> the composite<br />

trapezoid rule T is<br />

for some ξ in (a,b)<br />

b<br />

b−a<br />

2<br />

2<br />

∫ f ( x)<br />

dx − T = − h f "( ξ ) = O(<br />

h )<br />

12<br />

a<br />

Pro<strong>of</strong>. We first prove the result for a=0, b= 1 and h=1. That is<br />

∫<br />

1<br />

0<br />

[ 1<br />

f<br />

(0) +<br />

f<br />

(1) ] = −<br />

f "(<br />

ξ<br />

)<br />

f ( x<br />

)<br />

dx −<br />

1<br />

2<br />

+<br />

12<br />

This simplified formula will be proved with the help <strong>of</strong> polynomial<br />

interpolation<br />

Define a polynomial <strong>of</strong> degree one that interpolates f at 0 and 1<br />

p ( x<br />

)<br />

=<br />

f<br />

(0)<br />

+<br />

[<br />

f<br />

(1) −<br />

f<br />

(0<br />

)]<br />

x<br />

14


Error Analysis (2)<br />

It follows that<br />

∫<br />

1<br />

0<br />

p(<br />

x)<br />

dx<br />

=<br />

=<br />

f (0) +<br />

1<br />

2<br />

1<br />

[<br />

2<br />

[ f (0) + f<br />

f (1) −<br />

(1)]<br />

f<br />

(0)]<br />

Using the error formula for the polynomial interpolation, we have<br />

Integrate it on both sides,<br />

∫<br />

1<br />

0<br />

f(x)<br />

− p(x)<br />

=<br />

1 f"[<br />

(x)]x(x<br />

( −<br />

2<br />

ξ 1<br />

)<br />

2<br />

1<br />

1 1<br />

f ( x)<br />

dx −∫<br />

p(<br />

x)<br />

dx = ∫ f "[ ξ(<br />

x)]<br />

x(<br />

x −1)<br />

dx<br />

0<br />

2<br />

0<br />

15


Error Analysis (3)<br />

Using the Mean‐Value Theorem for Integrals<br />

So we have<br />

∫<br />

1<br />

0<br />

∫<br />

1<br />

f "[ ξ ( x)]<br />

x(<br />

x −1)<br />

dx =<br />

f "[ ξ ( s)]<br />

0 0<br />

f ( x)<br />

dx −<br />

1<br />

2<br />

[<br />

f<br />

(0)<br />

+<br />

= −<br />

We then do a change <strong>of</strong> variable, and let<br />

f<br />

1<br />

6<br />

(1)]<br />

∫<br />

1<br />

f "( ζ )<br />

=<br />

x(<br />

x −1)<br />

dx<br />

−<br />

1<br />

12<br />

f "( ζ )<br />

g( t)<br />

= f [ a + t(<br />

b − a)],<br />

x = a + ( b − a)<br />

t<br />

dx<br />

= ( b<br />

− a)<br />

dt,<br />

g'(<br />

t)<br />

'[ a<br />

g"(<br />

t<br />

) =<br />

f<br />

"[ a<br />

+<br />

t<br />

(<br />

b − a<br />

)](<br />

b − a<br />

)<br />

=<br />

f<br />

+ t(<br />

b<br />

2<br />

− a)](<br />

b<br />

−<br />

a)<br />

16


Error Analysis (4)<br />

Then using the result for the special case,<br />

∫<br />

a<br />

b 1<br />

f (x)dx<br />

=<br />

(b −<br />

a)<br />

= (b − a)<br />

=<br />

∫<br />

∫<br />

1<br />

0<br />

0<br />

f[a<br />

+<br />

t(b −<br />

a)]dt<br />

g(t)dt<br />

⎧<br />

1<br />

1<br />

⎫<br />

= (b − a) ⎨ [g( 0)<br />

+ g( 1)]<br />

− g"( ζ ) ⎬<br />

⎩2<br />

12 ⎭<br />

3<br />

b − a<br />

(b − a)<br />

[f (a)<br />

+<br />

f (b)] − f"(<br />

ξ<br />

)<br />

2<br />

12<br />

This is the error formula for the trapezoid rule with only one subinterval.<br />

Let [a,b] be divided into n equal subintervals by points<br />

x<br />

, x1,...,<br />

xn,<br />

with subinterval[<br />

xi<br />

,<br />

xi<br />

1<br />

]<br />

0 +<br />

17


Let h be the interval length<br />

Error Analysis (5)<br />

x i h<br />

∫<br />

+ f<br />

(x)dx =<br />

[f (x<br />

)<br />

+<br />

f (x<br />

x i 2<br />

1<br />

)] −<br />

h<br />

12<br />

=<br />

i i+1<br />

f"(<br />

ξ<br />

)<br />

1 3<br />

Sum over all subintervals to get the composite trapezoid rule<br />

b<br />

−1<br />

x<br />

−1<br />

−1<br />

i<br />

∫ = ∑ ∫<br />

+ 1<br />

f ( x)<br />

dx f ( x)<br />

x = ∑ [ f ( xi<br />

) + f ( xi<br />

+ 1)]<br />

− ∑<br />

a<br />

n<br />

i=<br />

0<br />

x<br />

i<br />

h<br />

2<br />

n<br />

i=<br />

0<br />

3<br />

h<br />

12<br />

n<br />

i=<br />

0<br />

f "( ξ )<br />

i<br />

Note that h=(b-a)/n, we use Intermediate-Value Theorem <strong>of</strong> Continuous<br />

Functions,<br />

3 1<br />

1<br />

h n −<br />

n−<br />

b − a 2 ⎡1<br />

− ∑ f "( ξi<br />

) = − h<br />

12 i<br />

12<br />

⎢ ∑<br />

= 0 ⎣n<br />

i<br />

=<br />

0<br />

⎤<br />

f "( ξi<br />

) ⎥ ⎦<br />

i i ⎦<br />

= −<br />

b − a<br />

12<br />

h<br />

2<br />

f<br />

"( ζ )<br />

18


Example 1<br />

Show that<br />

a<br />

h<br />

∫<br />

+ f ( x)<br />

dx<br />

a<br />

h<br />

2<br />

=<br />

3<br />

h<br />

[ f a)<br />

+ f ( a + h)<br />

] − f "( a)<br />

+ L<br />

(<br />

12<br />

Need to define<br />

F ( t)<br />

f ( x)<br />

= ∫<br />

t a<br />

We can expand F(a+h) using Taylor series<br />

dx<br />

2<br />

3<br />

h h<br />

F<br />

( a+ h<br />

) = F<br />

( a<br />

) + hF'(<br />

a<br />

) + F"(<br />

a<br />

) + F"'(<br />

a<br />

) +L<br />

2 3!<br />

Then by the Fundamental Theorem <strong>of</strong> Calculus, we have F’(t) = f(t).<br />

Note that F(a) = 0, F”(t)=f’(t), F”’(t)=f”(t), and so on.<br />

19


We have<br />

Example 2<br />

+ 2<br />

3<br />

a h<br />

h h<br />

∫ f<br />

( x<br />

) dx = hf<br />

( a<br />

) +<br />

f '(<br />

a<br />

) +<br />

f "(<br />

a<br />

) +L<br />

3!<br />

(1)<br />

a<br />

2<br />

We can also apply the Taylor series directly on f(t) as<br />

2<br />

3<br />

(2)<br />

h h<br />

f<br />

( a<br />

+ h<br />

) =<br />

f<br />

( a<br />

)<br />

+<br />

hf<br />

'( a<br />

)<br />

+<br />

f<br />

"( a<br />

)<br />

+<br />

f<br />

"'( a<br />

)<br />

+L<br />

2 3!<br />

Adding f(a) on both sides <strong>of</strong> (2) and multiplying it by h/2, we obtain<br />

(3)<br />

h<br />

[<br />

2<br />

2<br />

3<br />

h<br />

h<br />

f ( a)<br />

+ f ( a+<br />

h)]<br />

= hf(<br />

a)<br />

+ f '( a)<br />

+ f "( a)<br />

+L<br />

2 4<br />

Subtracting (3) from (1), we finally get<br />

a<br />

∫ + h h<br />

1 3<br />

f ( x)<br />

dx−<br />

[ f ( a)<br />

+ f ( a+<br />

h)]<br />

=− h f"(<br />

a)<br />

+L<br />

a<br />

2<br />

12<br />

20


Estimate Grid Spacing<br />

Example. If the composite trapezoid rule is used to compute<br />

1 2<br />

−<br />

∫ 0<br />

e x<br />

dx<br />

with an error <strong>of</strong> at most 0.5 × 10 -4 , what is the uniform grid spacing h?<br />

From the graph <strong>of</strong> the second derivative (a decreasing function)<br />

f "( x)<br />

= (4x<br />

2 − x<br />

− 2) e<br />

2<br />

We find that<br />

f "(<br />

x)<br />

≤ f "(0) =<br />

2<br />

We need<br />

−<br />

b − a<br />

12<br />

h<br />

2<br />

f "( ξ )<br />

≤<br />

1<br />

6<br />

h<br />

2<br />

<<br />

0.5×<br />

10<br />

−4<br />

It follows that h ≤ 0.01732. The number <strong>of</strong> subintervals is n ≥ [1/h] = 58<br />

21


Recursive Trapezoid Idea<br />

What can we do if the initial partition <strong>of</strong> interval is not fine enough?<br />

22


Recursive Trapezoid Formula<br />

Given a parameter n, dividing [a,b] into 2 n equally spaced subintervals, we<br />

have<br />

n 1<br />

h<br />

T(<br />

f ; P)<br />

= h f ( xi ) + [ f ( x0 ) + f ( x n )]<br />

2<br />

∑ −<br />

i=<br />

1<br />

n<br />

= h∑ − f ( a + i h)<br />

+ [ f ( a)<br />

+ f ( b)<br />

]<br />

i=<br />

1<br />

2<br />

Note that n = 2 n and h = (b – a)/2 n<br />

Note that n 2 and h (b a)/2<br />

R(<br />

n,0)<br />

=<br />

h<br />

n<br />

2<br />

∑ − 1<br />

i=<br />

1<br />

1<br />

f ( a +<br />

h<br />

h<br />

i h)<br />

+<br />

2<br />

[ f ( a)<br />

+ f ( b)<br />

]<br />

Notice that R(n,0) can be viewed as dividing each subinterval <strong>of</strong><br />

R(n –1,0)into two equal sub‐subintervals. If we already computed<br />

R(n –1,0), how can we compute R(n,0) cheaply?<br />

23


Recursive Formula<br />

If R(n –1,0)is available, R(n,0) can be computed as<br />

R(n, 0)<br />

1<br />

= R(n −1,<br />

0)<br />

+ h<br />

2<br />

n−<br />

2<br />

1<br />

∑<br />

For n ≥ 1 using h = (b – a)/2 n . Initial starting value is<br />

−<br />

1<br />

k=<br />

1<br />

f[a + ( 2k<br />

−1)h]<br />

1<br />

R ( 0,<br />

0)<br />

= 2<br />

(b − a)[f (a) + f (b)]<br />

The trick is to only sum the function values at every other grid points<br />

Pro<strong>of</strong>. Note that<br />

R<br />

(<br />

n,0)<br />

=<br />

h<br />

2<br />

n<br />

1<br />

∑<br />

− f<br />

(<br />

a<br />

+<br />

i<br />

h<br />

)<br />

+<br />

C<br />

i=<br />

1<br />

with C = h[f(a) + f(b)]/2 and<br />

R(<br />

n − 1,0) = 2h<br />

−<br />

2<br />

n 1<br />

∑ − 1<br />

f ( a + 2 j h)<br />

+ 2C<br />

j=<br />

1<br />

24


Recursive Formula<br />

Hence, we have<br />

R(<br />

n,0)<br />

−<br />

1<br />

2<br />

R(<br />

n −1,0)<br />

=<br />

h<br />

n<br />

n−11<br />

2 −<br />

1<br />

2 −<br />

1<br />

∑<br />

i=<br />

1<br />

f ( a + ih)<br />

− h<br />

∑<br />

j=<br />

1<br />

f<br />

( a + 2<br />

jh)<br />

=<br />

h<br />

Each term in the first sum that corresponds to an even value <strong>of</strong> l is<br />

cancelled by a term in the second term. The final result has only the odd<br />

values <strong>of</strong> l<br />

2<br />

n−1<br />

∑<br />

k = 1<br />

f [ a + (2k<br />

−1)<br />

h]<br />

We can use the recursive trapezoid formula to compute a sequence <strong>of</strong><br />

approximations to a definite integral using the trapezoid rule, without<br />

recomputing the values at points that have already been computed in the<br />

previous step<br />

25


Two Dimensional Integration<br />

For one dimensional numerical integration on [0,1], using uniform space<br />

h = 1/n<br />

n−1<br />

1 1<br />

⎛ i ⎞<br />

∫<br />

f<br />

(<br />

x<br />

)<br />

dx<br />

≈<br />

[<br />

f<br />

(0)<br />

+<br />

2<br />

∑<br />

f<br />

⎜<br />

⎟ +<br />

f<br />

(1)]<br />

0<br />

2h<br />

⎝ n ⎠<br />

i=<br />

1<br />

n<br />

⎛ i ⎞<br />

= ∑ Ai<br />

f ⎜ ⎟<br />

i= 0<br />

⎝<br />

n<br />

⎠<br />

For two dimensional integration on a unit square<br />

1 1<br />

∫ ∫<br />

0 0<br />

f<br />

(<br />

x<br />

,<br />

y<br />

)<br />

dx<br />

dy ≈<br />

=<br />

≈<br />

1<br />

n<br />

∫ ∑<br />

0<br />

i=<br />

1<br />

n<br />

∑<br />

i<br />

=<br />

0<br />

n<br />

∑<br />

i=<br />

0<br />

= n<br />

A<br />

A<br />

n<br />

A<br />

i<br />

∑∑<br />

i= 0 j=<br />

0<br />

∫<br />

i<br />

1<br />

0<br />

n<br />

∑<br />

i<br />

j=<br />

0<br />

A<br />

⎛ i<br />

f<br />

⎜<br />

,<br />

⎝ n<br />

i<br />

f<br />

⎛ ⎜<br />

⎝<br />

A<br />

A<br />

j<br />

j<br />

i<br />

n<br />

f<br />

f<br />

⎞<br />

y<br />

⎟<br />

dy<br />

⎠<br />

⎞<br />

, y⎟<br />

dy<br />

⎠<br />

⎛<br />

⎜<br />

⎝<br />

⎛<br />

⎜<br />

⎝<br />

i<br />

n<br />

i<br />

n<br />

,<br />

,<br />

j<br />

n<br />

j<br />

n<br />

⎞<br />

⎟<br />

⎠<br />

⎞<br />

⎟<br />

⎠<br />

26


Romberg Algorithm<br />

Recursive composite trapezoid method<br />

For h = 1/2 n and n ≥ 1<br />

1 R ( 0,0) 0)<br />

=<br />

(<br />

b<br />

−<br />

a<br />

)[<br />

f<br />

(<br />

a<br />

)<br />

+<br />

f<br />

(<br />

b<br />

)]<br />

2<br />

n−<br />

1<br />

R(n, 0)<br />

=<br />

2<br />

Using Richardson extrapolation, we can have<br />

2 1 − 1<br />

R(n −1,<br />

0)<br />

+ h ∑f[a<br />

+ ( 2k<br />

−1<br />

2 k=1<br />

R(<br />

i,<br />

j)<br />

= R(<br />

i,<br />

j − 1)<br />

+ −<br />

j<br />

1<br />

j<br />

[ R(<br />

i,<br />

j − 1) − R(<br />

i − 1, −<br />

4 1<br />

For i ≥ j and j ≥ 1. This is the Romberg algorithm, which may yield better<br />

approximate values for larger j<br />

1)]<br />

)h]<br />

27


Deriving Romberg Algorithm<br />

Composite trapezoid rule on 2 n-1 subintervals<br />

∫<br />

b<br />

a<br />

f<br />

( x<br />

)<br />

dx =<br />

R<br />

( n −<br />

1,0)<br />

+ a<br />

h<br />

+ a<br />

h<br />

+ a<br />

h<br />

2<br />

4<br />

6<br />

+ L<br />

with h = (b – a)/2 n-1 and the coefficients a i depend on f but not on h<br />

After one refinement and replacing n –1 with n and h with h/2, we have<br />

b<br />

a<br />

∫ f ( x)<br />

dx<br />

=<br />

1 1<br />

1<br />

R( n,0)<br />

+ a h + a h + a h<br />

4<br />

2<br />

Subtracting the 1 st equation from 4 times the 2 nd equation<br />

where for n ≥ 1<br />

∫<br />

R<br />

a<br />

b<br />

2<br />

16<br />

2<br />

4<br />

4<br />

1<br />

4<br />

4<br />

64<br />

4<br />

6<br />

6<br />

16<br />

6<br />

+ L<br />

4 5<br />

f (x) dx = R(n, 1)<br />

− a h − a h<br />

1<br />

( n,1)<br />

= R(<br />

n,0)<br />

+ [ R(<br />

n,0)<br />

− R(<br />

n −<br />

3<br />

6<br />

6<br />

1,0)]<br />

+L<br />

28


More Romberg Algorithm<br />

We could apply the extrapolation idea repeatedly to get<br />

where<br />

∫<br />

b<br />

a<br />

1 6 21<br />

f ( x)<br />

dx = R(<br />

n,2)<br />

+ a h + a h<br />

4<br />

3<br />

6<br />

4<br />

5<br />

8<br />

8<br />

+L<br />

1<br />

R( n,2)<br />

= R(<br />

n,1)<br />

+<br />

15<br />

[ R(<br />

n,1)<br />

− R(<br />

n −1,1)]<br />

This time, the truncation error is <strong>of</strong> sixth order<br />

A few steps <strong>of</strong> extrapolation may generate very accurate<br />

approximations<br />

Too many extrapolations may make the computation tedious<br />

29


General Extrapolation<br />

Extrapolation processes can be applied in more general cases where the error<br />

term can be represented as<br />

E<br />

=<br />

a<br />

h<br />

α<br />

+ b h<br />

β<br />

+ c h<br />

γ<br />

+ L<br />

with 0 < α < β < γ, we show how the first term <strong>of</strong> the error expansion is<br />

annihilated. Let<br />

α β γ<br />

L = φ( h)<br />

+ a h + b h + c h + L (1)<br />

Replacing h by h/2 yields<br />

h<br />

h α<br />

h β<br />

h γ<br />

L = φ ( ) +<br />

a<br />

( ) +<br />

b<br />

( ) +<br />

c<br />

( ) + L<br />

(2<br />

)<br />

2 2 2 2<br />

Multiplying (2) by 2 α<br />

α<br />

α<br />

h α α h β α h γ<br />

( ) + a h + 2 b ( ) + 2 c ( ) + (3)<br />

2 L = 2 φ<br />

2<br />

2<br />

2<br />

L<br />

30


General Extrapolation – Cont.<br />

Subtracting the previous two equations, we can remove the h α term<br />

α<br />

α<br />

⎛ h⎞<br />

⎞<br />

(2 − 1) L = 2 φ⎜<br />

⎟ − φ(<br />

h)<br />

⎝ 2 ⎠<br />

+ (2<br />

α −β<br />

− 1) b h<br />

β<br />

+ (2<br />

α −γ<br />

We can write the new approximation formula as<br />

α<br />

2 ⎛ h⎞<br />

1<br />

L = φ⎜<br />

⎟ − φ(<br />

h)<br />

+ bh<br />

α<br />

α<br />

2 − 1<br />

⎝<br />

2<br />

⎠<br />

2 −<br />

1<br />

− 1) c h<br />

β<br />

γ<br />

+ ch<br />

+ L<br />

γ<br />

+ L<br />

This approximation formula raises the order <strong>of</strong> truncation error from<br />

O(h α ) to O(h β ) with α < β<br />

Please read the book on p. 217 for a concrete example to show how the<br />

approximation accuracy is improved using extrapolation<br />

31


Basic Simpson’s Rule<br />

Simple trapezoid rule uses two points for approximations<br />

Can we get more accurate approximation using more points?<br />

32


Basic Simpson’s Rule<br />

A three point numerical integration rule using the middle point <strong>of</strong> the<br />

interval is known as the Simpson’s s rule with different weights for each point<br />

a<br />

a<br />

2h<br />

[ f ( a)<br />

+ 4 f ( a + h)<br />

+ f ( a 2h<br />

]<br />

∫ + h<br />

f ( x)<br />

dx ≈<br />

+<br />

3<br />

)<br />

Using Taylor’s expansion, we can find the error term <strong>of</strong> this approximation<br />

is<br />

5<br />

h (4)<br />

− f ( ξ )<br />

90<br />

For some point ξ in (a,a+2h). This should be compared to the error term <strong>of</strong><br />

the simple trapezoid rule O(h 3 )<br />

It is desirable to subdivide the interval adaptively so that refinement is only<br />

placed in the area <strong>of</strong> large fluctuation <strong>of</strong> function value<br />

33


Basic Simpson’s Rule<br />

Comparing composite trapezoid rule and Simpson’s rule<br />

34


Basic Simpson’s Rule<br />

Using Taylor series for f(x) at a, we have<br />

1 2<br />

1 3<br />

1 4 (4)<br />

f(<br />

a+ h)<br />

= f(<br />

a)<br />

+ hf'(<br />

a)<br />

+ h f"(<br />

a)<br />

+ h f"'(<br />

a)<br />

+ h f ( a)<br />

+L<br />

2! 3! 4!<br />

If we replace the interval size h by 2h, we obtain<br />

4<br />

2 4<br />

3 2<br />

4<br />

(4)<br />

f<br />

( a+ 2 h<br />

) =<br />

f<br />

( a<br />

) +<br />

2<br />

hf<br />

'( a<br />

) +<br />

2<br />

h<br />

f<br />

"( a<br />

) +<br />

h F<br />

"'( a<br />

) +<br />

h<br />

f<br />

( a<br />

) +L<br />

3 4!<br />

By combining these two expansions, we get<br />

2<br />

3 20 4 (4)<br />

f(<br />

a)<br />

+ 4f(<br />

a+<br />

h)<br />

+ f(<br />

a+<br />

2 h)<br />

= 6f(<br />

a)<br />

+ 6hf'(<br />

a)<br />

+ 4h<br />

f"(<br />

a)<br />

+ 2h<br />

f"'(<br />

a)<br />

+ h f ( a)<br />

+L<br />

4!<br />

35


On the other hand, define<br />

We expand F(a+2h) as<br />

Basic Simpson’s Rule<br />

F (<br />

x<br />

)<br />

= x f<br />

(<br />

t<br />

)<br />

dt<br />

a<br />

∫<br />

5<br />

2 4<br />

3 2<br />

4<br />

(4) 2<br />

5<br />

(5)<br />

F ( a<br />

+ 2 h<br />

) =<br />

F ( a<br />

)<br />

+<br />

2<br />

hF '( a<br />

)<br />

+<br />

2<br />

h F<br />

"( a<br />

)<br />

+<br />

h F<br />

"'( a<br />

)<br />

+<br />

h<br />

f<br />

( a<br />

)<br />

+<br />

h F<br />

( a<br />

)<br />

+L<br />

3 3 5!<br />

Note that F’=f, F(a)=0, F”=f’, F”’=f”, we have<br />

∫ + 5<br />

a 2h<br />

2 4 3 2 4 2 5 (4)<br />

f(<br />

x)<br />

dx=<br />

2hf(<br />

a)<br />

+ 2h<br />

f'(<br />

a)<br />

+ h f"(<br />

a)<br />

+ h f"'(<br />

a)<br />

+ h f ( a)<br />

+L<br />

a<br />

3 3 5⋅4!<br />

From the previous page, we have<br />

h<br />

[ f ( a)<br />

+ 4 f ( a + h)<br />

+ f ( a + 2h)]<br />

=<br />

3<br />

2 4 3<br />

2hf<br />

( a)<br />

+ 2h<br />

f '(<br />

a)<br />

+ h f "( a)<br />

3<br />

+ 2 4 20 5 (4<br />

h f "'(<br />

a)<br />

+ h f<br />

) ( a)<br />

+L<br />

3 3⋅<br />

4!<br />

36


Basic Simpson’s Rule (1)<br />

Subtracting the previous two terms, we have<br />

a<br />

∫ + 2h<br />

a<br />

5<br />

h<br />

h (4)<br />

f ( x)<br />

dx=<br />

[ f ( a)<br />

+ 4f<br />

( a+<br />

h)<br />

+ f ( a+<br />

2h)]<br />

− f −L<br />

3<br />

90<br />

We have the Simpson’s rule as<br />

a<br />

+ 2h<br />

b−a<br />

⎛ a+<br />

b⎞<br />

∫<br />

f ( x ) dx≈<br />

[<br />

f<br />

( a<br />

) + 4<br />

f<br />

⎜<br />

⎟+<br />

f<br />

( b<br />

)]<br />

a<br />

6<br />

⎝ 2<br />

⎠<br />

The error term <strong>of</strong> the Simpson’s rule us<br />

5<br />

1 (4)<br />

⎛b−a⎞<br />

− ⎜ ⎟ 90 ⎝<br />

2<br />

⎠<br />

f<br />

( ξ)<br />

37


Adaptive Simpson’s Algorithm<br />

Reduce the size <strong>of</strong> the intervals to get more accurate approximations<br />

38


Adaptive Simpson’s Algorithm<br />

Given an interval [a,b], we can use the basic Simpson’s rule to compute<br />

an approximation to the integral as<br />

where the approximation part is<br />

I ∫ f ( x)<br />

dx = S(<br />

a,<br />

b)<br />

+ E(<br />

a,<br />

b)<br />

≡ b a<br />

( b − a)<br />

⎡ ⎛ a + b ⎞ ⎤<br />

S( a,<br />

b)<br />

= ⎢ f ( a)<br />

+ 4 f ⎜ ⎟ + f ( b)<br />

6<br />

⎥<br />

⎣ ⎝ 2 ⎠ ⎦<br />

and the error term is<br />

E(<br />

a,<br />

b)<br />

= −<br />

b−a<br />

5 (4)<br />

( ) f ( )<br />

1<br />

ξ<br />

90 2<br />

For simplicity, we assume f (4) (x) remains constant on (a,b). Let h = b – a,<br />

we have<br />

(1) (1)<br />

I = S + E<br />

For the first step approximation with<br />

(1)<br />

S = S(<br />

a,<br />

b)<br />

39


Adaptive Simpson – (II)<br />

And<br />

E<br />

(1)<br />

=<br />

−<br />

1 ⎛ h⎞<br />

⎜<br />

⎟<br />

90<br />

⎝<br />

2<br />

⎠<br />

5<br />

f<br />

(4)<br />

We then subdivide the interval [a,b] and apply the basic Simpson’s rule<br />

on the subintervals [a,c] and [c,b] respectively. We have a new<br />

approximation on [a,b] as the sum <strong>of</strong> two separate approximations<br />

where c = (a + b)/2 with<br />

(2)<br />

(2)<br />

I = S +<br />

S = S(<br />

a,<br />

c)<br />

+<br />

E<br />

(2)<br />

S(<br />

c,<br />

b)<br />

and<br />

5<br />

5<br />

(2) 1 ⎛ h / 2 ⎞ (4) 1 ⎛ h / 2 ⎞ (4) 1 (1)<br />

E = − ⎜ ⎟ f − ⎜ ⎟ f = E<br />

90 ⎝ 2 ⎠ 90 ⎝ 2 ⎠ 16<br />

This is certainly til a better btt approximation since the subintervals are smaller<br />

than the original interval<br />

20


Adaptive Simpson – (III)<br />

Subtracting the two approximations yields<br />

(2)<br />

(1)<br />

(1)<br />

(2)<br />

S −<br />

S<br />

=<br />

E −<br />

E<br />

=<br />

15E<br />

Hence the numerical integration can be<br />

(2)<br />

(2)<br />

(2)<br />

I =<br />

S<br />

+<br />

E =<br />

S<br />

+<br />

(2)<br />

(2)<br />

1<br />

(<br />

S −<br />

S<br />

15<br />

The error term is then computable and can be used for building the<br />

adaptive process<br />

1<br />

(2)<br />

(1)<br />

S − S < ε<br />

15<br />

If this test shows that the error is larger than ε, the interval [a,b] can be<br />

split into two subintervals [a,c] and [c,b] with c = (a + b)/2. The<br />

previously described procedure is replaced by ε/2 to make sure that the<br />

error sum is smaller than ε<br />

(1)<br />

)<br />

41


Adaptive Simpson’s Algorithm<br />

Refine the intervals at the places where the function changes quickly<br />

42


Adaptive Simpson – (IV)<br />

Numerical integration on subintervals<br />

b<br />

c<br />

b<br />

I = ∫ f (x) dx = ∫ f (x) dx + ∫ f (x) dx = IL<br />

+ I<br />

a<br />

(2)<br />

L<br />

a<br />

Let S be thesum<strong>of</strong> S on[<br />

a,c]<br />

and S on[<br />

c,b]<br />

,wehave<br />

I<br />

If we want to have<br />

−<br />

S<br />

=<br />

I<br />

I<br />

L<br />

L<br />

1<br />

15<br />

It is more than enough to have<br />

and<br />

≤<br />

=<br />

S<br />

+<br />

I<br />

−<br />

R<br />

(2)<br />

S L<br />

(2)<br />

L −<br />

−<br />

I<br />

S<br />

− S<br />

c<br />

(2)<br />

R<br />

S<br />

+<br />

(1)<br />

L<br />

(2)<br />

L<br />

I<br />

R<br />

+<br />

≤ ε<br />

−<br />

+<br />

1<br />

15<br />

S<br />

S<br />

1 (2) (1)<br />

S − ≤<br />

ε<br />

15 L S L 2<br />

1 (2)<br />

(1)<br />

S −<br />

≤<br />

ε<br />

15 R S R 2<br />

(2)<br />

R<br />

(2)<br />

R<br />

(2)<br />

R<br />

S<br />

−<br />

S<br />

(1)<br />

R<br />

R<br />

43


Adaptive Simpson’s Algorithm<br />

One decision to make is to choose where to refine the interval<br />

44


Computational Procedure<br />

The interval [a,b] is divided into four subintervals <strong>of</strong> equal length. Two<br />

Simpson approximations are computed using two double‐width subintervals<br />

and four single‐width subintervals<br />

S<br />

S<br />

1<br />

=<br />

h<br />

⎡<br />

⎛ a<br />

+<br />

b<br />

⎞<br />

⎢ f ( a)<br />

+ 4 f<br />

⎜<br />

⎟ +<br />

6 ⎣ ⎝ 2 ⎠<br />

h ⎡<br />

=<br />

12<br />

⎢<br />

⎣<br />

⎤<br />

f ( b)<br />

⎥<br />

⎦<br />

⎛ a + c ⎞<br />

⎛ c + b ⎞<br />

f<br />

( a<br />

) + 4<br />

f<br />

⎜<br />

⎟ + 2<br />

f<br />

( c<br />

) + 4<br />

f<br />

⎜<br />

⎟ +<br />

⎝<br />

2<br />

⎠<br />

⎝<br />

2<br />

⎠<br />

2 f<br />

⎤<br />

( b<br />

)<br />

⎥<br />

⎦<br />

If |S 2 -S 1 | ≤15ε, we have done, and set<br />

1<br />

S =<br />

[ 16<br />

S2<br />

−<br />

S1<br />

]<br />

15<br />

Otherwise the interval [a,b] is divided in half and the recursive procedure is<br />

applied on the two subintervals [a,c] and [c,b], until either the error tolerance<br />

is satisfied or the maximum number <strong>of</strong> subdivisions is reached<br />

45


Adaptive Simpson’s Algorithm<br />

Which sub‐interval or both to divide for refinement<br />

46


Gaussian Quadrature Formulas<br />

A general numerical integration formula is<br />

∫<br />

b<br />

a<br />

f x<br />

) dx ≈ A<br />

f<br />

( x<br />

) + A<br />

f<br />

( x<br />

) + L+<br />

( 0 0<br />

1<br />

1 A<br />

n<br />

f<br />

( x<br />

n<br />

It suffices to know the nodes x 0 , x 1 ,…, x n and the weights A 0 , A 1 ,…, A n .<br />

For important special functions, they are listed in some reference books<br />

Suppose a set <strong>of</strong> nodes is given, how to find the weights. This can be<br />

done using Lagrange interpolation polynomial as<br />

n<br />

p(<br />

x)<br />

= f ( x ) l ( x)<br />

With<br />

l<br />

(<br />

x<br />

)<br />

i<br />

=<br />

∑<br />

i=<br />

0<br />

n<br />

∏<br />

j=<br />

o,<br />

j≠1<br />

⎛<br />

⎜<br />

⎝<br />

i<br />

i<br />

i<br />

x −<br />

x − x<br />

x i<br />

j<br />

⎟⎞<br />

⎟<br />

⎠<br />

)<br />

If p is a good approximate to f, we anticipate<br />

approximate to ∫ b f ( x<br />

) dx<br />

a<br />

∫ b a<br />

p ( x)<br />

dx<br />

is a good<br />

47


We integrate over p(x) as<br />

∫<br />

b<br />

a<br />

f ( x<br />

)<br />

dx ∫ p<br />

( x<br />

)<br />

dx<br />

where we can compute<br />

Gaussian Quadrature<br />

b<br />

≈ ∫ a<br />

n<br />

n<br />

b<br />

= ∑ f ( xi<br />

) ∫ l =<br />

a i ( x)<br />

dx ∑<br />

i=<br />

0<br />

i=<br />

1<br />

i<br />

∫<br />

= b l<br />

a i<br />

A ( x)<br />

dx<br />

A<br />

i<br />

f ( x<br />

Note that the polynomial interpolation is exact for a polynomial <strong>of</strong><br />

degree at most n. It follows that the integration will be exact for such<br />

polynomials<br />

If the nodes can be chosen carefully, it is possible to increase the order<br />

<strong>of</strong> polynomial with the exact integration remarkably. This was<br />

discussed by Karl Gauss<br />

i<br />

)<br />

48


An Example<br />

Determine a quadrature formula when the interval is [‐2,2] and the<br />

nodes are ‐1, 0, and 1.<br />

We first need to compute the cardinal functions<br />

2 ⎛ x − x ⎞<br />

j 0 1 1<br />

( ) ⎜ ⎟<br />

⎛ x − ⎞⎛<br />

x − ⎞<br />

l0 x = ∏ = ⎜ ⎟⎜ ⎟ = x(<br />

x −1)<br />

j<br />

=<br />

1 ⎝ x<br />

0<br />

− x<br />

j<br />

⎠<br />

⎝<br />

( −1)<br />

− 0<br />

⎠⎝<br />

−1−1<br />

⎠ 2<br />

2 ⎛ x − x ⎞<br />

j ⎛ x + 1 ⎞⎛<br />

x −1⎞<br />

1 2<br />

l ( x)<br />

= ∏⎜<br />

⎟ = ⎜ ⎟ ⎟ = − x<br />

1 ⎜<br />

j 1 x1<br />

x<br />

= ⎝ −<br />

j ⎠ ⎝ 0 − ( −1)<br />

⎠⎝<br />

0 −1⎠<br />

2 ⎛ x − x ⎞<br />

1) ⎞<br />

− 0<br />

1<br />

⎛ x − ( −<br />

⎛ x ⎞<br />

2<br />

( ) = ∏ ⎜ j<br />

l x<br />

⎟ =<br />

⎜<br />

⎟<br />

⎜<br />

⎟ = x<br />

( x<br />

+<br />

1)<br />

j=<br />

1 ⎝ x2<br />

− x<br />

j ⎠ ⎝ 1−<br />

( −1)<br />

⎠⎝<br />

1−<br />

0 ⎠ 2<br />

The weights are computed by integrating these functions<br />

A<br />

2<br />

2 1 2<br />

1<br />

⎡1<br />

3 1 2<br />

⎤<br />

= ∫ l ( x)<br />

dx = ( −1)<br />

=<br />

=<br />

0 2 0<br />

2<br />

2<br />

2 ⎢<br />

−<br />

− ∫ x x dx x x<br />

−<br />

⎣3<br />

2 ⎥<br />

⎦ −2<br />

8<br />

3<br />

49


Similarly, we have<br />

A<br />

An Example<br />

2 2<br />

2<br />

2<br />

1<br />

3<br />

( )<br />

(1 )<br />

⎤<br />

1 2 1<br />

2 ⎢<br />

⎡ = ∫ l x dx = − = − =<br />

3 ⎥<br />

⎣ ⎦<br />

−<br />

− ∫ x dx x x<br />

−<br />

−2<br />

2<br />

=<br />

2<br />

2 1 2<br />

1 ⎡1<br />

3 1 2 ⎤<br />

A = ∫ l<br />

( x<br />

) dx =<br />

+ 1) =<br />

x(<br />

x<br />

dx<br />

x + x<br />

2 2 2<br />

2<br />

2<br />

2<br />

⎢<br />

⎣<br />

3<br />

2<br />

⎥ − ∫ −<br />

⎦<br />

So the quadrature formula defined on the interval [‐2,2] and using the<br />

node ‐1, 0, 1, is<br />

2<br />

∫ − 2<br />

8<br />

4<br />

8<br />

f ( x)<br />

dx≈<br />

f ( −1)<br />

− f (0) +<br />

3 3 3<br />

f (1)<br />

It can be verified that this formula gives exact values for the three<br />

functions<br />

2<br />

f ( x)<br />

= 1, x,<br />

x<br />

−2<br />

8<br />

3<br />

4<br />

3<br />

50


Gaussian Quadrature Theorem<br />

Let q be a nontrivial polynomial <strong>of</strong> degree n + 1 such that<br />

∫<br />

b<br />

a<br />

x<br />

k<br />

q( x)<br />

dx = 0 (0 ≤ k ≤ n)<br />

Let x 0 , x 1 ,…, x n be zeroes <strong>of</strong> q. Then we define the formula<br />

b<br />

∑<br />

∫<br />

f<br />

(<br />

x<br />

)<br />

dx ≈<br />

A i<br />

f<br />

(<br />

x i<br />

),<br />

A i<br />

=<br />

∫<br />

l<br />

(<br />

x<br />

)<br />

dx<br />

a<br />

≈ n<br />

i=<br />

0<br />

With these x i ’s as nodes, the approximation will be exact for all<br />

polynomials <strong>of</strong> degree at most 2n+1. All these nodes lie in the open<br />

interval (a,b)<br />

We can first figure out the quadrature for<br />

∫<br />

1<br />

−1<br />

f<br />

( t<br />

)<br />

dt ≈<br />

Then use the transformation t = [2x –(b – a)]/(b – a) for a Gaussian<br />

quadrature on the general interval [a,b]<br />

n<br />

∑<br />

i=<br />

0<br />

A<br />

f<br />

(<br />

i t i<br />

)<br />

b<br />

a i<br />

51


The transformed integral is<br />

∫ a f ( x<br />

) dx<br />

∫ b<br />

=<br />

Gaussian Theorem Pro<strong>of</strong><br />

1<br />

[<br />

1<br />

1<br />

( b − a)<br />

∫ −<br />

f ( b − a)<br />

t + ( b + a ]dt<br />

1 2<br />

1 2<br />

2<br />

)<br />

Pro<strong>of</strong> <strong>of</strong> Gaussian Quadrature Theorem:<br />

Let f be any polynomial <strong>of</strong> degree at most (2n +1) 1). Dividing f by q with<br />

quotient p and a remainder r<br />

f = p q +<br />

Both q and r are <strong>of</strong> degree at most n<br />

r<br />

By hypothesis, we have<br />

∫ b a<br />

Since x i are roots <strong>of</strong> q, we have<br />

q( x)<br />

p(<br />

x)<br />

dx =<br />

f ( xi<br />

) = p(<br />

xi<br />

) q(<br />

xi<br />

) + r(<br />

xi<br />

) = r(<br />

xi<br />

)<br />

0<br />

52


Gaussian Theorem Pro<strong>of</strong> (II)<br />

Since the degree <strong>of</strong> r is at most n, the integration<br />

∫ b a<br />

r ( x)<br />

dx<br />

is exact<br />

∫<br />

b<br />

a<br />

f ( x)<br />

dx<br />

=<br />

∫<br />

b<br />

a<br />

=<br />

∫<br />

r<br />

(<br />

x<br />

)<br />

dx<br />

b<br />

a<br />

p(<br />

x)<br />

q(<br />

x)<br />

dx +<br />

=<br />

n<br />

∑<br />

A r<br />

(<br />

x<br />

)<br />

=<br />

∫<br />

b<br />

a<br />

n<br />

∑<br />

i<br />

i<br />

i= 0 i=<br />

0<br />

r(<br />

x)<br />

dx<br />

A<br />

i<br />

f<br />

(<br />

x<br />

Gaussian Quadrature Theorem guarantees high accuracy numerical<br />

integration with just a few nodes. However, finding these nodes is not an<br />

easy task. The roots <strong>of</strong> Legendre polynomials are the nodes for Gaussian<br />

quadrature on the interval [-1,1]. With q 0 (x) = 1, q 1 (x) = x, we have for<br />

n ≥ 2<br />

q<br />

n<br />

⎛ 2n<br />

− 1⎞<br />

⎛ n − 1⎞<br />

( x)<br />

= ⎜ ⎟xqn−1(<br />

x)<br />

− ⎜ ⎟qn−2(<br />

x)<br />

⎝ n ⎠ ⎝ n ⎠<br />

i<br />

)<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!