0% found this document useful (0 votes)
4 views10 pages

Numerical Differentiation Examples

Uploaded by

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

Numerical Differentiation Examples

Uploaded by

sheryar badini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lecture 42

Examples of Numerical Differentiation

The simplest formula for differentiation is

1 h2
f ′( x0 ) = [ f ( x0 + h) − f ( x0 )] − f (2) (ξ ),
h 2

Example
Let f(x)= In x and x0 = 1.8. Then quotient
f (1.8 + h) − f (1.8)
, h > 0,
h
is used to approximate f ′(1.8) with error
hf ′′(ξ ) h h
= ≤ , where 1.8 < ξ < 1.8 + h.
2 2ξ 2
2(1.8) 2
Let us see the results for h = 0.1, 0.01, and 0.001.

h f(1.8 + h) f (1.8 + h) − f (1.8) h


h 2(1.8) 2

0.1 0.64185389 0.5406722 0.0154321

0.01 0.59332685 0.5540180 0.0015432

0.001 0.58834207 0.5554013 0.0001543


Since f ′( x) = 1/ x,

The exact value of f ′(1.8) is 0.555 and the error bounds are a appropriate.
The following two three point formulas become especially useful if the nodes are equally spaced,
that is, when
x1 = x0 + h and
x2 = x0 + 2h,
1 h2
f ′( x0 ) = [ −3 f ( x0 ) + 4 f ( x0 + h) − f ( x0 + 2h)] + f (3) (ξ0 ),
2h 3
where ξ0 lies between x0 and x0 + 2h, and
1 h 2 (3)
f ′( x0 ) = [ f ( x0 + h) − f ( x0 − h)] − f (ξ1 ),
2h 6
where ξ1 lies between (x0 – h) and (x0 + h).
Given in Table below are values for f (x) = xex.
x f (x)

1.8 10.889365

1.9 12.703199

2.0 14.778112

2.1 17.148957

2.2 19.855030

Since
f ′( x) = ( x + 1)e x , f ′(2.0) = 22.167168.
Approximating f ′(2.0)
using the various three-and five-point formulas produces the following results.
Three point formulas:
1 h 2 (3)
f ′( x0 ) = [ −3 f ( x0 ) + 4 f ( x0 + h) − f ( x0 + 2h) ] + f (ξ 0 ),
2h 3
1 h 2 (3)
f ′( x0 ) = [ f ( x0 + h) − f ( x0 − h) ] − f (ξ1 ),
2h 6
Using three point formulas we get
1
h = 0.1: [ −3 f (2.0) + 4 f (2.1) − f (2.2)]
0.2
= 22.032310,
1
h = −0.1: [ −3 f (2.0) + 4 f (1.9) − f (1.8)]
−0.2
= 22.0054525,
1
h = 0.1: [ f (2.1) − f (1.9)]
0.2
= 22.228790,
1
h = 0.2 : [ f (2.2) − f (1.8)]
0.4
= 22.414163.
Five point formula
Using the five point formula with h = 0.1 (the only formula applicable):
1
f ′( x0 ) = [ f ( x0 − 2h) − 8 f ( x0 − h) + 8 f ( x0 + h) − f ( x0 + 2h)]
12h
1
= [ f (1.8) − 8 f (1.9) + 8 f (2.1) − f (2.2)]
0.2
= 22.166999.
The errors in the formulas are approximately
1.35 × 10−1 ,1.13 × 10−1 , − 6.16 × 10−2 , −2.47 × 10−1 ,

−4
and 1.69 × 10 ,
respectively. Clearly, the five-point formula gives the superior result.
Consider approximating for f (x) = sin x, using the values in table [ the true value is cos (0.900) =
0.62161.]

x sin x x sin x

0.800 0.71736 0.901 0.78395

0.850 0.75128 0.902 0.78457

0.880 0.77074 0.905 0.78643

0.890 0.77707 0.910 0.78950

0.895 0.78021 0.920 0.79560

0.898 0.78208 0.950 0.81342

0.899 0.78270 1.000 0.84147

Using the formula


f (0.900 + h) − f (0.900 − h)
f ′(0.900) ≈
2h
with different values of h gives the approximations in table given below:

h Approximation to Error
f ′(0.900)

0.001 0.62500 0.00339

0.002 0.62250 0.00089

0.005 0.62200 0.00039

0.010 0.62150 -0.00011

0.020 0.62150 -0.00011

0.050 0.62140 -0.00021

0.100 0.62055 -0.00106


Examples of
Numerical Integration
EXAMPLE
The Trapezoidal rule for a function f on the interval [0, 2] is
2 h
∫0
f ( x)dx = [ f ( x0 ) + f ( x1 )]
2
2
∫0
f ( x)dx ≈ f (0) + f (2),
while Simpson’s rule for f on [0, 2] is
2 h
∫0
f ( x)dx = [ f ( x0 ) + 4 f ( x1 ) + f ( x2 )].
3
That is

2 1
∫0
f ( x)dx ≈ [ f (0) + 4 f (1) + f (2)].
3
f (x) x2 x4 1/(x + 1) sin x ex
1 + x2

Exact value 2.667 6.400 1.099 2.958 1.416 6.389

Trapezoidal 4.000 16.000 1.333 3.326 0.909 8.389

Simpson’s 2.667 6.667 1.111 2.964 1.425 6.421

Use close and open formulas listed below to approximate


π /4
∫0
sin xdx = 1 − 2 2

Some of the common closed Newton-Cotes formulas with their error terms are as follows:
n = 1: Trapezoidal rule
x1 h h3
∫x0 f ( x ) dx =
2
[ f ( x0 ) + f ( x1 )] −
12
f ′′(ξ ),
Where x0 < ξ < x1.
n = 2: Simpson’s rule
x2 h h5 (4)
∫ x0
f ( x)dx = [ f ( x0 ) + 4 f ( x1 ) + f ( x2 )] −
2 90
f (ξ ), x0 < ξ < x2 .

n = 3: Simpson’s rule
x3 3h 3h5 (4)
∫ x0
f ( x) dx = [ f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x3 )] −
8 80
f (ξ ), x0 < ξ < x3 .
n = 4:
x1 2h 8h 7 (6)
∫ x2
f ( x)dx = [7 f ( x0 ) + 32 f ( x1 ) + 12 f ( x2 ) + 32 f ( x3 ) + 7 f ( x4 )] −
45 945
f (ξ

Where x0 < ξ < x4 .

n = 0: Midpoint rule

x1 h3
∫x2
f ( x)dx = 2hf ( x0 ) +
3
f ′′(ξ ), where x−1 < ξ < x1.

n 1 2 3 4

Closed 0.27768018 0.29293264 0.29291070 0.29289318


formulas

Error 0.01521303 0.00003942 0.00001748 0.00000004

Open formulas 0.29798754 0.29285866 0.29286923

Error 0.00509432 0.00003456 0.00002399

Composite Numerical Integration


EXAMPLE 1
π
Consider approximating ∫ 0
sin xdx with an absolute error less than 0.00002, using the
Composite Simpson’s rule. The Composite Simpson’s rule gives
π h  ( n / 2) −1 n/2
 π h4
∫ sin xdx =  2 ∑ sin x2 j + 4∑ sin x2 j −1  − sin µ .
0 3  j =1 j =1  180
Since the absolute error is required to be less than 0.00002, the inequality
π h4 π h4 π5
sin µ ≤ = < 0.00002
180 180 180n 4
is used to determine n and h. Computing these calculations gives n greater than or equal to 18. If
n = 20, then the formula becomes
π π  9
 jπ  10
 (2 j − 1)π 
∫ sin xdx ≈  ∑ sin 
2  ∑ sin 
+ 4   = 2.000006.
0 60  j =1  10  j =1  20 
To be assured of this degree of accuracy using
the Composite Trapezoidal rule requires that
π h2 π h2 π3
sin µ ≤ = < 0.00002
12 12 12n 2
or that n ≥ 360. Since this is many more
calculations than are needed for the
Composite Simpson’s rule, it is clear
that it would be undesirable to use the Composite Trapezoidal rule on this problem. For
comparison purposes, the Composite Trapezoidal rule with n = 20 and
gives
π π 
19
 jπ  
∫0 sin xdx ≈ ∑ sin 
2  + sin 0 + sin π 
40  j =1  20  
π  19  jπ  
=  2∑ sin    = 1.9958860.
40  j =1  20  
The exact answer is 2; so Simpson’s rule with n = 20 gave an answer well within the required
error bound, whereas the Trapezoidal rule with n = 20 clearly did not.
An Example of Industrial applications: A company advertises that every roll of toilet paper
has at least 250 sheets. The probability that there are 250 or more sheets in the toilet paper is
given by

P ( y ≥ 250) = ∫ 0.3515
2
e −0.3881( y − 252.2) dy
250
Approximating the above integral as
270
P ( y ≥ 250) = ∫
2
0.3515 e −0.3881( y − 252.2) dy
250
a)use single segment Trapezoidal rule
to find the probability that there are 250
or more sheets.
b)Find the true error, Et for part (a).
C)Find the absolute relative true
error for part (a).
 f (a ) + f (b) 
I ≈ (b − a)   where
 2
a = 250 b = 270
2 2
f ( y ) = 0.3515e −0.3881( y − 252.2) f (250) = 0.3515e −0.3881(250− 252.2)
= 0.053721
2
f (270) = 0.3515e −0.3881(270− 252.2) = 1.3888 × 10−54
 0.053721 + 1.3888 × 10−54 
I = (270 − 250)  
 2 
= 0.53721
b) The exact value of the above integral cannot be found. We assume the value obtained by
adaptive numerical integration using Maple as the exact value for calculating the true error and
relative true error.
270
P ( y ≥ 250) = ∫
2
0.3515 e −0.3881( y − 252.2) dy
250
= 0.97377

so the true error is = 0.97377 − 0.53721 = 0.43656


The absolute relative true error,
∈t , would then be
True Error
∈t = × 100
True Value
0.97377 − 0.53721
= × 100
0.97377
= 44.832%
Improper Integrals
EXAMPLE
To approximate the values of the improper integral
1 ex
∫0
x
dx,

we will use the Composite Simpson’s rule with h = 0.25. Since the fourth Taylor polynomial for ex
about x = 0 is
x 2 x3 x 4
P4 ( x) = 1 + x + + + .
2 6 24
We have
1
P ( x)
1  12 2 32 1 52 1 7 2 1 9 2
∫0 4 x dx = Mlim+ 
→0 
2x + x + x + x +
3 5 21 180
x 
M
2 1 1 1
= 2+ + + + ≈ 2.9235450.
3 5 21 108
Table below lists the approximate values of
 e x − P4 ( x)
 when 0 < x ≤1
G ( x) =  4
0, when x=0

x G(x)

0.00 0

0.25 0.0000170

0.50 0.0004013

0.75 0.0026026

1.00 0.0099485

Applying the Composite Simpson’s rule to G using these data gives


1
∫ G( x)dx ≈
0

0.25
[0 + 4(0.0000170) + 2(0.0004013)
3
+4(0.0026026) + 0.0099485]
= 0.0017691
Hence
1 ex
∫ 0
x
dx ≈ 2.9235450 + 0.0017691 = 2.9253141.
This result is accurate within the accuracy of the Composite Simpson’s rule approximation for the
function G. Since G
(4)
( x) < 1
on [0, 1], the error is bounded by
1− 0
(0.25) 4 (1) = 0.0000217.
180
EXAMPLE
To approximate the value of the improper integral

∞ 1
I = ∫ x −3 2 sin dx.
1 x
1
we make the change of variable t = x-1 to obtain I = ∫t
12
sin t dt.
0

The fourth Taylor polynomial, P4(t), for sin t about 0 is


1
P4 (t ) = t − t 3 ,
6

sin t − t + 16 t 3
1 1 1
So we have I = ∫ 12
dt + ∫ t1 2 − t 5 2 dt
0 t 0 6
1
1 sin t − t + t
3
1
2 1 
=∫ 1 2
6
dt +  t 3 2 − t 7 2 
0 t 3 21  0
1sin t − t + 16 t 3
=∫ dt + 0.61904761.
0 t1 2

Applying the Composite Simpson’s rule with n = 8 to the remaining integral gives
I = 0.0014890097 + 0.61904761 = 0.62053661,

−8
which is accurate to within 4.0 × 10 .

You might also like