Sie sind auf Seite 1von 14

Chapter 4

Differentiation and Integration

4.1 INTRODUCTION
The derivative of a function gives a clear indication of the rate of increase or decrease of the function
with respect to its domain. The rate of increase or decrease of a function contributes in the overall
understanding of a system that is governed by such parameters. In general, the derivatives of a function
contribute in the modeling of a given problem which describe the properties and dynamics of the
elements in the problem. For example, in studying the electrostatic field properties of an area the
solution requires a graphing of the first and second derivatives of the points in the area. We will discuss
some useful properties of the derivatives of a function for modeling in the next few chapters.
The analytical derivative of a function f ( x) with respect to the variable x is denoted by f ( x) , or
df
. This derivative returns the exact solution in the form of a function of x . For example, if
dx
f ( x) = x 2 sin x then its analytical derivative is f ( x) = 2 x cos x .
By default, a digital computer does not have the processing capability to produce the analytical
derivative of a function. However, this analytical solution can still be produced through a software that
stores a list of primitive functions and its derivatives in a numerical database. On the computer, the
analytical solution to a derivative is a complex problem that requires several recursive calls to the
functions in its numerical database. Symbolic computing is one area of study that addresses this problem
which involves the construction of a database of mathematical functions for generating the analytical
solution to their derivatives.
The computer gives a good approximation to the derivatives of a function based on some finite
points in the given domain. A numerical approximation to the derivative of a function f ( x) is a solution
expressed as a number, rather than a function of x . The domain of f ( x) is first decomposed into its
discrete form, xi for i = 1, 2,..., m , and the derivatives are computed at these points based on their
relative points.
An integral of a function does the opposite of derivative. Integral returns the differentiated
function to its original value. A numerical approach for finding the integral of a function is needed in
cases where the integral is difficult to compute.

4-1 Shaharuddin Salleh


In this chapter, we will discuss several numerical approaches to finding the derivatives and integral
of a function. The approximated values returned from the methods are reasonably close to the exact
values, and are acceptable in most cases.

4.2 NUMERICAL DIFFERENTIATION


The starting point in finding a derivative is the n th order Taylor series expansion of a discrete function
yi = f ( xi ) given as follows:

h h2 h3 h n (n)
y i +1 y i + y i + y i + y i + ... + yi . (4.1)
1! 2! 3! n!

Equation (4.1) gives the one-term forward expansion of y = f ( x) . In this equation, h = x is the width
of the x subintervals which are assumed to be uniform. The term yi +1 = f ( xi +1 ) above is equivalent to
yi +1 = f ( xi +1 ) = f ( xi + h) .

f ( xi+2 )

f ( xi+1 )

f ( xi )
f ( xi-1 )
f ( xi-2 )

h h h h
x
xi-2 xi-1 xi xi+1 xi+2

Figure 4.1. Relative position of discrete points of f ( x) in the Taylor series expansion.

Figure 4.1 shows the relative position of the discrete points of f ( x) in the interval xi 2 x xi + 2 .
Taking only up to the second derivative term, this equation reduces to

h h2
yi+1 yi + yi + yi . (4.2a)
1! 2!

Obviously, the one-term forward expansion in Taylor series involves xi +1 = xi + h . In a similar


manner, we can define the two-term forward expansion by replacing h with 2h , or xi + 2 = xi + 2h , to
produce
4-2 Shaharuddin Salleh
2h (2h) 2 2h 4h 2
yi+2 yi + yi + yi = yi + yi + yi . (4.2b)
1! 2! 1! 2!

It follows that the one-term backward expansion is obtained by replacing h with h , or


xi 1 = xi + (h) = xi h , to produce

( h) ( h) 2 h h2
yi1 yi + yi + yi = yi yi + yi . (4.2c)
1! 2! 1! 2!

Subsequently, the two-term backward expansions of y = f ( x) involves xi 2 = xi + (2h) = xi 2h ,


is given by

(2h) ( 2h) 2 2h 4h 2
yi2 yi + yi + yi = yi yi + yi . (4.2d)
1! 2! 1! 2!

The simplest rule for the first derivative is obtained by taking yi as a subject in the first two terms
of Equation (4.1). It produces the forward-difference rule for the first derivative,

h
yi +1 yi + yii ,
1!
y yi
yi i +1 . (4.3a)
h

The forward-difference rule for the second derivative is obtained by subtracting twice Equation (4.2c) from
Equation (4.2d), and simplying the terms to produce

yi+2 2 yi+1 + yi
yi . (4.3b)
h2

There is also the backward-difference rule for the first derivative, obtained by taking yi as a subject in
the first two terms of Equation (4.2c), to produce

yi yi 1
yi . (4.4a)
h

Similarly, subtracting twice Equation (4.2c) from Equation (4.2d) gives the backward-difference rule for the
second derivative:

yi 2 yi 1 + yi 2
yi . (4.4b)
h2

As the names suggest, the forward-difference and backward-difference rules have the
disadvantages in that they are bias towards the forward and backward points, respectively. A more
balanced approach is the central-difference rules which consider both forward and backward points.
Subtracting Equation (4.2a) from (4.2c), and simplify the terms we obtain the central-difference rule for the
first derivative,

yi +1 yi 1
yi . (4.5a)
2h

4-3 Shaharuddin Salleh


By adding Equations (4.2a) and (4.2c), and simplifying the terms we obtain the central-difference rule
for the second derivative,

yi +1 2 yi + yi 1
yi . (4.5b)
h2

4.3 NUMERICAL INTEGRATION


b
An integral of the form a
f ( x) dx in the interval a x b has many applications especially in science
and engineering. In its fundamental form, the integral evaluates the area enclosed between the function
f ( x) and the x axis. Area in this sense is a symbolic represention of many other quantities and
problems in engineering such as moment, volume, mass, density, pressure and temperature. Therefore, a
numerical solution to a definite integral contributes as part of the whole solution to a problem.

f (a )

f (b )

f (x)

x
a b
Figure 4.2. The area under the curve between f ( x) and the x axis.

The exact methods for evaluating definite integrals have been widely discussed in elementary
calculus classes. Some popular methods involve techniques such as direct integration, substitutions,
integration by parts, partial fractions, and substitutions with the use of trigonometric functions.
However, not all definite integral problems can be solved using such methods. This may be the case
when the function f ( x) is too difficult to integrate, or in the case where f ( x) is given in the form of a
discrete data set. Furthermore, it may not be possible to implement the exact method on the computer
as the computer does not have the analytical skill like a human does. Therefore, approximations using
numerical methods may prove to be an alternative approach and practical for implementation here.
Numerical solutions for evaluating definite integrals are obtained using several methods. Some of
the most fundamental methods include the trapezium, Simpson, Simpsons 3/8 and Gaussian quadrature
methods. We discuss these methods in this section.

4-4 Shaharuddin Salleh


Trapezium Method
The trapezium method is a classical technique for approximating the definite integral of a function,
b
a
f ( x) dx in the interval a x b . As the name suggests, the method is based on an approximation of
the area under the curve between the function and the x axis as several trapeziums taken over some
finite subintervals.
In the trapezium method, the x interval in a x b is divided into m equal-width subintervals,
each with width h . A straight line is connected from ( xi , f ( xi )) to ( xi +1 , f ( xi +1 )) in the subinterval
[ xi , xi+1 ] and this forms a trapezium with f ( xi ) and f ( xi+1 ) as the parallel sides whose distance
between them is h . The area under the curve in this subinterval is then approximated as the area of the
trapezium, given as

h
( f ( xi ) + f ( xi+1 ) ) .
xi +1
xi
f ( x) dx
2

b
With m subintervals, a
f ( x)dx is approximated as the sum of all the areas of the trapeziums,
given as

m1
h
f ( x) dx ( f ( xi ) + f ( xi+1 ) )
b
a
i =0 2
h
= [ f ( x0 ) + f ( xm ) + 2 {( f ( x1 ) + f ( x2 ) + ... + f ( xm1 )}] (4.6)
2

f (x0 )

f (x3 )
f (x2 )
f (x1 )

f (x4 )

f (x)
A1 A2 A3 A4

x
x0 x1 x2 x3 x4
Figure 4.3. Trapezium method with four subintervals.

Equation (4.6) gives the trapezium method for finding the definite integral of a function f ( x) in the
interval from x = a to x = b with m equal subintervals. The method is illustrated in Figure 4.3 using
x4
four equal subintervals. From the figure, it is clear that
x0
f ( x) dx for x0 x x4 is a problem in finding

4-5 Shaharuddin Salleh


the area under the curve in the given interval. The interval in this problem is divided into four
subintervals with m = 4 and h = ( x4 x0 ) / m . The total area is then approximated as the sum of the
subareas Ai for i = 1, 2,3, 4 , given as

b
a
f ( x) dx A1 + A2 + A3 + A4
h h h h
= ( f ( x0 ) + f ( x1 ) ) + ( f ( x1 ) + f ( x2 ) ) + ( f ( x2 ) + f ( x3 ) ) + ( f ( x3 ) + f ( x4 ) )
2 2 2 2
h
= [ f ( x0 ) + f ( x4 ) + 2( f ( x1 ) + f ( x2 ) + f ( x3 ))] .
2

Simpsons Method
The trapezium method uses a straight line approximation on two successive f ( x) values in the
b
subintervals for evaluating a
f ( x) dx for a x b . A straight line approximation may not produce a
good solution especially when the number of subintervals is small. This is due to the fact that a straight
line does not approximate a given curve well. Due to the large error imposed, the trapezium method
requires a large number of subintervals in order to produce a good solution.
The accuracy of the trapezium method can be improved by replacing the straight line with a
quadratic function. This idea makes sense as a quadratic curve lies closer to the real curve in the given
function than a straight line. Since a quadratic function requires three points for interpolation, the
method suggests pairs of two subintervals in the approximation. The approach is called the Simpsons
method.

yi

yi+2
yi+1

Ai

x
xi xi+1 xi+2
Figure 4.4. Quadratic polynomial fitting on two subintervals in the Simpsons method.

As the Simpsons method requires two subintervals in each pair, the total number of subintervals
in the given interval must be an even number. Consider the subintervals [ xi , xi+1 ] and [ xi+1 , xi+2 ] which
involve the points, ( xi , f ( xi )) , ( xi+1 , f ( xi+1 )) and ( xi+2 , f ( xi+2 )) . Figure 4.4 shows this scenario with the
dotted curve as the quadratic approximation to the real curve. This curve has an equation given by

4-6 Shaharuddin Salleh


y = a0 + a1 x + a2 x 2

where a0 , a1 and a2 are the constants that are to be determined. The quadratic curve interpolates
( xi , yi ) , ( xi+1 , yi+1 ) and ( xi+2 , yi+2 ) . This produces a system of linear equations, given as

yi = a0 + a1 xi + a2 xi2 ,
yi +1 = a0 + a1 xi+1 + a2 xi2+1 ,
yi +2 = a0 + a1 xi +2 + a2 xi2+2 .

The above system is solved to produce the Simpsons formula, given by

h
( yi + 4 yi+1 + yi+2 ) .
xi + 2
xi
f ( x) dx
3
(4.7)

Equation (4.7) can be extended into the case of m even subintervals for x = x0 to x = xm . The
total area is found as a sum of m / 2 subareas where each subarea combines two subintervals. Applying
Equation (4.7), we obtain the Simpsons method for m subintervals, as follows:

h h h
( y0 + 4 y1 + y2 ) + ( y2 + 4 y3 + y4 ) + ... + ( ym2 + 4 ym1 + ym )
xm
x0
f ( x) dx
3 3 3
h
= [ ( y0 + yn ) + 4( y1 + y3 + ... + yn1 ) + 2( y2 + y4 + ... + yn2 ) ] (4.8)
3

An extension to the Simpsons method is the Simpsons 3/8 method. In this method, three
subintervals are combined to produce one subarea based on a cubic polynomial. This approach requires
four points for each subarea, and, therefore, it provides a more accurate approximation to the problem.
With three subintervals for each subarea, the total number of subintervals in the Simpsons 3/8 method
becomes a multiple of three.
Interpolation over four points for each subarea in the Simpsons 3/8 method produces a system of
four linear equations. The interpolating curve is a cubic polynomial given by

y = a0 + a1 x + a2 x 2 + a3 x 3 ,

where a0 , a1 and a2 are constants. The above curve interpolates ( xi , yi ) , ( xi+1 , yi+1 ) , ( xi +2 , yi+2 ) and
( xi+3 , yi+3 ) to produce an approximated subarea, given by

3h
( yi + 3 yi+1 + 3 yi+2 + yi+3 ) .
xi +3
xi
f ( x) dx
8
(4.9)

With m subintervals, Equation (4.9) can be extended to produce

3h
[( y0 + yn ) + 2( y3 + y6 + ... + yn3 ) + 3( y1 + y2 + y4 + y5 + ... + yn2 + yn1 )] . (4.10)
xm
f ( x) dx
x0 8

4-7 Shaharuddin Salleh


Gaussian Quadrature
The three methods outlined above are applicable to problems whose data is normally given in discrete
form. Quite often data is given in the form of a function f ( x) whose integral is difficult to find. A
method called the Gaussian quadrature specializes in tackling this kind of problem. The method is based
on an approximation on Legendre polynomials.
A Legendre polynomial of degree n is given in the form of an ordinary differential equation of
order n , as follows:

1 dn
Pn ( x) =
2n n ! dx n
( ( x2 1)n ) . (4.11)

Table 4.1 lists some of the Legendre polynomials of lower degrees. Legendre polynomials have the
characteristics of being orthogonal over x (1,1) , and satisfy


1
2
Pm ( x) Pn ( x) dx = mn ,
1
2n + 1

where mn is the Kronecker delta.

Table 4.1. Legendre polynomials.


n Pn ( x)
0 1
1 x
2 (3 x 2 1) / 2
3 (5 x3 3x) / 2
4 (35 x 4 30 x 2 + 3) / 8
5 (63 x 5 70 x 3 + 15 x) / 8
6 (231x 6 315 x 4 + 105 x 2 5) /16

f (a )

g (t)

f (b )

f (x)

x
a b t
-1 1


b 1
Figure 4.5. Transformation from a
f ( x) dx to
1
g (t ) dt in the Gauss-Legendres method.

4-8 Shaharuddin Salleh


b
Gaussian quadrature method consists of two major steps. First, the integral a
f ( x) dx in the


1
interval a x b is transformed into the form of g (t ) dt . This is achieved through a linear
1
relationship given by

(b a )t + (b + a)
x= , (4.12)
2

where g (t ) is a new function that is continuous in 1 t 1 . It can be verified that substituting x = a


and x = b into the linear equation produces t = 1 and t = 1 , respectively. The transformation


1
preserves the area under the curve in g (t ) dt , as illustrated in Figure 4.5. We have
1

ba (b a )t + (b + a )
f ( x) dx = f dt .
2 2


b b
ba (b a )t + ( b + a )
f ( x) dx = f dt .
a a
2 2

ba ( b a )t + ( b + a )
g (t ) = f . (4.13)
2 2


1
The second step in this method consists of an approximation to the integral g (t ) dt through a
1
quadrature, given by
n

g (t ) dt wi g (ti ) .
1
(4.14)
1
i =1
The above equation is called the n point Gauss quadrature where n is an integer number greater than
1. The constant wi is called the weight while ti is the argument in the quadrature. The argument ti in
Equation (4.14) is actually a root of the Legendre polynomial given in Table 4.1.

Table 4.3. Weights and arguments in the Gaussian quadrature.


n Weight, wi Argument, ti
2 w1 = 1 t1 = 1/ 3 = 0.577350
w2 = 1 t2 = 1/ 3 = 0.577350
3 w1 = 0.555556 t1 = 3 / 5 = 0.774597
w2 = 0.888889 t2 = 0
w3 = 0.555556 t3 = 3 / 5 = 0.774597
4 w1 = 0.347855 t1 = 0.861136
w2 = 0.652145 t2 = 0.339981
w3 = 0.652145 t3 = 0.339981
w4 = 0.347855 t4 = 0.861136
5 w1 = 0.236927 t1 = 0.90610
w2 = 0.478629 t2 = 0.538469
w3 = 0.568889 t3 = 0
w4 = 0.478629 t4 = 0.538469
w5 = 0.236927 t5 = 0.90610
4-9 Shaharuddin Salleh
Fast Example 1: Differentiations using Newtons methods

Example 4.1. Given y = x sin x , find y and y at the points along 0 x 2 whose subintervals have
an equal width given by h = 0.3333 using the forward, backward and central-difference methods.

Solution
In this problem, m = (2 0) / .3333 = 6 . The analytical derivatives are given by y = sin x + x cos x and
y = 2 cos x x sin x . Table 4.1 plots the values of xi and yi for i = 0,1,..., 6 . The analytical derivatives at
these points are shown in the fourth and fifth columns of the table.
At i = 0 , y0 and y0 can be evaluated using the forward-difference rules using Equation (4.3a) and
(4.3b):
y y 0.1090 0
y0 1 0 = = 0.3270 ,
h 0.3333
y 2 y1 + y0 0.4122 2(0.1090) + 0
y0 2 = = 1.7481 .
h2 0.33332
It is not possible to evaluate y0 and y0 using the backward and central-difference rules as both
methods involve the terms y1 and y2 which do not exist. The results at other points are shown in
Table 4.1. Through comparison with the analytical (exact) method, the central-difference method
produces the closest approximations for the derivatives.

Table 4.1. The numerical results from Example 4.1.


Analytical Forward- Backward- Central-difference
Solutions difference difference
i xi yi yi yi yi yi yi yi yi yi
0 0 0 0 2 0.3270 1.7481 void void void void
1 0.3333 0.1090 0.6421 1.7809 0.9097 1.1342 0.3270 void 0.6183 1.7481
2 0.6667 0.4122 1.1423 1.1594 1.2877 0.2277 0.9097 1.7481 1.0987 1.1342
3 1.000 0.8414 1.3818 0.2391 1.3636 -0.8228 1.2877 1.1342 1.3257 0.2277
4 1.3333 1.2959 1.2856 -0.8255 1.0894 -1.8319 1.3636 0.2277 1.2265 -0.8228
5 1.6667 1.6590 0.8358 -1.8515 0.4788 void 1.0894 -0.8228 0.7841 -1.8319
6 2.000 1.8186 0.0770 -2.6509 void void 0.4788 -1.8319 void void

4-10 Shaharuddin Salleh


Fast Example 2: Trapezium Method
Formula

h
[ yi + yi +1 ]
xi +1
One-Interval Trapezium Method: xi
f ( x)dx
2
h
[( y0 + y n ) + 2( y1 + y 2 + .... + y n1 ]
xn
General Trapezium Method: x0
f ( x) dx
2

1.9
Find 1
f ( x) dx using the Trapezium method from the following data:

i 0 1 2 3 4 5 6 7 8 9
xi 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
yi = f i 2.5 2.8 2.7 2.6 2.3 2.1 2.4 2.3 2.6 3.0

Solution

From the table, the width of each interval is h = x = 0.1 .

Therefore,
1.9
1
f ( x) dx A = A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8 + A9
h h h h
= ( y 0 + y1 ) + ( y1 + y 2 ) + ( y 2 + y 3 ) + ( y 3 + y 4 )
2 2 2 2
h h h h h
+ ( y 4 + y 5 ) + ( y 5 + y 6 ) + ( y 6 + y 7 ) + ( y 7 + y8 ) + ( y8 + y 9 )
2 2 2 2 2

=
h
[( y 0 + y9 ) + 2( y1 + y 2 + y3 + y 4 + y5 + y6 + y 7 + y8 ]
2

=
0.1
[(2.5 + 3.0) + 2(2.8 + 2.7 + 2.6 + 2.3 + 2.1 + 2.4 + 2.3 + 2.6)] = 2.255
2

4-11 Shaharuddin Salleh


Fast Example 3: Simpson Method
(condition: n is an even number)

Formula

h
( f i + 4 f i +1 + f i + 2 )
xi + 2
2-interval Simpson Method: xi
f ( x) dx
3
h
[( y 0 + y n ) + 4( y1 + y3 + ... + y n1 ) + 2( y 2 + y 4 + ... + y n2 )],
xn
General Simpson Method: x0
f ( x) dx
3

1.8
Find 1
f ( x) dx using the Simpson method from the following data:

i 0 1 2 3 4 5 6 7 8
xi 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8
yi = f i 2.5 2.8 2.7 2.6 2.3 2.1 2.4 2.3 2.6

Solution

From the table, the width of each interval is h = x = 0.1 .

1.8
1
f ( x) dx A = A1 + A2 + A3 + A4
h h h h
= ( y 0 + 4 y1 + y 2 ) + ( y 2 + 4 y 3 + y 4 ) + ( y 4 + 4 y 5 + y 6 ) + ( y 6 + 4 y 7 + y8 )
3 3 3 3
= [( y 0 + y8 ) + 4( y1 + y 3 + y 5 + y 7 ) + 2( y 2 + y 4 + y 6 )]
h
3
=
0.1
[(2.5 + 2.6) + 4(2.8 + 2.6 + 2.1 + 2.3) + 2(2.7 + 2.3 + 2.4)] = 1.970
3

4-12 Shaharuddin Salleh


Fast Example 4: Simpson 3/8 Method
(Condition: n is the multiple of 3)

Formula
3h
( f i + 3 f i +1 + 3 f i + 2 + f i +3 ) ,
xi + 3
3-interval rule: xi
f ( x) dx
8
General rule:
3h
[( f 0 + f n ) + 2( f 3 + f 6 + f 9 + ... + f n3 ) + 3( f1 + f 2 + f 4 + f 5 + ... + f n2 + f n1 )]
xn
x0
f ( x) dx
8

1.9
Find 1
f ( x) dx using the Simpson 3/8 method from the following data:

i 0 1 2 3 4 5 6 7 8 9
xi 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
yi = f i 2.5 2.8 2.7 2.6 2.3 2.1 2.4 2.3 2.6 3.0

Solution

From the table, the width of each interval is h = x = 0.1 .

We get,

3h
( f 0 + 3 f1 + 3 f 2 + f 3 ) + 3h ( f 3 + 3 f 4 + 3 f 5 + f 6 ) + 3h ( f 6 + 3 f 7 + 3 f 8 + f 9 )
b
a
f ( x) dx
8 8 8
= [ f 0 + f 9 + 2( f 3 + f 6 ) + 3( f1 + f 2 + f 4 + f 5 + f 7 + f 8 )]
3h
8

Finally,

3(0.1)
[2.5 + 3.0 + 2(2.6 + 2.4) + 3(2.8 + 2.7 + 2.3 + 2.1 + 2.3 + 2.6)]
1.9
1
f ( x) dx
8
= 2.246

4-13 Shaharuddin Salleh


Fast Example 5: Gauss Quadrature Method

Formula

Gauss Quadrature:

n
(b a)t + (b + a)
g (t ) dt ci g (t i ) , where x =
b 1
n-point: a
f ( x) dx =
1
i =1 2

b 1 1 1
2-point: a
f ( x) dx =
1
g (t ) dt g

+ g
3 3

5 3 8 5 3
+ g (0 ) + g
b 1
3-point: a
f ( x) dx =
1
g (t ) dt g
9
5 9

9 5

2
Find 1
x sin x dx using the 3-point Gauss quadrature method.

Solution
(2 1)t + (2 + 1) t 3
Compute x = = + .
2 2 2
dx 1 dt
Therefore = , and we get dx =
dt 2 2

2 1 t + 3 t + 3 dt 1 t +3 t + 3
1
x sin x dx =
-1 2
sin = -1
2 2 4
sin
2
dt

t + 3 t + 3
We obtain g (t ) = sin .
4 2

5 3 8 5 3
+ g (0) + g
2
1
x sin x dx g
9 5 9

9 5
5 8 5
= g (0.775) + g (0) + g (0.775)
9 9 9
5 8 5
= (0.499) + (0.748) + (0.897)
9 9 9
= 1.440

4-14 Shaharuddin Salleh

Das könnte Ihnen auch gefallen