Skip to content
ScienceQuest
Maths & Data Simulator School

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
Parameters

The gap used by the limit definition. Widen it and the estimate visibly leaves the true gradient.

Both cost two evaluations of f. Central is second order, forward is only first.

Two turning points, at the two places the derivative crosses zero.

  • Exact: 3x^2 - 3
  • From the limit, h = 0.1
The exact gradient against the one the limit definition gives at the current step. The gap between them is the error, and it closes as h shrinks.

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.

Teaching with this? You can put it on a class page or LMS for free, with no ads inside the frame. Get the embed code.

The equation

f′(x)=lim⁡h→0f(x+h)−f(x)hf'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}

Differential calculus, Newton and Leibniz

The derivative is a function, not an answer

Most tools that differentiate will hand you an expression and stop. That answers a question, but usually not the one people are stuck on, which is why the gradient of a curve should turn out to be a curve of its own.

The two panels here share a single x axis, and that alignment is the whole point. Pick any vertical line through the scene: the upper curve tells you the value of the function there, and the lower one tells you how steeply it is changing. Watch the tangent sweep and the lower curve is drawn as it goes, one gradient at a time, which is precisely how a derivative is assembled.

Where the gradient crosses zero

A flat tangent means a turning point. Because the panels are aligned, the zero crossing in the lower curve sits directly beneath the peak or trough that caused it. On the default cubic, x³ - 3x, that happens at x = -1 and x = 1, which is exactly where 3x² - 3 = 0.

The sign tells you the rest. 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, which is the same statement as the curve falling everywhere, said twice.

Watching a limit actually converge

The derivative is defined as a limit, and a limit is a promise about what happens as something gets small. The step slider lets you keep that promise honest. The difference quotient

(f(x + h) - f(x)) / h

is not the derivative for any particular h; it is an approximation that improves as h shrinks. Set the step to 1 and the estimated curve is visibly the wrong shape. Bring it down to 0.01 and the two curves become hard to tell apart. Nothing is hidden in that transition, and it is a more convincing account of what a limit means than any amount of notation.

Two ways to take a difference, and why one is better

The forward difference above is the textbook definition. The central difference instead straddles the point:

(f(x + h) - f(x - h)) / 2h

Both evaluate the function twice, so they cost exactly the same. But the central version is symmetric about the point, which cancels the leading error term. In practice: halve the step and the central error drops to a quarter, while the forward error only halves. Switch the method with the step held fixed and the gap against the exact curve visibly changes.

There is a neat special case worth trying. 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 functions here are undefined somewhere: ln x at zero and below, √x below zero, and 1/x at zero. 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 a wide step, the exact gradient is still reported but the estimate is not. The derivative is perfectly well defined there; it is the finite difference that fails, because it needs f(x - h) and that point lies outside the domain. Distinguishing those two failures is the difference between a tool that is honest and one that quietly prints 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 column keeps meaning what it says. The derivative itself is shown in the hint under the gradient readout, so you can check it against your working rather than taking it on trust.

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 precisely the point anybody studying it is looking at, so this refuses instead of being confidently wrong there.

The viewing window is not a guess either. It is the widest stretch between -6 and 6 where the function was found to have values, which is why ln x opens on the positive side and 1/x does not straddle its pole.

Common mistakes

  • Reading the lower curve as a second copy of the function. It is not the function at a different scale. It is the slope of the function, and its units differ.
  • Thinking a large function value means a large gradient. Try √x: the function grows slowly and steadily, yet its gradient is unbounded at the origin. Height and steepness are independent.
  • Believing a smaller step is always better. In exact arithmetic it is. In floating point, shrinking h far 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 will generally cross the curve again somewhere else, and that is fine.
  • Assuming the gradient is zero wherever the curve looks flat. Zoom is deceptive. Read the number rather than the picture, which is why it is printed beside the marker.

Model and assumptions

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.

Derivative and Tangent Line Explorer: the gradient of the cubic x³ − 3x against x, crossing zero at its two turning points.
The gradient of the cubic x³ − 3x against x, crossing zero at its two turning points, computed by the simulator’s own model. Image © ScienceQuest, CC BY 4.0. Free to reuse with credit and a link to this page; how to reuse it. Download PNG

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.