How to Animate the Derivative | QuantumSketch

Animate the derivative by drawing a secant line on a curve and shrinking the gap h toward zero until it becomes the tangent. Here's the visual and the prompt.

By Shihab
2 min read

Animate the derivative by drawing a secant line through two points on a curve, then shrinking the gap h toward zero until the secant becomes the tangent. The slope of that final tangent is the derivative — this is the limit definition made visible.

The visual, beat by beat

  1. Plot the curve. Draw f(x) = x² on Axes. Mark point P at x = 1.
  2. Draw the secant. Add a second point Q at x = 1 + h, connect P→Q.
  3. Shrink h. Animate h: 1 → 0.5 → 0.1 → 0.01. Q slides toward P; the secant rotates.
  4. Snap to tangent. At the limit, the secant is the tangent. Show its slope.
  5. Reveal f'(x) = 2x → at x = 1, slope = 2.

This shows why the derivative equals the limit of the difference quotient, not just the formula.

The math on screen

f′(x)=lim⁔h→0f(x+h)āˆ’f(x)hf'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}

As h → 0, the average rate of change (secant slope) becomes the instantaneous rate (tangent slope).

How Manim builds it

| Element | Manim object | |---|---| | Axes + curve | Axes, axes.plot | | Moving point | Dot + ValueTracker | | Secant line | always_redraw(Line) | | Slope label | DecimalNumber |

A ValueTracker on h drives everything; always_redraw keeps the secant attached as h changes. Want the mechanics? See Mobjects, Scenes & Animations Explained.

The one-line prompt

"Show the derivative of f(x) = x² as a secant through P=(1,1) and a point h away, shrinking h to 0 until it's the tangent; display the slope updating to 2."

Animate it now

→ Paste that into quantumsketch.app for a narrated render. Next: Animate Riemann Sums and Visualize Gradient Descent.


Written by Shihab Shahriar Antor Ā· Shahriar Labs

FAQ

Q.What's the clearest way to show what a derivative is?

The clearest visual is the secant-to-tangent animation. Plot a curve like f(x) = x², mark a point P, and draw a secant line through P and a nearby point Q a distance h away. As you animate h shrinking toward zero, Q slides toward P and the secant rotates until it becomes the tangent line at P. The slope of that final line is the derivative f'(x). This directly shows the limit definition — the derivative is the slope the secant approaches as h goes to 0 — far better than a static formula.

Q.How do I animate the derivative without coding it myself?

Describe it as a prompt to an AI animation tool: 'Show the derivative of f(x) = x² as a secant line through P and a point h away, then shrink h to zero so it becomes the tangent; display the slope updating.' QuantumSketch turns that into a narrated Manim animation. Under the hood it uses Manim's Axes, a plotted function, a secant Line, and a Transform driven by a ValueTracker on h — but you don't write any of it. You just refine the prompt until the pacing feels right.

Tags:#math#animation#calculus
S

Shihab Shahriar

AI Engineer & Founder of Shahriar Labs. Exploring the intersection of design, cognition, and machine learning.