Download as pdf or txt
Download as pdf or txt
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

LESSON OUTCOMES
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

DIFFERENTIATION
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:
y f ( xi x) f ( xi )

x
x

y and f(x) dependent variable


x is dependent variable

If x is allowed to approach zero, the differences becomes a


derivative
dy/dx : first derivative of y with
f ( xi x) f ( xi )
dy
lim
dx x0
x

respect to x evaluated at xi.

derivative slope of the


tangent to the curve at xi

INTEGRATION
Integrate to bring together, as parts, into a whole; to unite; to
indicate the total amount.
Mathematical definition represented by
b

I f ( x) dx
a

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.

The integral is
equivalent to the
area under the curve

NONCOMPUTER METHODS FOR


DIFFERENTIATION AND INTEGRATION

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.
6

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.
7

A noncomputer method for determining integration from data :


(a) A complicated,
continous function
(b) Table of discrete
values of f(x) generated
from the function
The use of grid to
approximate an integral

The use of rectangles or strips to


approximate an integral

(c) Use of numerical


method to estimate the
integral on the basis of
the discrete points.

Application of a numerical
integration or quadrature
method
8

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:
b

I f ( x)dx f n ( x)dx
where f n ( x) form of polynomial
f n ( x) a0 a1 x an 1 x n 1 an x n
9

(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 straightline segments

10

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.
11

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:
b

I f ( x)dx f1 ( x)dx

The area under this first order polynomial is an estimate of


the integral of f(x) between the limits of a and b:
Trapezoidal Rule

f (a) f (b)
I (b a)
2

12

I f ( x)dx f1 ( x)dx
f1 ( x) f ( x0 ) f ( x1 ) f ( x0 )

x x0
x1 x0
f1 ( x) f ( x0 )
f1 ( x) f (a )

f ( x1 ) f ( x0 )
( x x0 )
x1 x0
f (b) f (a )
( x a)
ba

f (b) f (a)

I f (a)
( x a) dx
ba

a
b

f (a) f (b)
I (b a)
2

Derivation:
Refer Box 21.1
(page 603) text book
13

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

f (a) f (b)
I (b a)
2
14

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:
1
1
Et
f ' ' (x )(b a)3
f ' ' (b a)3
12

12

where x 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.
Derivation and Error Estimate:
Refer Box 21.2
(page 606) text book

15

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.

16

General format for multiple


application integrals

ba
n

a x0

b xn

n segments equally
I

x1

x2

xn

x0

x1

xn1

f ( x)dx f ( x)dx f ( x)dx

f ( x0 ) f ( x1 )
f ( xn1 ) f ( xn )
f ( x1 ) f ( x2 )
I h
h
h
2
2
2
I

f
(
x
)

2
f
(
x
)

f
(
x
)

0
i
n

2
i 1

n 1

n 1

I (b a)

f ( x0 ) 2 f ( xi ) f ( xn )
i 1

2n
17

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:

(b a ) 3 n
Et
f (x i )
3
12n i 1

f (x ) nf
i

(b a ) 3
Ea
f
2
12n

18

Example
Given f(x)=0.2+25x200x2+675x3900x4+400x5
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.
19

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.

20

Simpsons 1/3 Rule


Results when a second-order interpolating polynomial is used.
b

I f ( x)dx f 2 ( x)dx
a

a x0

b x2

f 2 ( x) is represented using second - order Lagrange polynomial,


( x x1 )( x x2 )

( x x0 )( x x2 )
( x x0 )( x x1 )
I
f ( x0 )
f ( x1 )
f ( x2 )dx
( x0 x1 )( x0 x2 )
( x1 x0 )( x1 x2 )
( x2 x0 )( x2 x1 )

x0
h
ba ba
I f ( x0 ) 4 f ( x1 ) f ( x2 )
h

3
n
2
or
f ( x0 ) 4 f ( x1 ) f ( x2 )
I (b a )
6
(b a)
where a x 0 , b x 2 and x1 the point midway between a and b; x1
2
x2

Single segment application of Simpsons 1/3 rule has a truncation error of:
(b a)5 ( 4)
Et
f (x )
2880

a x b

Simpsons 1/3 rule is more accurate than trapezoidal rule.


21

The Multiple-Application Simpsons 1/3 Rule


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.
n 1

I (b a)

f ( x0 ) 4 f ( xi ) 2
i 1, 3, 5

n2

f (x ) f (x )

j 2, 4, 6

3n
(b a)5 ( 4)
Ea
f
4
180 n
22

Example
Given f(x)=0.2+25x200x2+675x3900x4+400x5

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.
23

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.
b

I f ( x)dx f 3 ( x)dx
3h
I f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 )
8
f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 )
I b a
8
(b a ) 5 ( 4 )
Et
f (x )
6480
More accurate

(b a )
h
n

24

Illustration of how Simpsons 1/3 and 3/8 rules


can be applied in tandem to handle multiple
applications with odd numbers of intervals.
25

Example
Given f(x)=0.2+25x200x2+675x3900x4+400x5
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.

26

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.
f ( x0 ) f ( x1 )
f ( xn1 ) f ( xn )
f ( x1 ) f ( x2 )
I h
h
h
2
2
2
In other method, inclusion of trapezoidal rule and Simpson's
Rule for unequal segments.

27

Example
Given data for f(x)=0.2+25x200x2+675x3900x4+400x5.
Given that the exact value of the integral that determined
analytically is 1.640533. Find true percent relative error.
x

f(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

Use following method to determine the integral for this data.


a) Trapezoidal rule with unequal segments
b) Inclusion of Trapezoidal and Simpsons rules
28

Numerical Differentiation
Forward finite divided difference

Backward finite divided difference

Centered finite divided difference

29

HIGH-ACCURACY DIFFERENTIATION FORMULAS


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
f " ( xi ) 2
f ( xi 1 ) f ( xi ) f ' ( xi )h
h ...
2
which can be solved for
f ( xi 1 ) f ( xi ) f " ( xi )
f ' ( xi )

h O(h 2 )
h
2
So, first forward difference
(excluding second and higher derivative terms) :
f ( xi 1 ) f ( xi )
f ' ( xi )
O ( h)
h
30

For second derivative term by substituting the approximation


of the second derivative,
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
Refer Text book
f " ( xi )

O
(
h
)
Page 92 & 93
h2
into first forward difference to yield
f ( xi 1 ) f ( xi ) f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
2
f ' ( xi )

O
(
h
)
2
h
2h
or, by collecting terms,
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
f ' ( xi )
O(h 2 )
2h
* This equation incorporates more terms of Taylor
series expansion and more accurate.
31

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.

h4

32

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.

33

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.

34

Example
Estimated the first derivative of
f(x) = 0.1x4 0.15x3 0.5x2 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(h2).
b) Use high-accuracy formulas of finite divided differences.

35

Solution

From calculatio n,
xi 2 0
xi 1 0.25
xi 0.5
xi 1 0.75
xi 2 1

f xi 2 1.2

f xi 1 1.1035
f xi 0.925

f xi 1 0.6363

f xi 2 0.2

Forward
O(h)

Backward
O(h)

Centered
O(h2)

Estimate

-1.155

-0.714

-0.934

t (%)

-26.5

21.7

-2.4

Forward
O(h2)

Backward
O(h2)

Centered
O(h4)

Estimate

-0.8594

-0.8781

-0.9125

t (%)

5.82

3.77

0
36

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.

37

Formula improvement of integral estimate, I


1
I I (h2 )
[ I (h2 ) I (h1 )]
2
(h1 / h2 ) 1
where I (h1 ) and I (h2 ) are integral estimates using two step sizes h1 and h 2 .
This formula written for the case where h2 h1 / 2,
1
I I (h2 )
[ I (h2 ) I (h1 )]
2
(h1 (2 / h1 )) 1
1
I I (h2 ) 2 [ I (h2 ) I (h1 )]
(2) 1
4
1
I I (h2 ) I (h1 )]
3
3
Similar fashion written for derivatives,
4
1
D D(h2 ) D(h1 )]
3
3

For centered difference


approximations with O(h2),
the application of this
formula will yield a new
derivative estimate of O(h4).

Example
Estimated the first derivative of
f(x) = 0.1x4 0.15x3 0.5x2 0.25x + 1.2
at x = 0.5 employing step sizes of h1 = 0.5 and h2 = 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

f ( xi 1 ) f ( xi 1 ) 0.2 1.2

1.0
t 9.6%
2h
2(0.5)
f ( xi 1 ) f ( xi 1 ) 0.6363 1.1035
D(h2 0.25) f ' ( xi )

0.9344 t 2.4%
2h
2(0.25)
4
1
4
1
D D(h2 ) D(h1 ) (0.9344) (1.0) 0.9125
t 0%
3
3
3
3
D(h1 0.5) f ' ( xi )

39

You might also like