Complex step differentiation is a method of numerical differentiation that estimates a derivative using
a function value at a complex
number. Let be real and let
be analytic near
, with real values on a real neighborhood of
. For sufficiently small real
, its Taylor series
gives
where
is the imaginary unit. Taking the imaginary
part and dividing by
yields
Here
denotes big-O notation. Thus
estimates
with error
(Squire and Trapp 1998).
The approximation avoids subtracting nearly equal real function values, which can cause roundoff error in real finite difference formulas. It requires an analytic function with the stated real-valued restriction and numerical evaluation that preserves the small imaginary perturbation. It does not eliminate errors in the function evaluation or underflow.