You are on page 1of 39

# WEEK 8 & 9

## Numerical Integration and Differentiation

Newton-Cotes integration formulas:
Trapezoidal rule
Simpsons Rule
Integration with unequal segments
Numerical differentiation:
High accuracy differentiation formula
Richardson extrapolation 2
At the end of this topic, the students will be able:

To identify and apply the methods outlines
to integrate formulae and data set

To identify and apply the methods outlines to
differentiate formulae and data set
LESSON OUTCOMES
4
Derivative represents the rate of change of a dependent
variable with respect to an independent variable given by
mathematical definition begin with a difference approximation:

If x is allowed to approach zero, the differences becomes a
derivative
x
x f x x f
x
y
i i
A
A +
=
A
A ) ( ) (
x
x f x x f
dx
dy
i i
x
A
A +
=
A
) ( ) (
lim
0
y and f(x) dependent variable
x is dependent variable
dy/dx : first derivative of y with
respect to x evaluated at x
i
.
derivative slope of the
tangent to the curve at x
i
DIFFERENTIATION
5
INTEGRATION
Integrate to bring together, as parts, into a whole; to unite; to
indicate the total amount.
Mathematical definition represented by

which stands for the integral of the function f(x) with respect to the
independent variable x, evaluated between the limits x=a to x=b.
}
=
b
a
dx x f I ) (
The integral is
equivalent to the
area under the curve
6
The function to be differentiated or integrated
will typically be in one of the following three
forms:
A simple continuous function such as polynomial,
an exponential, or a trigonometric function.
A complicated continuous function that is difficult
or impossible to differentiate or integrate directly.
A tabulated function where values of x and f(x) are
given at a number of discrete points, as is often
the case with experimental or field data.

NONCOMPUTER METHODS FOR
DIFFERENTIATION AND INTEGRATION
7
A noncomputer method for determining derivatives from data :
equal-area graphical differentiation
Centered finite divided
differences are used to
estimates the derivative
for each interval between
the data points
Then, these values are
plotted as a stepped
curve versus x. That is, it
is drawn so that visually,
the positive and negative
area are balance.
Then, values of dy/dx
can be read off the
smooth curve at given
valus of x.
8
A noncomputer method for determining integration from data :
The use of grid to
approximate an integral
The use of rectangles or strips to
approximate an integral
Application of a numerical
integration or quadrature
method
(a) A complicated,
continous function
(b) Table of discrete
values of f(x) generated
from the function
(c) Use of numerical
method to estimate the
integral on the basis of
the discrete points.
9
Newton-Cotes Integration Formulas
The Newton-Cotes formulas are the most common numerical
integration schemes.

They are based on the strategy of replacing a complicated
function or tabulated data with an approximating function
that is easy to integrate:

n
n
n
n n
n
b
a
n
b
a
x a x a x a a x f
x f
dx x f dx x f I
+ + + + =
~ =

} }
1
1 1 0
) (
polynomial of form ) ( where
) ( ) (

10
(a) First-order
polynomial (straight
line) is used as an
approximation
(b) A parabola is
employed as an
approximation
The integral can also be approximated using a series of polynomials applied
piecewise to the function or data over segments of constant length.
The approximation of
an integral by the area
under three straight-
line segments
11
Closed and open forms of the Newton-Cotes formulas
are available.

Closed forms where the data
points at the beginning and end of
the limits of integration are known.
Open forms where have
integration limits that extend
beyond the range of the data.
This formulas not generally used
for difinite integration.
However, they are utilized for
evaluating improper integrals and for
solution of ODE.
12
THE TRAPEZOIDAL RULE
The Trapezoidal rule is the first of the Newton-Cotes closed
integration formulas, corresponding to the case where the
polynomial is first order:

The area under this first order polynomial is an estimate of
the integral of f(x) between the limits of a and b:

} }
~ =
b
a
b
a
dx x f dx x f I ) ( ) (
1
2
) ( ) (
) (
b f a f
a b I
+
= Trapezoidal Rule
13
) (
) ( ) (
) ( ) (
) (
) ( ) (
) ( ) (
) ( ) ( ) ( ) (
1
0
0 1
0 1
0 1
0 1
0 1
0
0 1
a x
a b
a f b f
a f x f
x x
x x
x f x f
x f x f
x x
x f x f
x x
x f x f

+ =

+ =

} }
~ =
b
a
b
a
dx x f dx x f I ) ( ) (
1
} (

+ =
b
a
dx a x
a b
a f b f
a f I ) (
) ( ) (
) (
2
) ( ) (
) (
b f a f
a b I
+
=
Derivation:
Refer Box 21.1
(page 603) text book
14
Geometrically, the trapezoidal rule is equivalent to
approximating the area of the trapezoid under the straight
line connecting f(a) and f(b).

(a) Area of trapezoid height x average bases
(b) I width x average height
I (b a) x average height
Average height = f(a) + f(b)
2
2
) ( ) (
) (
b f a f
a b I
+
=
15
Error of the Trapezoidal Rule
When we employ the integral under a straight line segment
to approximate the integral under a curve, error may be
substantial:

where lies somewhere in the interval from a to b.
If the function being integrated is linear, the trapezoidal rule
will be exact.
Otherwise, for functions with second and higher order
derivatives (curvature), some error can occur.

3 3
) ( ' '
12
1
) )( ( ' '
12
1
a b f a b f E
t
= =
Derivation and Error Estimate:
Refer Box 21.2
(page 606) text book
16
The Multiple-Application Trapezoidal Rule
One way to improve the accuracy of the trapezoidal rule is to
divide the integration interval from a to b into a number of
segments and apply the method to each segment.
The areas of individual segments can then be added to yield
the integral for the entire interval.
The resulting equations are called multiple-application or
composite integration formulas.

17
} } }

+ + + =
= =

=
n
n
x
x
x
x
x
x
n
dx x f dx x f dx x f I
n
x b x a
n
a b
h
1
2
1
1
0
) ( ) ( ) (
equally segments

0

2
) ( ) (
2
) ( ) (
2
) ( ) (
1 2 1 1 0 n n
x f x f
h
x f x f
h
x f x f
h I
+
+ +
+
+
+
=

+ + =

=
1
1
0
) ( ) ( 2 ) (
2
n
i
n i
x f x f x f
h
I
n
x f x f x f
a b I
n
i
n i
2
) ( ) ( 2 ) (
) (
1
1
0

=
+ +
=
General format for multiple
application integrals
18
Error of the multiple-application Trapezoidal Rule

An error for multiple-application trapezoidal rule can be
obtained by summing the individual errors for each segment:

f
n
a b
E
f n f
f
n
a b
E
a
i
n
i
i t
' '

=
' '
~
' '
' '

=
2
3
1
3
3
12
) (
) (
) (
12
) (

19
Example

Given f(x)=0.2+25x200x
2
+675x
3
900x
4
+400x
5

Use following method to estimate the integral of given
equation from a = 0 to b = 0.8.
a) Single application of the Trapezoidal Rule
b) Multiple application of the Trapezoidal Rule (2 segments)

Given that the exact value of the integral that determined
analytically is 1.640533.
Find true percent relative error and estimated error of
the Trapezoidal Rule.

20
THE SIMPSONS RULES
More accurate estimate of an integral is obtained if a
high-order polynomial is used to connect the points. The
formulas that result from taking the integrals under such
polynomials are called Simpsons rules.
(a) Graphical depiction
of Simpsons 1/3 rule:
It consists of taking the
area under a parabola
connecting three points.
(b) Graphical depiction
of Simpsons 3/8 rule:
It consists of taking the
area under a cubic
equation connecting
four points.
21
Simpsons 1/3 Rule
Results when a second-order interpolating polynomial is used.
| |

2
a) (b
x b; and a between midway point the x and x b , x a where

6
) ( ) ( 4 ) (
) (
or
2
) ( ) ( 4 ) (
3

) (
) )( (
) )( (
) (
) )( (
) )( (
) (
) )( (
) )( (
, polynomial Lagrange order - second using d represente is ) (
) ( ) (
1 1 2 0
2 1 0
2 1 0
2
1 2 0 2
1 0
1
2 1 0 1
2 0
0
2 0 1 0
2 1
2
2 0 2
2
0
+
= = = =
+ +
~

= + + ~
(

+

+

=
= = ~ =
}
} }
x f x f x f
a b I
a b
n
a b
h x f x f x f
h
I
dx x f
x x x x
x x x x
x f
x x x x
x x x x
x f
x x x x
x x x x
I
x f
x b x a dx x f dx x f I
x
x
b
a
b
a
Single segment application of Simpsons 1/3 rule has a truncation error of:

Simpsons 1/3 rule is more accurate than trapezoidal rule.
b a f
a b
E
t
< <

= ) (
2880
) (
) 4 (
5
22
Just as the trapezoidal rule, Simpsons rule can be improved
by dividing the integration interval into a number of segments
of equal width.
Yields accurate results and considered superior to trapezoidal
rule for most applications.
However, it is limited to cases where values are equispaced.
Further, it is limited to situations where there are an even
number of segments and odd number of points.

The Multiple-Application Simpsons 1/3 Rule
) 4 (
4
5
1
5 , 3 , 1
2
6 , 4 , 2
0
180
) (

3
) ( ) ( 2 ) ( 4 ) (
) (
f
n
a b
E
n
x f x f x f x f
a b I
a
n
i
n
n
j
j i

=
+ + +
=

=
23
Example

Given f(x)=0.2+25x200x
2
+675x
3
900x
4
+400x
5

Use following method to estimate the integral of given
equation from a = 0 to b = 0.8.
a) Single application of the Simpsons 1/3 Rule
b) Multiple application of the Simpsons 1/3 Rule with n=4.

Given that the exact value of the integral that determined
analytically is 1.640533.
Find true percent relative error and estimated error of
the Simpsons Rule.
24
Simpsons 3/8 Rule
An odd-segment-even-point formula used in conjunction with
the 1/3 rule to permit evaluation of both even and odd
numbers of segments.
The equation called Simpsons 3/8 rule because h is multiplied
by 3/8.
| |
( )
) (
6480
) (
8
) ( ) ( 3 ) ( 3 ) (
) (
) ( ) ( 3 ) ( 3 ) (
8
3
) ( ) (
) 4 (
5
3 2 1 0
3 2 1 0
3
f
a b
E
x f x f x f x f
a b I
n
a b
h x f x f x f x f
h
I
dx x f dx x f I
t
b
a
b
a

=
+ + +
~

= + + + ~
~ =
} }
More accurate
25
Illustration of how Simpsons 1/3 and 3/8 rules
can be applied in tandem to handle multiple
applications with odd numbers of intervals.
26
Example

Given f(x)=0.2+25x200x
2
+675x
3
900x
4
+400x
5

Use following method to estimate the integral of given
equation from a = 0 to b = 0.8.
a) Simpsons 3/8 Rule
b) Use Simpsons 3/8 Rule in conjuction with Simpsons 1/3 Rule
to integrate the same function for five segments.

Given that the exact value of the integral that determined
analytically is 1.640533. Find true percent relative error.
27
INTEGRATION WITH UNEQUAL SEGMENTS
In practice, many situations deal with unequal-sized segments.
In that case, one method is apply the trapezoidal rule to each
segment and sum the results.

In other method, inclusion of trapezoidal rule and Simpson's
Rule for unequal segments.
2
) ( ) (
2
) ( ) (
2
) ( ) (
1 2 1 1 0 n n
x f x f
h
x f x f
h
x f x f
h I
+
+ +
+
+
+
=

28
Example
Given data for f(x)=0.2+25x200x
2
+675x
3
900x
4
+400x
5
.
Given that the exact value of the integral that determined
analytically is 1.640533. Find true percent relative error.

Use following method to determine the integral for this data.
a) Trapezoidal rule with unequal segments
b) Inclusion of Trapezoidal and Simpsons rules
x f(x) x f(x)
0.0 0.200000 0.44 2.842985
0.12 1.309729 0.54 3.507297
0.22 1.305241 0.64 3.181929
0.32 1.743393 0.70 2.363000
0.36 2.074903 0.80 0.232000
0.40 2.456000
Forward finite divided difference
Backward finite divided difference
Centered finite divided difference
29
Numerical Differentiation
30
High-accuracy divided difference formulas can be
generated by including additional terms from the Taylor
series expansion.
For example, the forward Taylor series expansion can be
written as
) (
) ( ) (
) ( '
: terms) derivative higher and second (excluding
difference forward first So,
) (
2
) ( " ) ( ) (
) ( '
for solved be can which
...
2
) ( "
) ( ' ) ( ) (
1
2
1
2
1
h O
h
x f x f
x f
h O h
x f
h
x f x f
x f
h
x f
h x f x f x f
i i
i
i i i
i
i
i i i
+

=
+

=
+ + + =
+
+
+
HIGH-ACCURACY DIFFERENTIATION FORMULAS
31
) (
2
) ( 3 ) ( 4 ) (
) ( '
terms, collecting by or,
) (
2
) ( ) ( 2 ) ( ) ( ) (
) ( '
yield to difference forward first into
) (
) ( ) ( 2 ) (
) ( "
, derivative second the of
ion approximat the ng substituti by term derivative second For
2
1 2
2
2
1 2 1
2
1 2
h O
h
x f x f x f
x f
h O h
h
x f x f x f
h
x f x f
x f
h O
h
x f x f x f
x f
i i i
i
i i i i i
i
i i i
i
+
+
=
+
+

=
+
+
=
+ +
+ + +
+ +
* This equation incorporates more terms of Taylor
series expansion and more accurate.
Refer Text book
Page 92 & 93
32
Forward finite-divided difference formulas: two versions are presented for each
derivative. The latter version incorporates more terms of Taylor Series expansion
and consequently more accurate.
h
4
33
Backward finite-divided difference formulas: two versions are presented for
each derivative. The latter version incorporates more terms of Taylor Series
expansion and consequently more accurate.
34
Centered finite-divided difference formulas: two versions are presented for each
derivative. The latter version incorporates more terms of Taylor Series expansion
and consequently more accurate.
35
Example

Estimated the first derivative of
f(x) = 0.1x
4
0.15x
3
0.5x
2
0.25x + 1.2
at x = 0.5 using finite divided differences and a step size of h = 0.25.

a) Use forward and backward differences approximations
of O(h) and centered difference approximation of O(h
2
).

b) Use high-accuracy formulas of finite divided differences.
36
( )
( )
( )
( )
( ) 2 . 0 1
6363 . 0 75 . 0
925 . 0 5 . 0
1035 . 1 25 . 0
2 . 1 0
n, calculatio From
2 2
1 1
1 1
2 2
= =
= =
= =
= =
= =
+ +
+ +

i i
i i
i i
i i
i i
x f x
x f x
x f x
x f x
x f x
Forward
O(h)
Backward
O(h)
Centered
O(h
2
)
Estimate -1.155 -0.714 -0.934

t
(%) -26.5 21.7 -2.4
Forward
O(h
2
)
Backward
O(h
2
)
Centered
O(h
4
)
Estimate -0.8594 -0.8781 -0.9125

t
(%) 5.82 3.77 0
Solution
37
RICHARDSON EXTRAPOLATION
Richardson extrapolation is a method uses two
estimates of an integral to compute a third, more
accurate approximation.

Two ways to improve derivative estimates when
employing finite divided difference:
1) decrease the step size
2) use a higher-order formula that employs
more point.
)] (
3
1
) (
3
4

s, derivative for itten fashion wr Similar
)] (
3
1
) (
3
4

)] ( ) ( [
1 ) 2 (
1
) (
)] ( ) ( [
1 )) / 2 ( (
1
) (
, 2 / where case for the written formula This
. h and h sizes step two using estimates integral are ) ( and ) ( where
)] ( ) ( [
1 ) / (
1
) (
estimate, integral of t improvemen Formula
1 2
1 2
1 2
2
2
1 2
2
1 1
2
1 2
2 1 2 1
1 2
2
2 1
2
h D h D D
h I h I I
h I h I h I I
h I h I
h h
h I I
h h
h I h I
h I h I
h h
h I I
I
~
~

+ ~

+ ~
=

+ ~
For centered difference
approximations with O(h
2
),
the application of this
formula will yield a new
derivative estimate of O(h
4
).
39
Example

Estimated the first derivative of
f(x) = 0.1x
4
0.15x
3
0.5x
2
0.25x + 1.2
at x = 0.5 employing step sizes of h
1
= 0.5 and h
2
= 0.25.
Compute an improved estimate with Richardson extrapolation.
The true value is -0.9125.
Solution
The first derivative estimates can be computed with centered
differences

% 0 9125 . 0 ) 0 . 1 (
3
1
) 9344 . 0 (
3
4
) (
3
1
) (
3
4
% 4 . 2 9344 . 0
) 25 . 0 ( 2
1035 . 1 6363 . 0
2
) ( ) (
) ( ' ) 25 . 0 (
% 6 . 9 0 . 1
) 5 . 0 ( 2
2 . 1 2 . 0
2
) ( ) (
) ( ' ) 5 . 0 (
t 1 2
t
1 1
2
t
1 1
1
= = = =
= =

= = =
= =

= = =
+
+
c
c
c
h D h D D
h
x f x f
x f h D
h
x f x f
x f h D
i i
i
i i
i