f (x h) = f (x) hf'(x) + f''(x) + O(h^{ 3}) .
| (1) |

f (x + h) - f (x - h) = 2hf'(x) + O(h^{ 3}) ,
| (2) |

f'(x) = + O(h^{ 2}) .
| (3) |

h |
f'(x) - /2 single precision |
f'(x) - /2 double precision |

10^{- 1} |
- 1.2 x 10^{- 3} |
- 1.2 x 10^{- 3} |

10^{- 2} |
- 1.1 x 10^{- 5} |
- 1.2 x 10^{- 5} |

10^{- 3} |
1.3 x 10^{- 5} |
- 1.2 x 10^{- 7} |

10^{- 4} |
1.0 x 10^{- 4} |
- 1.2 x 10^{- 9} |

10^{- 5} |
- 7.9 x 10^{- 4} |
- 1.3 x 10^{- 11} |

10^{- 6} |
- 2.2 x 10^{- 2} |
- 4.5 x 10^{- 11} |

10^{- 7} |
1.9 x 10^{- 1} |
- 6.2 x 10^{- 10} |

Notice that the results, at first, get better as

f'(x) = + + O(h^{ 2})
| (4) |

Error + h^{ 2}
| (5) |

The key point to this exercise is that you do not get to turn off your brain when you start the computer.

With this in hand let's calculate the gradient of a scalar function
() . We first assume that it can be written in cartesian
coordinates as (*x*,*y*,*z*) . The gradient at the point
(*x*_{0},*y*_{0},*z*_{0}) is

(x_{0},y_{0},z_{0})
| = | ||

+ | |||

+ | |||

+ |
O(h^{ 2})
| (6) |

We can also use these sorts of formulas to calculate the divergence
and curl of vector fields, again assuming that both the field components
and the coordinates are cartesian,

(x_{0},y_{0},z_{0})
| = | ||

+ | |||

+ | |||

+ |
O(h^{ 2})
| (7) |

(x_{0},y_{0},z_{0})
| = | ||

- |
x
| ||

+ | |||

- |
y
| ||

+ | |||

- |
z
| ||

+ |
O(h^{ 2}) .
| (8) |

Second derivatives can be calculated by applying the first derivative formulas twice, or equivalently by using the central second difference formula. To derive it from the Taylor series, simply add rather than subtract the two Taylor series of Eq. 1,

f (x + h) + f (x - h) = 2f (x) + h^{ 2}f''(x) + O(h^{ 4})
| (9) |

f''(x) = + O(h^{ 2})
| (10) |

Error + h^{ 2}
| (11) |

The Laplacian of a function can now be calculated as

(x_{0},y_{0},z_{0})
| = | ||

+ | |||

+ | |||

+ |
O(h^{ 2}) .
| (12) |

We can also use our first derivative formulas twice.
If we calculate the
Laplacian by taking the divergence of the gradient, both calculated
numerically from our central difference formulas above, we get
the formula of Eq. 12 with *h* replaced by 2*h* .
Calculating the divergence of the curl by substituting Eq. 8
into Eq. 7, shows that the central difference formulas evaluate
to zero identically for this operation.