Check a derivative with a finite difference

Check signs and decimal points before moving to the next value. · 170 words

A derivative is the instantaneous rate of change of a function. A finite difference checks it by evaluating the function at nearby points. For f(x) = x^3 - 2x, the exact derivative is f'(x) = 3x^2 - 2, so f'(2) = 10. The central difference is [f(x+h) - f(x-h)] / (2h), where h is a small positive step. With h = 0.01, f(2.01) = 4.100601 and f(1.99) = 3.900599. The estimate is (4.100601 - 3.900599) / 0.02 = 10.0001, close to 10.

Finite differences can reveal a wrong derivative implementation. For g(x) = x^2, the one-sided difference, which uses x and x+h, gives [g(x+h) - g(x)] / h. At x = 3 and h = 0.1, it gives (9.61 - 9) / 0.1 = 6.1, while g'(3) = 6. Using h = 0.05 gives 6.05, which is closer. The central difference gives (9.61 - 8.41) / 0.2 = 6 exactly. Use a small but not tiny h: tiny steps make numerical rounding errors larger, while large steps increase approximation error.

Check your recall

Using the central difference for f(x) = x^3 - 2x at x = 2 with h = 0.01, what value do you get, and is it correct?

Check your answer

The finite-difference estimate is 10.0001. The exact derivative is f'(2) = 10, so the estimate is correct within 0.0001.

Sources and credits

Original KeyTouch lesson. Background reading · Google · Linear regression.