+10 XP

Analytical vs Numerical Derivatives

There are two ways to get a derivative, and knowing which to use is half the battle.

1. Analytical (exact). You have a formula, like f(t) = t². You apply the rules (power, product, chain) to get an exact new formula: f′(t) = 2t. No error. You can evaluate it anywhere.

Python can do this symbolically with SymPysp.diff(f) hands you the exact formula. (That's what powered the explorer earlier, under the hood.)

2. Numerical (approximate). You only have data points — measurements, a recorded signal — not a formula. You estimate the slope with the finite difference:

FD = ( f(a + h) − f(a) ) / h

The rise over the run between two nearby points, a small step h apart. As h → 0, this approaches the true derivative.

The catch with h: smaller h = more accurate, but more computation. Too large and you miss the curve's detail. There's always a tradeoff.

Also: a numerical derivative is one point shorter than the original — with N points you can only form N−1 differences (each one needs a pair of neighbors).

See the tradeoff for yourself. The exact derivative of sin(t) is cos(t). Below, the finite difference estimates that derivative using a step size h. Drag h and watch how close the numerical estimate (green) stays to the exact answer (orange).

h — the step size (gap between sample points)h = 0.50
-10-50510Time, t (au)
sin(t)
exact derivative: cos(t)
numerical derivative

The exact derivative of sin(t) is cos(t) (orange). The green curve is the finite-difference estimate using step h. Shrink h → green hugs orange (accurate). Grow h → green lags and distorts. Smaller h is more accurate, but needs more points — the accuracy-vs-cost tradeoff.

Rule of thumb: have a formula? Differentiate it analytically (exact). Only have recorded data? Go numerical with np.gradient. Same idea — the difference is exact formula vs approximation from data.