Table of Contents
Taylor Series ...................................................................................................................................................... 1
Application.......................................................................................................................................................1
Approximating First Derivatives.......................................................................................................................... 1
Forward and Backward Difference.................................................................................................................. 1
Centered Difference........................................................................................................................................ 3
Approximating Second Derivatives..................................................................................................................... 4
Finite difference methods are used to approximate derivatives of functions, and is also known as Numerical
Differentiation. Taylor series play a fundamental role in these methods.
Taylor Series
Taylor Series. If a function f is infinitely differentiable, then for any specified expansion point
where h is any number, also written as
, we have
representing the change in
The partial sum formed by the first n + 1 terms of a Taylor series is a polynomial of degree n that is called
the nth Taylor polynomial of the function.
Taylor's Theorem. If a function f is n + 1 times differentiable, then for any specified expansion point
every real number h, there is a number c in the interval
The term
, for
such that
is precisely the error between the function and its Taylor approximation.
Application
Taylor series can also be used to check derivatives (analytic/numeric) of a given function. For example,
when we used the Netwon's method to find roots in Ch 1, we needed the first order derivatives of the
function. We can use Taylor series to double check if the computed derivatives are correct. More on this,
shortly.
Approximating First Derivatives
Forward and Backward Difference
For a finite h, we know that the first derivative of a function
is defined as
Hence,
Now suppose, we are given the function values
at some points
instead of knowing the function analytically. Then using the above definition, we have
1
two-point forward difference :
(substitute
two-point backward difference :
(substitute
)
)
Ques. How accurate are these approximaions?
Theorem. Let f be a twice differentiable function in an interval containing
. Then the error in approximating
with the forward difference approximation is bounded by
where Cis a constant independent of h, but depends on the
We have the same theorem for backward difference approximation.
Note. The above theorem can be use to check derivateives. If you have
at hand, then the difference on
the on the right hand side of the inequality should decrease at the same rate as h.
Example. Let us do try this for
at
.
=
h = (0.5).^[1:10];
2
fp = 1;
fp_fd =
( exp ( sin (0+h))- exp(sin (0)))./ h;
fp_bd =
( exp ( sin (0+h))- exp(sin (0)))./ h;
err_fd = abs(fp_fd-fp);
err_bd = abs(fp_bd-fp);
T = table(h', fp_fd', err_fd', [0, err_fd(1:end -1)./ err_fd(2:end)]', fp_bd',
err_bd', [0, err_bd(1:end -1)./ err_bd(2:end)]' ,'VariableNames', {'h', 'fwd
diff', 'fwd abs err', 'rel_err','bwd diff', 'bwd abs err', 'bwd rel err' });
disp(T)
h
__________
fwd diff
________
fwd abs err
___________
rel_err
_______
bwd diff
________
bwd abs err
___________
bwd rel err
___________
0.5
0.25
0.125
0.0625
0.03125
0.015625
0.0078125
0.0039062
0.0019531
0.00097656
1.2303
1.1228
1.0622
1.0312
1.0156
1.0078
1.0039
1.002
1.001
1.0005
0.23029
0.12279
0.06224
0.031218
0.015621
0.007812
0.0039062
0.0019531
0.00097656
0.00048828
0
1.8756
1.9728
1.9937
1.9985
1.9996
1.9999
2
2
2
1.2303
1.1228
1.0622
1.0312
1.0156
1.0078
1.0039
1.002
1.001
1.0005
0.23029
0.12279
0.06224
0.031218
0.015621
0.007812
0.0039062
0.0019531
0.00097656
0.00048828
0
1.8756
1.9728
1.9937
1.9985
1.9996
1.9999
2
2
2
Centered Difference
Using Taylor series, we can also approximate the derivatives just the points before and after.
two-point centered difference :
Theorem. Theorem. Let f be a thrice differentiable function in an interval containing
approximating
with the forward difference approximation is bounded by
where Cis a constant independent of h, but depends on the
3
. Then the error in
Example. Let us consider the same example as above
at
.
h = (0.5).^[1:10];
fp = cos(1);
fp_cd =
( sin (1+h)- sin(1-h))./ (2*h);
err_cd = (fp_cd-fp);
T = table(h', fp_cd', err_cd', [0, err_cd(1:end -1)./
err_cd(2:end)]','VariableNames', {'h', 'cnt diff', 'cnt abs err', 'rel_err'});
disp(T)
h
__________
cnt diff
________
cnt abs err
___________
rel_err
_______
0.5
0.25
0.125
0.0625
0.03125
0.015625
0.0078125
0.0039062
0.0019531
0.00097656
0.51807
0.53469
0.5389
0.53995
0.54021
0.54028
0.5403
0.5403
0.5403
0.5403
-0.022233
-0.0056106
-0.0014059
-0.00035169
-8.7936e-05
-2.1985e-05
-5.4962e-06
-1.3741e-06
-3.4351e-07
-8.5879e-08
0
3.9627
3.9906
3.9977
3.9994
3.9999
4
4
4
4
You can also approximate the derivatives using three point point formula, refere to Ch 4.1.3 of the book.
Good resource for coefficients of the terms. https://en.wikipedia.org/wiki/Finite_difference_coefficient
Approximating Second Derivatives
One can use the Taylor series to approximate a higher-order derivatives.
Rewriting the Taylor series by substituting
to h, we have
Adding this (1), we have
Doing some algebra to find
we get
Hence,
4
5