Differentiation · CMNA Laboratory

A derivative from nearby function values.

Move a finite distance away from x, measure the change in f, and turn the resulting secant slope into an approximation of the tangent.

Step size is the whole game.

A large h measures the wrong neighborhood. A very small h eventually runs into floating-point subtraction. The interesting numerical question is not simply “make h smaller,” but how the approximation behaves as h changes.

Bring your own function

Watch the secants become a tangent.

R evaluates your function while the laboratory halves h repeatedly and compares forward, symmetric, and Richardson estimates.

RuntimePreparing R…
RDefine f and optionally fp

levelhforwardsymmetricRichardson
Book§5.1.1 · Finite Differences · p. 126Book details
CMNA packagefindiffsymdiffrdiff
TeachingInstructor notes and chapter contextOpen teaching material