0% found this document useful (0 votes)
92 views9 pages

Chapter 2. Numerical Integration: 2.1. Taylor Series

The document describes numerical integration techniques, including: 1) The trapezoidal rule, which approximates the integral of a function over an interval by using linear approximations within subintervals. 2) Richardson extrapolation, which uses integration results from multiple subinterval lengths to extrapolate a more accurate approximation. 3) Romberg integration, which is a type of Richardson extrapolation that systematically improves the approximation accuracy through recursive applications of the technique.

Uploaded by

Chris Lem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views9 pages

Chapter 2. Numerical Integration: 2.1. Taylor Series

The document describes numerical integration techniques, including: 1) The trapezoidal rule, which approximates the integral of a function over an interval by using linear approximations within subintervals. 2) Richardson extrapolation, which uses integration results from multiple subinterval lengths to extrapolate a more accurate approximation. 3) Romberg integration, which is a type of Richardson extrapolation that systematically improves the approximation accuracy through recursive applications of the technique.

Uploaded by

Chris Lem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

1

Chapter 2. Numerical Integration

2.1. Taylor Series

Function y ( x) can be expanded over a small interval t using the Taylor series
from a start or reference point x
1 2 1 1
y ( x t ) y ( x) ty ( x) t y ( x) t 3 y ( x ) t 4 y ( 4 ) ( x) (2.1.1)
2! 3! 4!

This forms an approximation to y in t which runs, say, from xi to xi 1 , and


can be used to integrate y (t ) . For example, if we keep the first four terms on the r.h.s.
of the above series in an integration, we get

I
h h 1 1
ydt y ty t 2 y t 3 y O t 4 y ( 4 )
2! 3!
dt
0 0

(2.1.2)

2 3 4
h h h
hy y y y O h 5 y ( 4 )
2 6 24

where hi xi 1 xi = h, a constant. Alternatively, by setting t to h in the Taylor


series, we may also approximate the first derivative

y ( x)
1
y ( x h) y ( x) O(hy ) yi ' yi 1 yi O(hy ) (2.1.3)
h h

The last expression, a first forward finite difference, will be used to complete the
trapezoid rule below. Note that it is only first order accurate.

The famous, second-order accurate central difference approximations for


derivatives are obtained by writing a backward Taylor expansion y(x-t) and letting t = h.
Then subtracting it from y(x+t) yields

y i 1 y i 1
y i O (h 2 y ) (2.1.4)
2h

Adding it to y(x+t) yields

y i 1 / h 2 ( y i 1 y i 1 2 y i ) O(h 2 y ( 4 ) ) (2.1.5)

9/9/17
2

yi+1
True derivative
yi
Forward difference

yi-1 Central difference

Backward difference

h h

xi-1 xi xi+1
Fig. 2.1 Finite difference techniques to calculate first order derivative at xi

2.2 Trapezoid Rule

The concept of the trapezoidal rule comes from approximating y ( x) at any point
t in an interval using the Taylors series. Then integrate the approximation. If the
approximation is a linear function, the resulting integration is called the trapezoidal rule.

For the data interval [ x i , xi 1 ]

h
y ty O(t 2 y ) dt y h dt y h tdt h O (t 2 y )dt
h
I 0
ydt
i
0
i i i
0
i
0 0 i

h2 h 2 y i 1 y i
hyi y i O (h 3 y i ) hyi O (h 3 y i ) (2.2.1)
2 2 h
h
y i 1 y i O( h 3 y i )
2

which is the trapezoidal rule for one interval. If we use it over a range of intervals
running from a to b, [ a x1 , x 2 , , x n 1 b ] , we get

n n n
h h
I ab ( y i y i 1 ) O( h 3 y i ) ( y1 2 y i y n 1 ) nh 3 y avg
i 1 2 i 1 2 i 2
n
(2.2.2)
h
( y a 2 y i y b ) ch 2
2 i 2

which is the composite trapezoidal rule.

9/9/17
3

Example 2.2.1. Use the trapezoidal rule to calculate the following integral

1
I
0 2
sin(x) dx

which has an exact answer of 1.

In a MATLAB code trapezoid_example_1.m, we use the MATLAB function


trapz for this calculation. The code is very short and looks like this with comments
attached

function trapezoid_example_1
% TRAPEZOID_EXAMPLE_1 is an example for integration
%using the trapezoidal rule;
%
%the integral has an exact value of 1;

xa=0; xb=1; % range of x for the integration;


exact_i=1; % exact solution;
for i=1:6;
n=10^i; % number of subintervals;
x=linspace(xa,xb,n+1); % data set x;
ai_trap(i)=trapz(x,fuser(x)); % trap. integ. with intrinsic fctn;
end;
format short e;
ai_trap - exact_i % show error

function f=fuser(x)
% user defines function

f=pi/2*sin(pi*x);

The results are tabulated below

# of subintervals 101 102 103 104 105 106


Error -8.2382e- -8.2248e- -8.2247e- -8.2247e- -8.2243e-11 -8.3489e-13
3 5 7 9

As we can see, the convergence is rather slow. To reach an accuracy of 10-13,


roughly 106 intervals are needed.

2.3 Romberg Integration

Denote I (h) as I with subinterval length h . Consider I for two different h

I I (h1 ) ch12
(2.3.1)
I I (h2 ) ch22
which gives

9/9/17
4

I (h1 ) I (h2 )
c (2.3.2)
h12 h22

By substituting it into either of the above equations, we would get a better approximation
to I . This idea of using multiple subinterval lengths to extrapolate better
approximations is generally called the Richardson extrapolation. It will be discussed in
more detail after the following example.

Example 2.3.1. Calculate the integral in Example 2.2.1 with h 0.1 and h 0.05 .
Then use the Richardson extrapolation to get a better approximation.

A MATLAB code trapezoid_example_2.m is used to solve this example. We


have

@ h 0. 1 : I (0.1) 1 8.2382 10 3
@ h 0.05 : I (0.05) 1 2.0570 10 3

where the integration values shown are the error terms compared with the exact solution
of 1. Then

(1 8.2382 10 3 ) (1 2.0570 10 3 )
c 0.82416
0.12 0.05 2

which gives
I I (0.1) c 0.12 1 3.3922 10 6

which is clearly an improvement over I (0.1) and I (0.05) without going through an
extensive integration process. We can improve upon this even further.

Generally the Richardson extrapolation rule assumes A(h) is an approximation


written as
A( h) A(0) ch p O(h q ) (2.3.3)

where p q and they need not to be integers. A(0) is the exact solution and the terms
to the right of it denote the error in A(h). To eliminate the h p term, lets introduce a fixed
number r 1 . Then for an interval h / r

A( h / r ) A(0) cr p h p O ([h / r ] q ) (2.3.4)

Solving for c from the two equations above and then substituting it back into the first
equation, we get

A(h / r ) A(h) r p A(h / r ) A(h)


A(0) A(h) h p
p p
O(h )
q
O(h q ) (2.3.5)
h r h
p
r 1
p

9/9/17
5

which gives an improved version of the approximation. We can repeat this process and
get better and better approximations. This is the Richardson approximation.
The Romberg integration uses the Richardson extrapolation on the composite
trapezoidal rule. The detailed proof of related theorems can be found in many numerical
analysis books such as Gautschi (1997) and Buchanan and Turner (1992). Only the
schemes are given here.
For the trapezoidal rule, the usual interval subdivision is 2, so let r 2 and
following Richardson, take even powers in the sequence p 2, 4, 6, , and q p 2 .
Moreover, if we recast the approximation (r.h.s. above) as a sequence in n = 1, 2, 3, ,
then A(0) can be written as

4 n An 1 (h / 2) An 1 (h)
An (h) (2.3.6)
4n 1

where p = 2n, 2 2 n 4 n and the subscript on A denotes its value at each recursive step,
the sequence of which is discussed next.
If we start from A0 ( h) and we want to get A1 ( h) , we need to calculate
A0 (h / 2) first. Then to get A2 ( h) , we need A1 (h / 2) in addition to A1 ( h) . A1 ( h / 2)
in turn needs A0 (h / 4) . The scheme can be arranged in a form very similar to the table
of divided differences (see Section 3.2) :

O (h 2 ) O(h 4 ) O (h 6 ) O (h 8 )
A0 ( h)
A0 ( h / 2) A1 ( h)
(2.3.7)
A0 ( h / 4) A1 ( h / 2) A2 ( h)
A0 ( h / 8) A1 ( h / 4) A2 ( h / 2) A3 ( h)

The A0 column is found from the composite trapezoidal rule. The algorithm for the
implementation of this scheme is as follows

(1) Set the desired level of approximation, nl , e.g., nl 4 in Equation (2.3.7);


(2) Define the integrated function and set the interval [ a, b ] over which the
integration is to be done, and the initial number of intervals, n ;
(3) Declare the table in (2.3.7) as a matrix r of dimension (nl, nl);
(4) Calculate the first column of r using the composite trapezoidal rule (Equations
2.3.8 and 2.3.9 given below);
(5) Calculate the rest of the matrix using Equation (2.3.6).

In step 4, we start with the first element using the composite trapezoidal rule:

9/9/17
6

n
h
r (1, 1) ( y (a ) y (b)) h y a (k 1) h (2.3.8)
2 k 2

where the sum goes to n because we have n+1 points. For subsequent i 2, 3, , nl ,
the calculation will be done step-by-step in a do loop down column 1 where each interval
length is half of the previous step. Since half of the data points and their function values
are calculated already, we take advantage of this by revising the composite trapezoidal
rule:
ni
hi
r (i, 1) ( y (a) y (b)) hi y a (k 1)hi
2 k 2

1 hi 1 ni ni 1

( y (a ) y (b)) hi y a (k 1)hi y a (k 1)hi
2 2 k 2 , 4 , 6 k 3, 5 , 7
ni 1 ni
1 hi 1 h

2 2
( y (a ) y (b)) i 1
2
y a (k 1)h h y a (k 1)h
k 3, 5 , 7
i i
k 2, 4, 6
i

ni 1 ni
1 hi 1 h

2 2
( y (a ) y (b)) i 1
2
y a (2 j 1 1)hi hi
j 2 , 3, 4
y a (k 1)h
k 2, 4, 6
i

1 hi 1 h ni 1 ni
( y (a ) y (b)) i 1 y a ( j 1)hi 1 hi y a (k 1)hi
2 2 2 j 2 k 2, 4, 6
ni
1
r (i 1, 1) hi y a (k 1)hi
2 k 2, 4,6

(2.3.9)
where ni , hi are the number of intervals and their length for row i , respectively, and
ni 2ni 1 .

Example 2.3.2. Calculate the integral in Example 2.2.1 using the Romberg integration for
five levels.

The MATLAB code romberg_example.m is generated for this example. The


resulting error matrix is

-8.2382e-3
-2.0570e-3 3.3922e-6
-5.1409e-4 2.1155e-7 -4.9836e-10
-1.2851e-4 1.3214e-8 -7.7686e-12 1.8652e-14
-3.2128e-5 8.2579e-10 -1.2057e-13 8.8818e-16 8.8818e-16

In Example 2.2.1, the error for the composite trapezoidal rule with 106 intervals is
about 10-13. We achieved 10-14 in just four levels of Romberg approximation. This scheme
certainly saves a lot of computational time.

9/9/17
7

2.4 Guass Quadrature

We will first illustrate the Gauss quadrature through two examples, and then a
general description is given. Before we do that, lets scale the interval [ a, b ] on x to
[ 1, 1 ] on t :

2( x a ) t 1
t 1 x (b a) a (2.4.1)
ba 2
Thus

b b t 1 ba 1
I
a
y ( x) dx
a
y ( x)d
2
(b a ) a
2 1
y (t ) dt (2.4.2)

So in general, we will assume the interval is [ 1, 1 ] and, if it is not, transform it to that


as shown above.

Example 2.4.1. For a linear function y ( x) c 0 c1 x

1
x2
I exact c0 x c1 2c 0 2 y (0) (2.4.3)
2 1
so we can say

I Gauss w1 y ( x1 ) 2 y ( x 0) I exact (2.4.4)

where w1 2 is called the weight which multiplies the function evaluated at the Gauss
point x = 0. Importantly, this means the exact integral of any linear function can be found
by 2 times the function value at x 0 . If we denote NGP as the number of Gauss points,
NGP = 1 for this case.

Example 2.4.2. For a cubic function y ( x) c0 c1 x c 2 x 2 c3 x 3

1
x2 x3 x4 2
I exact c 0 x c1 c2 c3 2c 0 c 2 (2.4.5)
2 3 4 1 3

Regardless of the values of the coefficients c0, c1, c2, and c3, lets try to find a two-point
approximation with two weights:

I Gauss w1 y ( x1 ) w2 y ( x 2 ) (2.4.6)

Thus

9/9/17
8

2
0 I exact I Gauss 2c0 c 2 w1 y ( x1 ) w2 y ( x 2 )
3
2
(2 w1 w2 )c0 ( w1 x1 w2 x 2 )c1 ( w1 x12 w2 x 22 )c 2 ( w1 x13 w2 x 23 )c3
3
(2.4.7)

Since the coefficients c0, c1, c2, and c3 are arbitrary, the terms in parentheses ( ) must all
be zero. That is

w1 w2 2
w1 w2 1
w1 x1 w2 x2 0
2
w1 x1 w2 x2 x1 1 , x2 1
2 2

3
w1 x13 w2 x23 0 3 3
(2.4.8)

Thus if NGP = 2, a polynomial of degree no greater than 3 can be solved through I Gauss
exactly with two weights of unit value and y evaluated at x1, x2.

Through these two examples, it is clear that our intention here is to convert the
integration of polynomials to a sum of weighted function values taken at several specific,
optimally chosen points, the Gauss points. That is

1 n

1
y ( x )dx w y( x )
i 1
i i (2.4.9)

In general, for n -point Gauss quadrature, if the x i are the zeros of the Legendre
polynomial Pn ( x) , and the weights are given by

n 1 1
x
i 1
k
i wi x
1
k
dx
k 1
(1 (1) k ), k 0, 1, , n 1 (2.4.10)

then the Gauss quadrature calculates polynomials of degree no greater than 2n 1


exactly. Considering the two examples above, the respective Legendre polynomials are

P1 ( x) x P2 ( x) (3 x 2 1) / 2

A more thorough treatment of Legendre polynomials can be found in the references, but
this is adequate for most applications, e.g., finite element methods. Weights and Gauss
point locations for higher order quadrature can also be found in the references.

Example 2.4.3. Calculate the integral in Example 2.2.1 using the Gauss quadrature.

9/9/17
9

This example is solved through a MATLAB file gauss_example.m. The results


are tabulated below

n 2 3 4 5
error -3.2090e-2 6.9446e-4 -7.8858e-6 5.5142e-8

Gauss Quadrature in Two Dimensions

Gauss quadrature can be applied over the unit square by applying the one-
dimensional method shown above in each direction. For example,

n m
f ( x, y )dxdy wi w j f ( xi , y j )
1 1

1 1
i 1 j 1

(2.4.11)

The number of Gauss points in each direction can be different. Clearly a rectangle can be
transformed into a square using (2.4.1) in each direction. Furthermore, a triangle can also
be treated, but this requires further development which can be found in the references;
notably, the weights and Gauss points will differ.

References

Buchanan, J.L. and Turner, P.R., Numerical Methods and Analysis, McGraw-Hill,
1992.
Gautschi, W., Numerical Analysis, 1997, Birkhauser Boston.

9/9/17

You might also like