Skip to content
Brainlag

Theme

Colour

← All simulations

Differentiation from first principles

The gradient of a curve at a point is the limit of the gradients of chords. Pull the second point Q towards P and the chord turns into the tangent.

Chord gradient and f'(x)

Readouts

What's happening

A curve has no single gradient, so we measure it at one point P = (x, f(x)). Take a second point Q a horizontal step h further on. The chord PQ has gradient (f(x + h) − f(x))/h, which you can always work out. As h shrinks towards 0, Q slides down the curve towards P and the chord gradient settles on one value: the derivative f'(x), the gradient of the tangent at P. For f(x) = x² the chord gradient is exactly 2x + h, so the limit is 2x. The graph traces the chord gradient for every x at the current h against the true f'(x): they meet as h goes to 0. In Advanced, the central difference (f(x + h) − f(x − h))/(2h) uses a point on each side, and its error shrinks like h² instead of h. Computers can't take h all the way to 0: below about 10⁻⁸ rounding errors take over, which the error graph shows.

f'(x) = lim (f(x + h) − f(x)) / h as h → 0forward error ≈ ½ f''(x) hcentral: (f(x + h) − f(x − h)) / 2h, error ≈ ⅙ f'''(x) h²

A-Level Maths (AQA, Edexcel, OCR): differentiation from first principles for xⁿ, sin x and cos x; gradients of tangents. First-year numerical analysis: finite differences and rounding error.

Work through the numbers with Graphing Calculator and Scientific Calculator.

Challenge

Predict first: for f(x) = x³ at x = 2, what is the chord gradient when h = 1, and what does it tend to as h shrinks? Choose x³, set x = 2, type your guess for f'(2) into the box, then press Shrink h.

FAQ

How do you differentiate x² from first principles?
Write the chord gradient: ((x + h)² − x²)/h = (2xh + h²)/h = 2x + h. Now let h tend to 0: the gradient tends to 2x, so f'(x) = 2x. The h only disappears in the limit, never by putting h = 0 into the fraction, which would give 0/0.
Why can't we just put h = 0?
The chord needs two different points. At h = 0 the fraction is 0/0, which has no value. The derivative is what the chord gradient gets closer and closer to as h shrinks, which is a limit.
Why is the central difference more accurate?
Expanding f(x ± h) as Taylor series, the h² terms cancel in f(x + h) − f(x − h), so the error is about f'''(x)h²/6 instead of f''(x)h/2. Halving h cuts the forward error by 2 and the central error by 4. On the log-log error graph the lines have slopes 1 and 2.
Why does the error go up again when h is tiny?
A computer stores about 16 significant figures. When h is tiny, f(x + h) and f(x) agree in almost every digit, so their difference loses most of its precision, and dividing by h magnifies that rounding error of about 10⁻¹⁶/h. The best forward h is near 10⁻⁸. This sim stops at h = 10⁻⁶, so the readouts stay meaningful while the error graph still shows the floor setting in.