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 dx . This derivative returns the exact solution in the form of a function of x . For example, if

f (xx) =

2 sin x then its analytical derivative is f (xx) = 2 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,

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.

x

i

for i = 1,2,

,

m , and the derivatives are computed at these points based on their 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

y = fx

i

(

i

)

given as follows:

y

i

+ 1

y +

i

h

1!

y ′+

i

h

2

2!

y

′′+

i

h

3

3!

y

′′′+ +

i

h

n

n !

y

(

i

n

)

.

(4.1)

Equation (4.1) gives the one-term forward expansion of y = fx( ) . In this equation, h = Δx is the width of the x subintervals which are assumed to be uniform. The term
y
=
fx
(
)
above is equivalent to
i
+
1
i
+
1
y
=
fx
()
=+ .
fx
(
h
)
ii
+
1
+
1
i
y
f ( x i+2 )
f ( x i+1 )
f ( x i )
f ( x i-1 )
f ( x i-2 )
h
h
h
h
x
x i-2
x i-1
x i
x i+1
x i+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 Taking only up to the second derivative term, this equation reduces to

≈+ h ′ +

yy

+ 1

ii

1!

y

i

h

2

2!

y ′′ .

i

x

i

2

x

≤ ≤

(4.2a)

x

i

+

2

.

Obviously, the one-term forward expansion in Taylor series involves manner, we can define the two-term forward expansion by replacing h with 2h , or produce

x

i

+

1

=

x

i

+

h

. In a similar

x

i

+ 2

=

x

i

+

2

h

, to 4-2

Shaharuddin Salleh

x

y

i i

+ 2

≈+ y

2

h

1!

y

′ +

i

(2

h

)

2

2!

yy ′′ =+

ii

2

hh ′ +

2

1!

y

i

4

2!

y ′′ .

i

(4.2b)

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

x

=

1

ii

+− =

i

(

h

)

xh

, to produce

y

≈+

i i

1

y

h

()

1!

y

′ +

i

h

()

2

2!

2

′′ =− hh ′ +

yy

ii

1!

y

i

2!

y ′′ .

i

(4.2c)

Subsequently, the two-term backward expansions of y = fx( ) involves is given by

y

i

2

≈+

y

i

h

(2)

1!

y

′ +

i

h

(2)

2

2!

′′ =−

yy

ii

2

hh ′ +

2

1!

y

i

4

2!

y ′′ .

i

x

2

(2)

hx

=

i

ii

= +−

x

(4.2d)

2

h

,

The simplest rule for the first derivative is obtained by taking

yas a subject in the first two terms

i

of Equation (4.1). It produces the forward-difference rule for the first derivative,

h

+

yy

i

+ 1

y ′ ≈

i

y

i

i

+

1

1!

y

i

y

h

.

ii

,

(4.3a)

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

y

′′

i

y

i

+

2

2

+

yy

1

ii

+

h

2

.

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

y

i

y

i

y

i

1

h

.

(4.3b)

yas a subject in

i

(4.4a)

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

y

′′

i

yyy

1

iii

2

+

2

h

2

.

(4.4b)

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, y

i

y

i

+

1

y

i

1

2 h

.

4-3

(4.5a)

Shaharuddin Salleh

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

y

′′ ≈

i

y

i

+

1

2

+

yy

ii

1

h

2

.

(4.5b)

4.3 NUMERICAL INTEGRATION

b

a

f

(

x

)

dx

An integral of the form

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.

in the interval axb≤ ≤

has many applications especially in science 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, Simpson’s 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 axb

. 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 axbeach with width h . A straight line is connected from (

x

i

,

is divided into m equal-width subintervals,

f

(

x

i

))

to

(

x

i

+

1

,

fx

(

i

+

1

))

in the subinterval

x

[,

i

x

i

+ 1

]

and this forms a trapezium with

f

(

x

i

)

and

f

(

x

i

+ 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

x

x

i

i

+ 1

f

(

x

)

dx

h

2

(

f

(

x

i

)

+

f

(

x

i + 1

)

)

. With m subintervals,
∫ b
f
(
x dx
)
is approximated as the sum of all the areas of the trapeziums,
a
given as
m − 1
h
∫ b
f
(
x
)
dx
(
f
(
x
)
+
f
(
x
)
)
i
i + 1
a
2
i = 0
h
=
[
fx
(
)
+
fx
(
)
+
2
{
(
fx
(
)
+
fx
(
)
++
fx
(
)
}
]
(4.6)
0
m
12
m −
1
2
f (x 0 )
f (x 3 )
f (x 2 )
f (x 1 )
f (x 4 )
f (x)
A 1
A 2
A 3
A 4
x
x 0
x 1
x 2
x 3
x 4

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

four equal subintervals. From the figure, it is clear that

x

4

x

0

f

(

x

)

dx

for

x

0

x x

4

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

subareas

hxxm= (

4

0

)/

. The total area is then approximated as the sum of the

A i for i = 1,2,3,4 , given as

b

a

f

=

=

x

)

(

dx ≈+++A

A

A

A

1234

f

()

x

++fx

()

)

01

(

fx

()

2

[

f

(

++fx

x

)

(

04

)

2(

fx

(

)

(

hhhh

++fx

()

12

++fx

(

)

)

(

fx

()

))]

++fx

()

)

2222

h

23

.

fx

(

123

(

+ fx

fx

()

()

34

)

Simpson’s Method

The trapezium method uses a straight line approximation on two successive f (x) values in the

subintervals for evaluating

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 Simpson’s method.

b

a

f

(

x

)

dx

for axb

. A straight line approximation may not produce a y i
y i+2
y i+1
A i
x i
x i+1
x i+2

x

Figure 4.4. Quadratic polynomial fitting on two subintervals in the Simpson’s method.

As the Simpson’s method requires two subintervals in each pair, the total number of subintervals

in the given interval must be an even number. Consider the subintervals

(

involve the points, (

dotted curve as the quadratic approximation to the real curve. This curve has an equation given by

x

[,

i

x

i

+

1

]

and

[,

x

i

+

1

x

i

+

2

]

which

x

i

,

f

(

x

i

))

,

(

x

i

+

1

,

fx

(

i

+

1

))

and

x

i

+

2

,

fx

(

i

+

2

))

. Figure 4.4 shows this scenario with the 4-6

Shaharuddin Salleh

where

x

(,

i

y

i

)

a

,

0

,

a

1

(,

x

i

+

1

y =+a

01

ax + ax

2

2

and

y

i

+

1

)

a

2

are the constants that are to be determined. The quadratic curve interpolates

and

(,

x

i

+

2

y

i

+

2

)

. This produces a system of linear equations, given as

y

y

y

i

i

+

i +

2

=+a ax + ax ,

01

ii2

1

=+

a

0

2

ax

11ii21 ++

+

ax

,

2

=+

a

0

2

ax

12ii22 ++

+

ax

.

The above system is solved to produce the Simpson’s formula, given by

x

x

i

i + 2

f

x

( )

dx

h

3

(

y

4

++

iii

+

y

1

y

+

2

)

.

Equation (4.7) can be extended into the case of m even subintervals for

x = x

0

to

(4.7)

x = x

m

. 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 Simpson’s method for m subintervals, as follows:

x

m

x

0

f

(

x

)

dx

=

hh

(

3

[

y

0

+

4

y

+

12

4(

y

)

+

(

y

2

+

4

y

33

h

34

)

+

y

)

(

+

yy

0

)

+

+ ++

yy

13

y

1

nn

2(

h

+ ++

3

(

y

m

2

+

+ ++

yy

24

4

y

y

n

+

mm

1

y

2

)

]

)

(4.8)

An extension to the Simpson’s method is the Simpson’s 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 Simpson’s 3/8 method becomes a multiple of three. Interpolation over four points for each subarea in the Simpson’s 3/8 method produces a system of four linear equations. The interpolating curve is a cubic polynomial given by

where

(,

x

i

+

3

y

i

a

+

3

0

)

,

a

1

y =+a ax + ax + ax ,

01

2

3

2

3

and

a

2

are constants. The above curve interpolates (,

x

i

y

i

)

to produce an approximated subarea, given by

x

x

i

i

+ 3

f

x

( )

dx

3

h

8

(

y

+++

y

ii

+

1

y

i

y

23

i

++

3

3

)

.

,

(,

x

i

+

1

y

i

+

1

)

,

(,

x

i

+

2

y

i

+

(4.9)

2

)

and

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

x

m

x

0

f

(

x

) dx

3

h

8

[

(

y

0

+

y

n

)

+

2(

y

+ y ++

36

y

n

3

)

+

4-7

3(

y

1245

+

y

+ y + y ++

y

+

nn

−−

2

y

1

)

]

.

(4.10)

Shaharuddin Salleh

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:

(

Px

n

)

=

1

2

n

n

!

d

n

dx

n

(

(

2

x

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

where δ

mn

1

1

P

m

() x P

n

() x dx =

2

2

n +

1

δ

mn

,

is the Kronecker delta.

Table 4.1. Legendre polynomials.

 n P ( x ) n 0 1 1 x 2 (3 x 2 − 1) / 2 3 (5x 3 − 3x) / 2 4 (35x − 30x + 3) /8 4 2 5 (63x − 70x +15x) / 8 5 3 6 642

(231xxx−+−315 105 5) /16 f (a )
f (b )
f (x)
x
a
b
Figure 4.5. Transformation from
∫ b
f
(
x
)
dx
to
a y
g (t)
-1
1
1 1 g(t) dt
in the Gauss-Legendre’s method.

t 4-8

Shaharuddin Salleh

Gaussian quadrature method consists of two major steps. First, the integral

b

a

f

(

x

)

dx

in the

interval axb≤ ≤

relationship given by

is transformed into the form of

1 1 g(t) dt . This is achieved through a linear

x =

(

b

)(

− ++

at

b

a

)

2

,

(4.12)

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

preserves the area under the curve in

1 1 g(t) dt

, as illustrated in Figure 4.5. We have

f

(

x

)

dx

b = ⎜ ⎝

a

2

⎞⎛ (

⎟⎜ ⎠⎝ f

b

− ++

)(

at

b

a

)

⎟ ⎠

2

dt

.

b

a

f

(

x

)

dx

=

b

a

b

⎜ ⎝

2

a

⎞⎛ (

⎟⎜ ⎠⎝ f

b

)(

− ++

at

b

a

)

⎟ ⎠

2

()

gt

b = ⎜ ⎝

a

2

⎞⎛ (

⎟⎜ f

⎠⎝

b

)(

− ++

at

b

a

)

2

.

dt

.

The second step in this method consists of an approximation to the integral

1

1

( )

g t

dt

n

i = 1

(

w g t

i

i

)

.

(4.13)

1 1 g(t) dt

through a

(4.14)

The above equation is called the n point Gauss quadrature where n is an integer number greater than

1. The constant

w i is called the weight while

t i is the argument in the quadrature. The argument t in

i

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, w i Argument, t i 2 3 w 1 =1 w =1 2 w 1 = 0.555556 t 1 =− 1/ 3 =−0.577350 t t =− 2 = 1/ 3 = 0.577350 1 3/ 5 =−0.774597 w 2 w 3 = 0.888889 = 0.555556 t t 2 3 = 0 = 3/ 5 = 0.774597 4 w 1 = 0.347855 t 1 = −0.861136 w 2 = 0.652145 t 2 = −0.339981 w 3 = 0.652145 t 3 = 0.339981 w 4 = 0.347855 t 4 = 0.861136 5 w 1 = 0.236927 t 1 = −0.90610 w 2 = 0.478629 t 2 = −0.538469 w 3 = 0.568889 t 3 = 0 w 4 = 0.478629 t 4 = 0.538469 w 5 = 0.236927 t 5 = 0.90610 4-9

Shaharuddin Salleh

Fast Example 1: Differentiations using Newton’s methods

Example 4.1. Given yx=

an equal width given by h = 0.3333 using the forward, backward and central-difference methods.

sin x , find yand y′′ at the points along 0 x 2 whose subintervals have

Solution In this problem, m =−(2

0) /.3333 = 6 . The analytical derivatives are given by y′ = sin xx+

cos x and

y ′′ = 2cos xx

sin x . Table 4.1 plots the values of x and

i

y

i

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 ,

(4.3b):

yand

0

y ′′ can be evaluated using the forward-di fference rules using Equation (4.3a) and

0

y

′≈= y y

0

y

1

2

h

0

2

+

yy

10

0.1090

0

0.3333

0.4122

= 0.3270

,

2(0.1090)

+

0

y ′′ ≈=

0

h

2

0.3333

2

=

1.7481

.

It is not possible to evaluate

methods involve the terms

Table 4.1. Through comparison with the analytical (exact) method, the central-difference method produces the closest approximations for the derivatives.

y

yand

0

1

and

y ′′ using the backward and central-difference rules as both which do not exist. The results at other points are shown in

y

0

2

Table 4.1. The numerical results from Example 4.1.

 Analytical Forward- Backward- Central-difference Solutions difference difference i x i y i y′ i y′′ i y′ i y′′ i y′ i y′′ i y′ i y′′ i 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

 i + 1 h One-Interval Trapezium Method: ∫ x f ( x ) dx ≈ [ y i + y i + 1 ] General Trapezium Method: ∫ x n f ( x ) x i dx ≈ h [ ( y 0 2 + y n ) + 2( y 1 + y 2 + + y n − 1 ] 1.9 x 0 2 ∫ 1 f (x) dx using the Trapezium method from the following data: i 0 1 2 3 4 5 6 7 8 9 x i 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 y i = f i 2.5 2.8 2.7 2.6 2.3 2.1 2.4 2.3 2.6 3.0 f (x) dx ≈ A = A h 1 + A 2 + A + A 3 h 4 + A + A + A + A 5 6 7 h h 8 + A 9 = 2 ( y 0 + y 1 ) + 2 ( y 1 + y 2 ) + 2 ( y 2 + y 3 ) + 2 ( y 3 + y 4 ) h h h h h + 2 ( y 4 + y 5 ) + 2 ( y 5 + y 6 ) + 2 ( y 6 + y 7 ) + 2 ( y 7 + y 8 ) + 2 ( y 8 + y 9 ) h = 2 [ ( y 0 + y 9 ) + 2( y 1 + y 2 + y 3 + y 4 + y 5 + y 6 + y 7 + y 8 ] 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

Find

Solution

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

Therefore,

1.9

1 4-11

Shaharuddin Salleh

Fast Example 3: Simpson Method

(condition: n is an even number)

Formula

 x i + 2 h ( f [( y 0 ) y 2-interval Simpson Method: General Simpson Method: ∫ x ∫ n x 0 f ( x ) dx ≈ x i 3 f ( x ) dx ≈ h 3 i + + y 4 n f i + ) + 1 + 4( f i y 1 + 2 + 3 + + y n − 1 ) + 2( y 2 + y 4 + + y n − 2 1.8 ∫ 1 f (x) dx using the Simpson method from the following data: i 0 1 2 3 4 5 6 7 8 x i 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 y i = f i 2.5 2.8 2.7 2.6 2.3 2.1 2.4 2.3 2.6 f (x) dx ≈ A = A 1 + A 2 + A + A 3 4 = h 3 ( y 0 + 4 y 1 + y 2 ) + h 3 ( y 2 + 4 y 3 + y 4 ) + h 3 ( y 4 + 4 y 5 + y 6 ) + h