B9 - numerical differentiation
finite difference numerical integrator
- for a given function, its derivative can be written as:
-
this is called the finite difference approximation
-
if
- this is a numerical integrator
different schemes and errors

image: Tristanevanslee
- the taylor approximations:
- the forward difference scheme:
-
the leading order error term is:
, and is in the order, -
the backward difference scheme:
-
the error has the exact same form, but is negative
-
the central difference scheme:
-
this reduces the error to the order
, ie. if is reduced by a factor of , the error is reduced by a factor of , and not just as it is for the previous schemes -
note: the error can be further reduced by using taylor expansions for
, and so on
x1 - code for difference schemes comparison

second derivative
- the finite difference approximation of the second derivative is:
- using the taylor expansions of
-
this is the central difference second derivative approximation with error in the order,
-
note: considering
, for
taking the step to zero
- theoretically, taking the step,
, to zero should make the error arbitrarily small, but this is not possible due to numerical truncation error - computers can only store a finite precision of bits and and decimals smaller than this get truncated by rounding it off
- for double precision, the round off error,
- eg:
will be stored as
- therefore, as
, the round off error
- the taylor series error:
, ie. as and as as and as - to minimise the error:
- assuming a constant