This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
04/20/23http://
numericalmethods.eng.usf.edu 1
Differentiation-Continuous Functions
Computer Engineering Majors
Authors: Autar Kaw, Sri Harsha Garapati
http://numericalmethods.eng.usf.eduTransforming Numerical Methods Education for STEM
Figure 1 Graphical Representation of forward difference approximation of first derivative.
Graphical Representation Of Forward Difference
Approximation
http://numericalmethods.eng.usf.edu
5
Example 1There is strong evidence that the first level of processing what we see is done in the retina. It involves detecting something called edges or positions of transitions from dark to bright or bright to dark points in images. These points usually coincide with boundaries of objects. To model the edges, derivatives of functions such as
0,1
0,1)(
xe
xexf
ax
ax
need to be found.
a)Use forward divided difference approximation of the first derivative of to calculate its derivative at for . Use a step size of . Also calculate the absolute relative true error.
b)Repeat the procedure from part (a) with the same data except choose . Does the estimate of the derivative increase or decrease? Also calculate the relative true error.
05.0x xf 24.0a1.0x
12.0a
http://numericalmethods.eng.usf.edu
6
Example 1 Cont.
x
xfxfxf iii
1'
1.0ix
15.005.01.0
1
xxxi
023714.01)1.0( )1.024.0(
ef
035360.01)15.0( )15.024.0(
ef
Solution:
24.0a
05.0x
http://numericalmethods.eng.usf.edu
7
Example 1 Cont.
05.0
1.015.01.0' ff
f
05.0
023714.00.035360
0.23291
The exact value of 1.0'f can be calculated by differentiating
0,1 xexf ax
as
xfdx
dxf '
http://numericalmethods.eng.usf.edu
8
Knowing that
axax aeedx
d
x
ax
ax
eae
edx
dxf
24.0
'
24.0
)1(
23431.0
)(24.0(1.0 )1.024.0('
ef
Example 1 Cont.
we find
http://numericalmethods.eng.usf.edu
9
The absolute relative true error is
%59761.0
1000.23431
0.232910.23431
100Value True
Value eApproximat-Value True
t
Example 1 Cont.
http://numericalmethods.eng.usf.edu
10
Example 1 Cont.
b)
011928.0
11.0 )1.012.0(
ef
017839.01)15.0( )15.012.0(
ef
12.0a
05.0
1.015.01.0' ff
f
05.0
011928.00.017838
0.11821
http://numericalmethods.eng.usf.edu
11
)1(' axedx
dxf
axae
)1.012.0(' )(12.0(1.0 ef
0.11856
Example 1 Cont.
xe 12.012.0
http://numericalmethods.eng.usf.edu
12
100Value True
Value eApproximat-Value Truet
The absolute relative true error is
1000.11857
0.118210.11857
0.29940%
The estimate of the derivative decreased.
Example 1 Cont.
http://numericalmethods.eng.usf.edu13
Backward Difference Approximation of the
First Derivative
We know
x
xfxxf
xxf
Δ
Δ
0Δ
lim
For a finite 'Δ' x ,
x
xfxxfxf
If 'Δ' x is chosen as a negative number,
x
xfxxfxf
x
xxfxf
Δ
Δ
http://numericalmethods.eng.usf.edu14
Backward Difference Approximation of the First Derivative Cont.
This is a backward difference approximation as you are taking a point backward from x. To find the value of xf at ixx , we may choose
anotherpoint 'Δ' x behind as 1 ixx . This gives
x
xfxfxf iii
1
1
1
ii
ii
xx
xfxf
where
1Δ ii xxx
http://numericalmethods.eng.usf.edu15
xx-Δx
x
f(x)
Figure 2 Graphical Representation of backward difference approximation of first derivative
Backward Difference Approximation of the First Derivative Cont.
http://numericalmethods.eng.usf.edu
16
Example 2There is strong evidence that the first level of processing what we see is done in the retina. It involves detecting something called edges or positions of transitions from dark to bright or bright to dark points in images. These points usually coincide with boundaries of objects. To model the edges, derivatives of functions such as
0,1
0,1)(
xe
xexf
ax
ax
need to be found.
a)Use backward divided difference approximation of the first derivative of to calculate its derivative at for . Use a step size of . Also calculate the absolute relative true error.
b)Repeat the procedure from part (a) with the same data except choose . Does the estimate of the derivative increase or decrease? Also calculate the relative true error.
05.0x xf 24.0a1.0x
12.0a
http://numericalmethods.eng.usf.edu
17
Example 2 Cont.Solution
a) x
xfxfxf iii
1
1.0ix05.0x
05.005.01.0
1
xxx ii
24.0a
http://numericalmethods.eng.usf.edu
18
)1.024.0(11.0 ef
0.023714
)05.024.0(1)05.0( ef
0.011928
05.0
05.01.01.0' ff
f
05.0
011928.0023714.0
0.23572
Example 2 Cont.
http://numericalmethods.eng.usf.edu
19
The absolute relative true error is
100Value True
Value eApproximat-Value Truet
1000.23431
0.235720.23431
%60241.0
Example 2 Cont.
http://numericalmethods.eng.usf.edu
20
b)
11893.005.0
0059820.0011928.005.0
05.01.01.0'
fff
)1.012.0(11.0 ef
0.011928)05.012.0(1)05.0( ef
0.0059820
Example 2 Cont.
12.0a
http://numericalmethods.eng.usf.edu
21
The absolute relative true error is
100Value True
Value eApproximat-Value Truet
1000.11857
0.118930.11857
%0.30060The estimate of the derivative decreased.
Example 2 Cont.
http://numericalmethods.eng.usf.edu22
Derive the forward difference approximation from Taylor series
Taylor’s theorem says that if you know the value of a function '' f at a point
ixand all its derivatives at that point, provided the derivatives are
continuous between ix and 1ix , then
2
111 !2 iii
iiiii xxxf
xxxfxfxf
Substituting for convenience ii xxx 1Δ
2
1 Δ!2
Δ xxf
xxfxfxf iiii
xxf
x
xfxfxf iiii !2
1
xx
xfxfxf iii
01
http://numericalmethods.eng.usf.edu23
Derive the forward difference approximation from Taylor series Cont.
The x0term shows that the error in the approximation is of the order
of xΔ Can you now derive from Taylor series the formula for backward
divided difference approximation of the first derivative?
As shown above, both forward and backward divided difference
approximation of the first derivative are accurate on the order of x0
Can we get better approximations? Yes, another method to approximate
the first derivative is called the Central difference approximation of
the first derivative.
http://numericalmethods.eng.usf.edu24
Derive the forward difference approximation from Taylor series Cont.
From Taylor series
32
1 Δ!3
Δ!2
Δ xxf
xxf
xxfxfxf iiiii
32
1 Δ!3
Δ!2
Δ xxf
xxf
xxfxfxf iiiii
Subtracting equation (2) from equation (1)
3
11 Δ!3
2Δ2 x
xfxxfxfxf i
iii
211
!32x
xf
x
xfxfxf iiii
211 02
xx
xfxfxf iii
http://numericalmethods.eng.usf.edu25
Central Divided Difference
Hence showing that we have obtained a more accurate formula as the
error is of the order of . 2Δ0 x
x
f(x)
x-Δx x x+Δx
Figure 3 Graphical Representation of central difference approximation of first derivative
http://numericalmethods.eng.usf.e
du
26
Example 3There is strong evidence that the first level of processing what we see is done in the retina. It involves detecting something called edges or positions of transitions from dark to bright or bright to dark points in images. These points usually coincide with boundaries of objects. To model the edges, derivatives of functions such as
0,1
0,1)(
xe
xexf
ax
ax
need to be found.
a)Use central divided difference approximation of the first derivative of to calculate its derivative at for . Use a step size of . Also calculate the absolute relative true error.
b)Repeat the procedure from part (a) with the same data except choose . Does the estimate of the derivative increase or decrease? Also calculate the relative true error.
05.0x xf 24.0a1.0x
12.0a
http://numericalmethods.eng.usf.e
du
27
Example 3 cont.
Solution
a) x
tftfxf xxi
211'
1.0ix
xxx ii 1
05.01.0 15.0
xxx ii 1
05.01.0
05.0
24.0a
05.0x
http://numericalmethods.eng.usf.e
du
28
Example 3 cont.
05.02
05.015.01.0' ff
f
1.0
05.015.0 ff
)15.024.0(115.0 ef
0.035360
)05.024.0(105.0 ef
0.011928
http://numericalmethods.eng.usf.e
du
29
Example 3 cont.
1.0
05.015.01.0' ff
f
1.0
0.0119280.035360
0.23431
The absolute relative true error is
100Value True
Value eApproximat-Value Truet
1000.23431
0.234310.23431
%0.0024000
http://numericalmethods.eng.usf.e
du
30
Example 3 cont.
1.0
05.015.01.0' ff
f
)15.012.0(115.0 ef
0.017839
)05.012.0(105.0 ef
0.0059820
b) 12.0a
1.0
0.00598200.017839
0.11857
http://numericalmethods.eng.usf.e
du
31
Example 3 cont.
The absolute relative true error is
100Value True
Value eApproximat-Value Truext
1000.11857
0.118570.11857x
%106.0000 4
The results from the three difference approximations are given in Table 1.
http://numericalmethods.eng.usf.e
du
32
Comparision
Type of DifferenceApproximation
ForwardBackwardCentral
0.23291 0.23572 0.23431
0.597610.602410.0024000
0.118210.118930.11857
0.29940 0.30060 6.0000
24.0),1.0(' af 24.0%, at 12.0),1.0(' af 12.0%, at
Table 1 Summary of using different divided difference approximations
410
1.0f
http://numericalmethods.eng.usf.edu33
Finding the value of the derivative within a prespecified tolerance
In real life, one would not know the exact value of the derivative – so how
would one know how accurately they have found the value of the derivative.
A simple way would be to start with a step size and keep on halving the step
size and keep on halving the step size until the absolute relative approximate
error is within a pre-specified tolerance.
Take the example of finding for tv
tt
t 8.921001014
1014ln2000
4
4
at using the backward divided difference scheme. 16t
210.50.250.125
28.91529.28929.48029.57729.625
1.27920.647870.326040.16355
http://numericalmethods.eng.usf.edu34
Finding the value of the derivative within a prespecified tolerance Cont.
Given in Table 2 are the values obtained using the backward difference approximation method and the corresponding absolute relative approximate errors.
t tv %a
Table 2 First derivative approximations and relative errors for different Δt values of backward difference scheme
http://numericalmethods.eng.usf.edu35
Finding the value of the derivative within a prespecified tolerance Cont.
From the above table, one can see that the absolute relative
approximate error decreases as the step size is reduced. At 125.0t
the absolute relative approximate error is 0.16355%, meaning that
at least 2 significant digits are correct in the answer.
http://numericalmethods.eng.usf.edu36
Finite Difference Approximation of Higher Derivatives
One can use Taylor series to approximate a higher order derivative.
For example, to approximate xf , the Taylor series for
32
2 Δ2!3
Δ2!2
Δ2 xxf
xxf
xxfxfxf iiiii
where
xxx ii Δ22
321 !3!2
xxf
xxf
xxfxfxf iiiii
where
xxx ii Δ1
http://numericalmethods.eng.usf.edu37
Finite Difference Approximation of Higher Derivatives Cont.
Subtracting 2 times equation (4) from equation (3) gives
3212 ΔΔ2 xxfxxfxfxfxf iiiii
xxfx
xfxfxfxf i
iiii Δ
Δ
22
12
xx
xfxfxfxf iiii Δ0
Δ
22
12
(5)
http://numericalmethods.eng.usf.edu38
Example 4
The velocity of a rocket is given by
300,8.921001014
1014ln2000
4
4
tt
tt
Use forward difference approximation of the second derivative of to calculate the jerk at . Use a step
size of .
tνst 16 st 2Δ
http://numericalmethods.eng.usf.edu39
Example 4 Cont.
Solution
2
12 2
t
ttttj iiii
16it
18216
1
ttt ii
202216
22
ttt ii
22
161822016
j
2t
http://numericalmethods.eng.usf.edu40
Example 4 Cont.
208.92021001014
1014ln200020
4
4
m/s35.517
188.91821001014
1014ln200018
4
4
sm /02.453
168.91621001014
1014ln200016
4
4
m/s07.392
http://numericalmethods.eng.usf.edu41
Example 4 Cont.
4
07.39202.453235.51716
j
3m/s84515.0
The exact value of 16j can be calculated by differentiating
tt
t 8.921001014
1014ln2000
4
4
twice as
tνdt
dta and ta
dt
dtj
http://numericalmethods.eng.usf.edu42
Example 4 Cont.
Knowing that
t
tdt
d 1ln and
2
11
ttdt
d
8.921001014
1014
1014
210010142000
4
4
4
4
tdt
dtta
t
t
3200
4.294040
8.9210021001014
10141
1014
210010142000
24
4
4
4
t
t
http://numericalmethods.eng.usf.edu43
Example 4 Cont.
2)3200(
18000
t
tadt
dtj
3
2
m/s77909.0 )]16(3200[
1800016
j
The absolute relative true error is
10077909.0
84515.077909.0
t
% 4797.8
Similarly it can be shown that
http://numericalmethods.eng.usf.edu44
Higher order accuracy of higher order derivatives
The formula given by equation (5) is a forward difference approximation of
the second derivative and has the error of the order of xΔ . Can we get
a formula that has a better accuracy? We can get the central difference
approximation of the second derivative.
The Taylor series for
4321 !4!3!2
xxf
xxf
xxf
xxfxfxf iiiiii
where
xxx ii Δ1
(6)
http://numericalmethods.eng.usf.edu45
Higher order accuracy of higher order derivatives Cont.
4321 !4!3!2
xxf
xxf
xxf
xxfxfxf iiiiii
where
xxx ii Δ1
(7)
Adding equations (6) and (7), gives
12
ΔΔ2
42
11
xxfxxfxfxfxf iiiii
12
Δ
Δ
2 2
211 xxf
x
xfxfxfxf iiiii
2
211 Δ0
Δ
2x
x
xfxfxfxf iiii
http://numericalmethods.eng.usf.edu46
Example 5
The velocity of a rocket is given by
300,8.921001014
1014ln2000
4
4
tt
tt
Use central difference approximation of second derivative of to calculate the jerk at . Use a step size of .
tνst 16 st 2Δ
http://numericalmethods.eng.usf.edu47
Example 5 Cont.
Solution
2
11 2
t
tttta iiii
16it
18216
1
ttt ii
14216
1
ttt ii
22
141621816
j
2t
http://numericalmethods.eng.usf.edu48
Example 5 Cont.
188.91821001014
1014ln200018
4
4
m/s02.453
168.91621001014
1014ln200016
4
4
m/s07.392
148.91421001014
1014ln200014
4
4
m/s24.334
http://numericalmethods.eng.usf.edu49
Example 5 Cont.
22
141621816
j
4
24.33407.392202.453
The absolute relative true error is
10077908.0
78.077908.0
t
3m/s77969.0
%077992.0
Additional Resources
For all resources on this topic such as digital audiovisual lectures, primers, textbook chapters, multiple-choice tests, worksheets in MATLAB, MATHEMATICA, MathCad and MAPLE, blogs, related physical problems, please visit