x(t+h) - x(t)
x'(t) = ------------- + O(h)
h
and
x(t+h) - x(t-h)
x'(t) = --------------- + O(h^2)
2h
are supposed to be better and better approximations to the derivative.
However, in finite precision, the subtraction in the numerator of these
expressions can cause problems (remember `cancellation error'?).
Write a simple program to observe this tradeoff --- the tradeoff between discretization error (which gets smaller as h goes to zero) and cancellation error (which gets larger). You do not have to turn in a copy of your program.
Try x(t) = t3 and evaluate the two finite difference formulas above for t=0.25. Try h = 10-n, for n = 1, 2, ..., 15. Give your results in a table something like this:
O(h) formula O(h^2) formula
n approx relerr approx relerr
---------------------------------------------------
1 2.7250E-01 4.5333E-01 1.9750E-01 5.3333E-02
2 1.9510E-01 4.0533E-02 1.8760E-01 5.3333E-04
3 1.8825E-01 4.0053E-03 1.8750E-01 5.3333E-06
.
.
.
---------------------------------------------------