Calculating the derivatives of functions is as fundamental as calculating integrals. Numerical approaches are illustrated below.
The figure below illustrates three points in a table listing a function on an equally spaced grid.
A low order approach follows by using the points and
,
the Forward formula.
The Backward formula follows the same
procedure but is based on the points
and
.
Both of these formulas for the derivative at
yield the same slope
in the
This is found in any calculus
textbook. However the numerical approach always
implies finite
, and therefore not so accurate results.
A more accurate way to compute the derivatives is illustrated in the
figure below. It uses the function values at points and
,
It is called the Symmetric form.
The program
<a href=../codes/Derivative.cpp> Derivative.cpp</a>
reads a tabulated function
from a pipe and calculates the derivative on the grid using the three
numerical forms, Forward, Backward and Symmetric. The exact derivative
of is also calculated as a reference. It is
obvious both graphically and by comparison with the exact answer
that the the symmetrical form is the most accurate.
Note that (some of) these formulas do not allow to calculate the derivatives at the first or last points on the grid. Can you analyze why ?
Note also that the calculation of derivatives is intrinsically not very accurate.
2015-01-05