Derivative and Tangent Line Explorer
Sweep a tangent along a curve and watch its gradient trace out the derivative beneath. Compare the exact value against the limit definition.
Simulator
Drag across the scene to move the tangent, or nudge it with the left and right arrow keys. Space plays and pauses.
- Gradient here Exact value of 3x^2 - 3 at this x.
- -3
- x
- 0
- x^3 - 3x at x
- 0
- From the limit Estimated from the difference quotient at the current step h.
- -2.99
- Error How far the estimate falls from the exact gradient. Shrink h to close it.
- 0.01
Two turning points, at the two places the derivative crosses zero.
- Exact: 3x^2 - 3
- From the limit, h = 0.1
Cite this tool
Citing this tool
Last updated . Add the date you accessed it as well, which a citation of a page that can change asks for. If a specific result matters, cite the permalink from the tool’s share row instead of this page: it reproduces the exact parameters.
The equation
Differential calculus, Newton and Leibniz
How does the tangent line relate to the derivative?
The tangent line to a curve at x0, where the function is differentiable, is the straight line through (x0, y0) whose gradient equals the derivative f′(x0): y − y0 = f′(x0)(x − x0). It is the best linear approximation to the function near x0. It can still cross the curve, as at an inflection point, or meet it again elsewhere.
The derivative as a curve of its own
A symbolic differentiator returns an expression and leaves open the question many students are stuck on: why the gradient of a curve should itself be a curve.
The two panels here share a single x axis. Pick any vertical line through the scene: the upper curve gives the value of the function there, and the lower one gives how steeply it is changing. Play the sweep and the lower curve is drawn as the tangent moves, one gradient at a time, which is how a derivative is assembled.
Where the gradient crosses zero
A flat tangent marks a stationary point, and on every preset here that
point is a peak or a trough. Because the panels are aligned, the zero
crossing in the lower curve sits directly beneath it. On the default
cubic, x³ - 3x, that happens at x = -1 and
x = 1, which is exactly where 3x² - 3 = 0.
Where the gradient curve sits above zero the function is rising; below
zero it is falling. Try 1/x: its gradient is negative
everywhere in view, the same fact as the curve falling everywhere in
view.
Watching the limit converge
The derivative is defined as a limit, and the step slider lets you watch the limit being approached. The difference quotient
(f(x + h) - f(x)) / h
only approximates the derivative at any finite h, and the
approximation improves as h shrinks. Set the step to 1
and the estimated curve sits visibly off the exact one: on the default
cubic, with the default central difference, it reads
3x² - 2 in place of 3x² - 3, an error of
exactly h². Bring the step down to 0.01 and the two curves
become hard to tell apart.
Two ways to take a difference, and why one is better
The forward difference above is the textbook definition. The central difference straddles the point instead:
(f(x + h) - f(x - h)) / 2h
Both evaluate the function twice, so they cost the same. The central version is symmetric about the point, which cancels the leading error term: halve the step and the central error drops to a quarter, while the forward error only halves. Switch the Difference control with the step held fixed and the gap against the exact curve visibly changes.
Choose x² and the central difference is exact at
every step, even h = 1. The error term it discards
depends on the third derivative, and a quadratic’s third derivative is
zero.
Where functions stop existing
Three of the presets are undefined somewhere: ln x at zero
and below, √x below zero, and 1/x at zero, where
this explorer draws only the positive branch. The curves are cut off at
those boundaries rather than flattened along them, because a flat segment
would assert a value that does not exist.
A subtler case shows up in the readouts. Near the left edge of
ln x, with the central difference and a wide step, the exact
gradient is still reported but the estimate is not. The derivative is
well defined there; the finite difference fails, because it needs
f(x - h) and that point lies outside the domain. The From the
limit readout says out of domain instead of printing a meaningless
number.
Your own function
Pick Type your own and the presets give way to a box. Whatever you type is differentiated symbolically, by the same rules you would apply on paper, so the exact gradient stays exact and the Error readout keeps its meaning. The derivative itself is shown in the hint under the gradient readout, so you can check it against your own working.
Some functions come back refused, with a reason. abs(x) has a
corner at zero, floor(x) is flat between jumps, and
min bends where its arguments cross. None of them has a
gradient everywhere. The answer usually given for abs is
sign(x), which is wrong at x = 0, the very point
a student of abs is looking at, so this explorer refuses
instead.
The viewing window comes from the function as well. It is the widest
stretch between −6 and 6 where the function was found to have
values, which is why a typed ln x opens on the positive side
and a typed 1/x does not straddle its pole.
Common mistakes
- Reading the lower curve as a second copy of the function.
It is the slope of the function, and its units differ: units of
yper unit ofx. - Thinking a large function value means a large gradient.
Try
√x: near the origin the function is close to zero, yet its gradient is unbounded there. Height and steepness are independent. - Believing a smaller step is always better. In exact
arithmetic it is. In floating point, shrinking
hfar enough subtracts two nearly equal numbers and the answer degrades again. The slider stops at 0.001, comfortably above where that starts to bite. - Expecting the tangent to touch at only one point. It is the line matching the curve’s slope at the marked point. On a cubic it generally crosses the curve again somewhere else.
- Assuming the gradient is zero wherever the curve looks flat. The zoom can deceive. Read the number printed beside the marker instead of the picture.
Model and assumptions
The method, what it assumes and how accurate it is
- Method
- Exact expression, no time stepping
- Repeatability
- Deterministic. The same link gives the same numbers on any machine.
What it assumes
- The exact derivative is symbolic, either hand differentiated for a preset or derived by the differentiation rules for a typed function, never estimated.
- The numerical estimate is a forward or central difference at the step you choose, so the error between the two is a real error rather than the gap between two approximations.
- Functions with a corner or a jump are refused rather than given a derivative that is wrong at exactly the interesting point.
Numerical accuracy
No time stepping, so nothing accumulates, and the exact gradient is exact to rounding: differentiated by hand for a preset and by the differentiation rules for a typed function. The estimate beside it is a finite difference at the step you choose, so it carries a real error by construction, and showing that error is the point of the tool. It grows with the step, and for very small steps rounding in the subtraction takes over.
Common questions
Why is the derivative a whole curve rather than a single number?
Because the gradient changes as you move along the function. At each x there is one number, the slope of the tangent there, and collecting all of them gives a new function. The lower panel is built exactly that way: the tangent sweeps, and the gradient it reports at each point is plotted below.
What does it mean when the gradient curve crosses zero?
The tangent is horizontal, so the function has a turning point. Because both panels share one x axis, the crossing sits directly beneath the peak or trough that produced it. On the cubic the gradient crosses zero at x = -1 and x = 1, which is where 3x squared minus 3 equals zero.
What is the step h actually doing?
It is the gap in the difference quotient, the finite version of the limit. The derivative is defined as what that quotient approaches as h goes to zero, and you can watch it approach: shrink h and the estimated curve settles onto the exact one. Widen it and the two visibly part company.
Why is the central difference better than the forward one?
It is symmetric about the point, so the leading error term cancels. Both methods evaluate the function twice, so they cost the same, but halving h quarters the central error while only halving the forward one. The forward version is the one written in textbooks because it is the definition, not because it is the best way to compute.
Why do some functions stop at the edge of the panel?
Because they are undefined beyond it, or in one case because only one branch is drawn. Natural log is undefined at zero and below, the square root below zero, and one over x only at zero; this explorer draws the positive branch of one over x and leaves the negative one out. The curve is cut off rather than flattened along the edge, because a flat segment there would claim the function has a value it does not have.