In: Advanced Math
Carry out a numerical experiment to compare the accu- racy of Formulas (5) and (19) on a function f whose derivative can be computed precisely. Take a sequence of valuesforh,suchas4−n with0≦n≦12.
hint: For CE 4.3.4, use f(x) = sin x and x = 0.25, for example. Then the exact derivative is cos 0.25, so you can compare your results to it, compute errors, and study how they behave as h decreases. You may want to format your outputs so that for each n you print, on the same row, the values of h, approximate f 0 (0.25), error of the approximation, and the theoretically estimated error term (h 2/6 for formula (5) and h 4/30 for formula (19)—here we are using the fact that the derivatives of sin x are at most 1 in absolute value). Don’t forget to discuss your findings!
f′(x)≈ 1 [f(x+h)− f(x−h)] (5)
f′(x)≈ 1 [f(x+h)− f(x−h)] /2h − 1 /12h(f(x +2h)−2[f(x +h)− f(x −h)]− f(x −2h)) (19)