of 30
7/23/2019 C1_L3
1/30
Numerical DifferentiationChapter 1 Lecture 3
7/23/2019 C1_L3
2/30
At the end of this session students should be able toestimate the derivative using forward, backward andcentered finite divided difference.
7/23/2019 C1_L3
3/30
Numerical Differentiation
he a!lor "eries e#pansion $%orward a!lor "eries e#pansion& of thefunction f at is given b!
where is a remainder term.
runcate the series after the first derivative term'
his e(uation can be solved for
1+ix
n
ni
n
iiii Rh
n
xfh
xfhxfxfxf +++++=+
!
)(...
!2
)(")(')()(
)(2
1
1)1(
)!1(
)( ++
+= n
n
n hn
fR
11
)(')()( Rhxfxfxfiii
++=+
h
R
h
xfxfxf iii
11 )()()('
= +
7/23/2019 C1_L3
4/30
Numerical Differentiation
he first part of the e(uation is the relationship used to appro#imate
the derivative and the second part is used to estimate the truncationerror associated with this appro#imation of the derivative.
%irst)order runcation errorappro#imation
h
R
h
xfxfxf iii
11 )()()('
= +
7/23/2019 C1_L3
5/30
Numerical Differentiation
)(xf
)(
)( 1
i
i
xf
xf+
1+ii xx
)(' ixf
h
h
R
h
xfxfxf iii
11 )()()('
= +
7/23/2019 C1_L3
6/30
Numerical Differentiation
*ere
hus, the estimate of the derivative has a truncation error of orderh.
+f we halve the step sie, i.e., , we would e#pect to halvethe error of the derivative, i.e.,
)(2
)("
2
)("
1
2
1
hOhf
h
R
hf
R
==
=
hh21
hf
h
R
4
)("1
7/23/2019 C1_L3
7/30
%orward Difference Appro#. of the %irst Derivative
he e(uation
is called a -%orward finite difference because it utiliesdata at to estimate the derivative, where
)()()(
)()()('
1
11
hOh
xfxfh
R
h
xfxfxf
ii
iii
=
=
+
+
1and +ii xx
........!4
)(
!3
)(
!2
)(")( 3
)4(2
)3(
+++= hxf
hxf
hxf
hO iii
7/23/2019 C1_L3
8/30
/ackward Difference Appro#. of the %irst Derivative
Let so that
)(xf
)(
)(
1i
i
xf
xf
ii xx 1
)(' ixf
h
1= ii xxh
.......
!3
)(
!2
)(")(')(
)()(
3)3(
2
1
++=
=
hxf
hxf
hxfxf
hxfxf
iiii
ii
7/23/2019 C1_L3
9/30
/ackward Difference Appro#. of the %irst Derivative
runcating this e(uation after the first derivative
and rearranging !ields
where
his e(uation is called a -/ackward %inite Difference because itutilies data at to estimate the derivative.
11 )(')()( Rhxfxfxf iii +=
)()()(
)(' 1 hOh
xfxfxf iii +
=
.......!3
)(
!2
)("
)(
2)3(
+=
h
xf
h
xf
hO
ii
ii xx and1
7/23/2019 C1_L3
10/30
Centered Difference Appro#. of the %irst Derivative
A third wa! to appro#. the first derivative is to subtract
the backward from the forward a!lor series e#pansionas follows'
......!3
)(
!2
)(")(')()(
:Forward
3)3(
2
1 ++++=+ hxf
hxf
hxfxfxf iiiii
.......!3
)(
!2
)(")(')()(
:Backward
3)3(
2
1 ++= hxf
hxf
hxfxfxf iiiii
7/23/2019 C1_L3
11/30
Centered Difference Appro#. of the %irst Derivative
%orward 0 /ackward'
)(2
)()(
.......!3
)(
2
)()()('
.......!3
)()('
2
)()(
......!3
)()('2
......!3
)(
)('2)()(
211
2)3(
11
2)3(
11
2)3(
3)3(
11
hOh
xfxf
hxf
h
xfxfxf
hxf
xfh
xfxf
hxf
xfh
h
xf
hxfxfxf
ii
iiii
ii
ii
ii
i
iii
=
+
=
++=
++=
++=
+
+
+
+
7/23/2019 C1_L3
12/30
Centered Difference Appro#. of the%irst Derivative
where
his e(uation is shown in the diagram below'
......!5
)(
!3
)()( 4
)5(2
)3(2 ++= h
xfh
xfhO ii
)(xf
)(
)(
)(
1
1
+
i
i
i
xf
xf
xf
11 + iii xxx
)(' ixf
hh
7/23/2019 C1_L3
13/30
Centered Difference Appro#. of the %irst Derivative
his e(uation is called a -Centered %inite Differencerepresentation of the first derivative. Note that the
truncation error is of the order of whereas theforward and backward appro#imation are of the order ofh.Conse(uentl!, the centered difference is a moreaccurate representation of the derivative. /ecause itwould appro#imatel! halve the truncation error, whereasfor centered difference, the error would be (uartered.
2
h
7/23/2019 C1_L3
14/30
#ample 1
2se forward and backward difference appro#. and
centered difference appro#. to estimate the firstderivative of the function
atx4.5 using a step sie h4.5. 6epeat thecomputation using h4.75. Compute !our results with
the true value of the derivative.
2.125.05.015.01.0)( 234 += xxxxxf
7/23/2019 C1_L3
15/30
"olution
he derivative of f(x)is
he true value is
%or the step sie h4.5, we have
25.00.145.04.0)(' 23 = xxxxf
9125.0)5.0(' =f
0.1
5.0
0
1
1
=
=
=
+
i
i
i
x
x
x
2.0)0.1()(
925.0)5.0()(
2.1)0()(
1
1
==
==
==
+
fxf
fxf
fxf
i
i
i
2.125.05.015.01.0)( 234 += xxxxxf
7/23/2019 C1_L3
16/30
"olution
he backward difference appro#. is
%7.39%1009125.0
55.09125.0
55.05.0
2.1925.0)5.0('
)()()(' 1
=
+=
=
t
iii
f
h
xfxfxf
7/23/2019 C1_L3
17/30
"olution
he forward difference appro#. is
%9.58%1009125.0
45.19125.0
45.15.0
925.02.0)5.0('
)()()(' 1
=
+=
=
+
t
iii
f
h
xfxfxf
7/23/2019 C1_L3
18/30
"olution
he centered difference appro#. is
%6.9%1009125.0
0.19125.0
0.1)5.0(22.12.0)5.0('
2
)()()(' 11
=
+=
=
+
t
iii
f
h
xfxfxf
7/23/2019 C1_L3
19/30
"olution
%or the step sie h4.75, we have
he backward difference appro#. is
75.0
5.025.0
1
1
=
=
=
+
i
i
i
x
xx
63632813.0)75.0()(
925.0)5.0()(10351563.1)25.0()(
1
1
==
==
==
+
fxf
fxffxf
i
i
i
%75.21%1009125.0
714.09125.0
714.025.0
10351563.1925.0)5.0('
)()()(' 1
=
+=
=
t
iii
f
hxfxfxf
7/23/2019 C1_L3
20/30
"olution
he forward difference appro#. is
%5.26%1009125.0
155.19125.0
155.125.0
925.063632813.0)5.0('
)()()(' 1
=
+=
=
+
t
iii
f
h
xfxfxf
7/23/2019 C1_L3
21/30
"olution
he centered difference appro#. is
%4.2%1009125.0
934.09125.0
934.0)5.0(2
10351563.163632813.0)5.0('
2
)()()(' 11
=
+=
=
+
t
iii
f
h
xfxfxf
7/23/2019 C1_L3
22/30
"olution
%or both step sies, the centered difference appro#. is more accuratethan forward and backward differences. Also as predicted b! the
a!lor series anal!sis, halving the step sie appro#imatel! halves theerror of backward and forward difference and (uarters the error ofthe centered difference.
h=0.5 h=0.25
/ackward
%orward
Centered
%7.39=t
%9.58=t
%6.9=t
%75.21=t
%5.26=t
%4.2=t
7/23/2019 C1_L3
23/30
%inite Difference Appro#imation of *igher Derivatives
a!lor series e#pansion can be used to derive numerical estimates ofhigher derivatives. o do this, we write a forward a!lor seriese#pansion for in terms of '
%rom the forward a!lor series e#pansion
)( 2+ixf)( ixf
)1(
....)2(!3
)()2(
!2
)(")2)((')()( 3
)3(2
2
++++=+ hxf
hxf
hxfxfxf iiiii
)2(
......!3
)(
!2
)(")(')()( 3
)3(2
1
++++=+
hxf
hxf
hxfxfxf iiiii
7/23/2019 C1_L3
24/30
%inite Difference Appro#imation of*igher Derivatives
(.$1& ) 7#(.$7& gives
which can be solved for
where
his relationship is called the -"econd forward finite difference.
......)()()(")(
)(2)(
4)4(
12
73)3(2
12
++++=
++
hxfhxfhxfxf
xfxf
iiii
ii
)()()(2)(
)("2
12 hOh
xfxfxfxf iiii
+= ++
......)()()( 2)4(
12
7)3( ++= hxfhxfhO ii
7/23/2019 C1_L3
25/30
%inite Difference Appro#imation of*igher Derivatives
"imilar manipulations can be emplo!ed to derive a
-"econd backward finite difference as
where
)()()(2)(
)("2
21 hOh
xfxfxfxf iiii +
+=
......)()()( 2)4(127)3( += hxfhxfhO ii
7/23/2019 C1_L3
26/30
%inite Difference Appro#imation of*igher Derivatives
he "econd centered finite difference is
where
Alternativel!, the "econd Centered finite difference canbe e#pressed as
h
h
xfxf
h
xfxf
xf
iiii
i
)()()()(
)("
11 +
)()()(2)()("2
11 hOh
xfxfxfxf iiii += +
......)()()( 4)6(36012)4(
121 ++= hxfhxfhO ii
7/23/2019 C1_L3
27/30
#ample 8
2se a centered difference appro#imation to estimate the
second derivative of the function
atx7 using step sies of h=4.75 and 4.175. Compare!our estimates with the true value of the secondderivative. +nterpret !our results on the basis of the
remainder term of the a!lor series e#pansion.
887625)( 23 += xxxxf
7/23/2019 C1_L3
28/30
"olution
he true value of the second derivative atx7 is
12150)("
71275)('
887625)(
2
23
=
+=
+=
xxf
xxxf
xxxxf
28812)2(150)2(" ==f
7/23/2019 C1_L3
29/30
"olution
h4.75
25.2
2
75.1
1
1
=
=
=
+
i
i
i
x
x
x
1406.182)25.2()(
102)2()(
85938.39)75.1()(
1
1
==
==
==
+
fxf
fxf
fxf
i
i
i
288)25.0(
)75.1()2(2)25.2()2("
)()(2)()("
2
2
11
=+=
+= +
ffff
h
xfxfxfxf iiii
7/23/2019 C1_L3
30/30
"olution
h4.175
/oth results are e#act because the errors are a function
of 9thand higher derivatives which are ero for a 3rdorder pol!nomial function.
125.2
2
875.1
1
1
=
=
=
+
i
i
i
x
x
x
6738.139)125.2()(
102)2()(
82617.68)875.1()(
1
1
==
==
==
+
fxf
fxf
fxf
i
i
i
288)125.0(
)875.1()2(2)125.2()2("
2 =
+=
ffff