8/11/2019 06 Numerical Differentiation Integration
1/50
NUMERICAL DIFFERENTIATION
The derivative of f(x)at x0is:
h
xfhxfxf
Limit
h
)(00
00
An approximation to this is:
h
xfhxfxf
)(00
0
for small values of h.
Forward Difference
Formula
8/11/2019 06 Numerical Differentiation Integration
2/50
810
.andln)(Let xxxf
Find an approximate value for 81.f
0.1 0.5877867 0.6418539 0.5406720
0.01 0.5877867 0.5933268 0.5540100
0.001 0.5877867 0.5883421 0.5554000
).( 81f ).( hf 81h
fhf ).().( 8181 h
The exact value of 555081 .. f
8/11/2019 06 Numerical Differentiation Integration
3/50
Assume that a function goes through three points:
.,and,,, 221100 xfxxfxxfx
)()( xPxf
221100 xfxLxfxLxfxLxP
Lagrange Interpolating Polynomial
8/11/2019 06 Numerical Differentiation Integration
4/50
2
1202
10
12101
20
0
2010
21
))((
))((
))((
))((
))(())((
xfxxxx
xxxx
xfxxxx
xxxx
xfxxxxxxxxxP
221100 xfxLxfxLxfxLxP
8/11/2019 06 Numerical Differentiation Integration
5/50
)()( xPxf
2
1202
10
1
2101
20
0
2010
21
))((
2
))((
2
))((2
xf
xxxx
xxx
xfxxxx
xxx
xfxxxx
xxxxP
8/11/2019 06 Numerical Differentiation Integration
6/50
2
0000
000
1
0000
000
0
0000
0000
)()2()2(
)(2
)2()()(
)2(2
)2()(
)2()(2
xfhxhxxhx
hxxx
xfhxhxxhx
hxxx
xfhxxhxx
hxhxxxP
If the points are equally spaced, i.e.,
hxxhxx 20201
and
8/11/2019 06 Numerical Differentiation Integration
7/50
2212020
2
2
2
3xf
h
hxf
h
hxf
h
hxP
2100 432
1xfxfxf
hxP
hxfhxfxfhxf 2432
1
0000
Three-point formula:
8/11/2019 06 Numerical Differentiation Integration
8/50
hxxhxx
0201and
If the points are equally spaced with x0in the middle:
2
0000
000
1
0000
000
0
0000
0000
)()()(
)(2
)()()(
)(2
)(()(
)()(2
xf
hxhxxhx
hxxx
xfhxhxxhx
hxxx
xfhxxhxx
hxhxxxP
8/11/2019 06 Numerical Differentiation Integration
9/50
2212020
22
0xf
h
hxf
h
hxf
h
xP
hxfhxfh
xf 000
2
1
Another Three-point formula:
8/11/2019 06 Numerical Differentiation Integration
10/50
Alternate approach (Error estimate)
Take Taylor series expansion of f(x+h) about x:
xfh
xfh
xfhxfhxf3
32
2
!32
xf
h
xf
h
xfhxfhxf
33
22
!32
xf
hxf
hxf
h
xfhxf 32
2
!32 .............. (1)
8/11/2019 06 Numerical Differentiation Integration
11/50
hOxf
h
xfhxf
hOh
xfhxfxf
h
xfhxfxf
Forward DifferenceFormula
xfh
xf
h
hO
32
2
!32
8/11/2019 06 Numerical Differentiation Integration
12/50
xfh
xfh
xfhxfhxf3
32
2
!3
8
2
422
xfh
xfh
xfhxfhxf3
32
2
!3
8
2
422
xfhxfhxfh
xfhxf 322
!3
4
2
2
2
2
................. (2)
8/11/2019 06 Numerical Differentiation Integration
13/50
xf
hxf
hxf
h
xfhxf 32
2
!32.............. (1)
xf
hxf
hxf
h
xfhxf 32
2
!3
4
2
2
2
2
................. (2)
2 X Eqn. (1)Eqn. (2)
8/11/2019 06 Numerical Differentiation Integration
14/50
xfhxfhxf
h
xfhxf
h
xfhxf
4
3
3
2
!46
!32
2
22
2
43
32
!4
6
!3
22
342
hOxf
xfh
xfh
xf
h
xfhxfhxf
8/11/2019 06 Numerical Differentiation Integration
15/50
2
2
342hOxf
h
xfhxfhxf
22
342 hOh
xfhxfhxfxf
hxfhxfhxfxf
2342
Three-point Formula
xfh
xfh
hO4
33
22
!4
6
!3
2
8/11/2019 06 Numerical Differentiation Integration
16/50
Take Taylor series expansion of f(x+h) about x:
xfh
xf
h
xfhxfhxf3
32
2
!32
Take Taylor series expansion of f(x-h) about x:
xfh
xfh
xfhxfhxf3
32
2
!32
The Second Three-point Formula
Subtract one expression from another
xfh
xfh
xfhhxfhxf6
63
3
!6
2
!3
22
8/11/2019 06 Numerical Differentiation Integration
17/50
xfh
xfh
xfhhxfhxf6
63
3
!6
2
!3
22
xfh
xfh
xfh
hxfhxf 65
32
!6!32
xfhxfh
h
hxfhxfxf6532
!6!32
8/11/2019 06 Numerical Differentiation Integration
18/50
2
2hO
h
hxfhxfxf
xfh
xfh
hO6
53
22
!6!3
h
hxfhxfxf
2
Second Three-point Formula
8/11/2019 06 Numerical Differentiation Integration
19/50
h
xfhxfxf
Forward Difference
Formula
Summary of Errors
xfh
xfh
hO3
22
!32Error term
8/11/2019 06 Numerical Differentiation Integration
20/50
h
xfhxfhxfxf
2
342
First Three-point Formula
Summary of Errors continued
xfh
xfh
hO4
33
22
!4
6
!3
2Error term
8/11/2019 06 Numerical Differentiation Integration
21/50
h
hxfhxfxf
2
Second Three-point Formula
xfh
xfh
hO6
53
22
!6!3Error term
Summary of Errors continued
8/11/2019 06 Numerical Differentiation Integration
22/50
Example:
xxexf
Find the approximate value of 2f
1.9 12.703199
2.0 14.778112
2.1 17.148957
2.2 19.855030
x xf
with 10.h
8/11/2019 06 Numerical Differentiation Integration
23/50
Using the Forward Difference formula:
0 0 0
1f x f x h f x
h
12 2 1 2
0 11
17 148957 14 7781120 1
23 708450
f f . f
.
. ..
.
8/11/2019 06 Numerical Differentiation Integration
24/50
Using the 1st Three-point formula:
032310.22
855030.19
148957.174778112.1432.0
1
)2.2()1.2(4)2(31.02
12
ffff
hxfhxfxf
h
xf 243
2
10000
8/11/2019 06 Numerical Differentiation Integration
25/50
Using the 2nd Three-point formula:
228790.22
703199.12148957.172.0
1
)9.1()1.2(1.02
12
fff
The exact value of 22.167168:is2f
hxfhxf
h
xf 000
2
1
8/11/2019 06 Numerical Differentiation Integration
26/50
Comparison of the results with h= 0.1
Formula Error
Forward Difference 23.708450 1.541282
1st Three-point 22.032310 0.134858
2nd Three-point 22.228790 0.061622
2f
The exact value of 2f is22.167168
8/11/2019 06 Numerical Differentiation Integration
27/50
Second-order Derivative
xfh
xfh
xfhxfhxf3
32
2
!32
xfh
xfh
xfhxfhxf3
32
2
!32
Add these two equations.
xfh
xfh
xfhxfhxf4
42
2
!4
2
2
22
2 42 42 222 4!
h hf x h f x f x h f x f x
8/11/2019 06 Numerical Differentiation Integration
28/50
8/11/2019 06 Numerical Differentiation Integration
29/50
NUMERICAL INTEGRATION
b
a
dxxf )( area under the curve f(x)between
.to bxax
In many cases a mathematical expression for f(x)isunknown and in some cases even if f(x)is known its
complex form makes it difficult to perform the integration.
8/11/2019 06 Numerical Differentiation Integration
30/50
y
xx0= a x0= b
f(a)
f(b) f(x)
8/11/2019 06 Numerical Differentiation Integration
31/50
y
xx0= a x0= b
f(a)
f(b)
f(x)
8/11/2019 06 Numerical Differentiation Integration
32/50
Area of the trapezoid
The length of the two parallel sides of the trapezoid
are: f(a)and f(b)The height isb-a
)()(
)()()(
bfaf
h
bfafabdxxf
b
a
2
2
8/11/2019 06 Numerical Differentiation Integration
33/50
Simpsons Rule:
2
0
2
0
x
x
x
x
dxxPdxxf )()(
hxxhxx 20201
and
8/11/2019 06 Numerical Differentiation Integration
34/50
2 2
0 0
2
0
2
0
1 2
0
0 1 0 2
0 2
1
1 0 1 2
0 1
2
2 0 2 1
x x
x x
x
x
x
x
( x x )( x x )P x dx f x dx
( x x )( x x )( x x )( x x )
f x dx( x x )( x x )
( x x )( x x )f x dx
( x x )( x x )
8/11/2019 06 Numerical Differentiation Integration
35/50
)()(
)()(
2104
3
2
0
2
0
xfxfxfh
dxxPdxxf
x
x
x
x
8/11/2019 06 Numerical Differentiation Integration
36/50
y
xx0= a x0= b
f(a)
f(b)
f(x)
8/11/2019 06 Numerical Differentiation Integration
37/50
y
xx0= a x0= b
f(a)
f(b)
f(x)
8/11/2019 06 Numerical Differentiation Integration
38/50
y
xx0= a x0= b
f(a)
f(b)
f(x)
8/11/2019 06 Numerical Differentiation Integration
39/50
y
xx0= a x0= b
f(a)
f(b)
f(x)
8/11/2019 06 Numerical Differentiation Integration
40/50
Composite Numerical Integration
8/11/2019 06 Numerical Differentiation Integration
41/50
Riemann Sum
The area under the curve is subdivided into n
subintervals. Each subinterval is treated as a
rectangle. The area of all subintervals are added
to determine the area under the curve.
There are several variations of Riemann sum as
applied to composite integration.
L ft Ri S
8/11/2019 06 Numerical Differentiation Integration
42/50
In Left Riemann
sum, the left-
side sample of
the function is
used as the
height of the
individual
rectangle.
a b
Left Riemann Sumy
x
x
1
2
32
1i
x b a / n
x a
x a x
x a x
x a i x
1
nb
ia
i
f x dx f x x
Ri ht Ri S
8/11/2019 06 Numerical Differentiation Integration
43/50
In Right Riemann
sum, the right-side
sample of the
function is used as
the height of the
individual rectangle.
a b
Right Riemann Sumy
x
x
1
2
3
2
3
i
x b a / n
x a x
x a x
x a x
x a i x
1
nb
ia
i
f x dx f x x
Mid i t R l
8/11/2019 06 Numerical Differentiation Integration
44/50
In the Midpoint
Rule, the sample at
the middle of the
subinterval is usedas the height of the
individual
rectangle.
a b
Midpoint Ruley
x
x
1
2
3
2 1 1 2
2 2 1 2
2 3 1 2
2 1 2i
x b a / n
x a x /
x a x /
x a x /
x a i x /
1
nb
ia
if x dx f x x
8/11/2019 06 Numerical Differentiation Integration
45/50
Composite Trapezoidal Rule:
Divide the interval into nsubintervals and apply
Trapezoidal Rule in each subinterval.
)()()( bfxfafh
dxxfn
kk
b
a
1
1
2
2
where
nkkhaxnabh
k ,...,,,forand 210
8/11/2019 06 Numerical Differentiation Integration
46/50
by dividing the interval into 20 subintervals.
Find
sin0
(x)dx
20210
20
20
20
.....,,,,,
kk
khax
nabh
n
k
8/11/2019 06 Numerical Differentiation Integration
47/50
9958861
20
20
40
2
2
19
1
1
10
.
sin
sinsin
)()()sin(
k
n
k k
k
bfxfafh
dxx
C it Si R l
8/11/2019 06 Numerical Differentiation Integration
48/50
Composite Simpsons Rule:
Divide the interval into nsubintervals and apply
Simpsons Rule on each consecutive pair of subinterval.
Note that nmust be even.
)()(
)()(
/
)/(
bfxf
xfaf
h
dxxf
n
k
k
n
kk
b
a
2
1
12
12
12
4
23
where
8/11/2019 06 Numerical Differentiation Integration
49/50
nkkhaxn
abh
k,...,,,forand 210
where
by dividing the interval into 20 subintervals.
Find
sin0
(x)dx
2021020
2020
.....,,,,,
kkkhax
n
abhn
k
8/11/2019 06 Numerical Differentiation Integration
50/50
0000062
20
124
20
220
60
10
1
9
10
.
)sin()(
sin
sinsin
)sin(
k
k
k
kdxx
Top Related