The complex-step formula can be worked by hand for a polynomial
PHYSICS · Multi-part · Fermi University Physics · Mathematical Methods for Physics · Numerical and computational mathematics · Numerical and computational mathematics
Error, Chance and the Machine, Ch Approximating a function: interpolation and differentiation
Problem
The complex-step formula f′(x)≈Imf(x+ih)/h can be worked by hand for a polynomial. Take f(x)=x3, the point x=1 and a real step h.
((a)) Expand (1+ih)3 and find Imf(1+ih)/h exactly. Evaluate it for h=0.1.
((b)) Find the error of the formula (formula minus exact f′(1)) and show that it equals −h2f′′′(1)/6. Evaluate it for h=0.1.
((c)) Find the error of the central difference [f(1+h)−f(1−h)]/2h in the same way, and compare it with your answer to (b) at h=0.1.
((d)) At h=10−8 both truncation errors are of order 10−16. Explain why only the complex step delivers a derivative that accurate in binary64.