Drag the yellow point along the curve. Drag empty space to pan; scroll or use the buttons to zoom.

1. The derivative: slope of a tangent

The average rate of change of $f$ between $x_0$ and $x_0+h$ is the slope of the secant line (a straight line through two points on the curve) through those two points. The derivative is what that slope approaches as the second point slides into the first:

$$f'(x_0)=\lim_{h\to 0}\frac{f(x_0+h)-f(x_0)}{h}$$

In the lab the orange secant uses the current $h$. Press Animate h → 0 and watch it rotate into the yellow tangent. If the left and right versions of the limit disagree (try abs(x) at $x_0=0$) the function has a corner and is not differentiable there.

$$\begin{gathered}\tfrac{d}{dx}x^n=nx^{n-1}\\ \tfrac{d}{dx}e^x=e^x\\ \tfrac{d}{dx}\ln x=\tfrac1x\end{gathered}$$
$$\begin{gathered}\tfrac{d}{dx}\sin x=\cos x\\ \tfrac{d}{dx}\cos x=-\sin x\\ \tfrac{d}{dx}\tan x=\tfrac{1}{\cos^2 x}\end{gathered}$$

Combination rules: product $(uv)'=u'v+uv'$, quotient $\left(\tfrac uv\right)'=\tfrac{u'v-uv'}{v^2}$ and chain $\tfrac{d}{dx}f(g(x))=f'(g(x))\,g'(x)$. The symbolic panel applies exactly these rules.

2. The integral: limit of Riemann sums

Split $[a,b]$ into $n$ strips of width $\Delta x=(b-a)/n$ and add up $f(x_i^*)\,\Delta x$. Here $x_i^*$ is any sample point inside strip $i$ (its left end, right end or middle), so each term is the area of one thin rectangle. As $n\to\infty$ every sensible choice of sample point gives the same number, the definite integral:

$$\int_a^b f(x)\,dx=\lim_{n\to\infty}\sum_{i=1}^{n} f(x_i^*)\,\Delta x$$
RuleFormulaError for smooth f
Left / right$\Delta x\sum f(x_{i-1})$ or $\Delta x\sum f(x_i)$$O(\Delta x)$
Midpoint$\Delta x\sum f\!\left(\tfrac{x_{i-1}+x_i}{2}\right)$$O(\Delta x^2)$
Trapezoid$\tfrac{\Delta x}{2}\left[f_0+2f_1+\dots+2f_{n-1}+f_n\right]$$O(\Delta x^2)$
Simpson ($n$ even)$\tfrac{\Delta x}{3}\left[f_0+4f_1+2f_2+\dots+4f_{n-1}+f_n\right]$$O(\Delta x^4)$

How to read the error column: $O(\Delta x^2)$ means the error is roughly proportional to $\Delta x^2$, so halving the strip width cuts the error about 4×; $O(\Delta x)$ only halves it. Area below the axis counts as negative (red strips in the lab).

Fundamental Theorem of Calculus

Define the accumulation function $F(x)=\int_a^x f(t)\,dt$. The lower graph in Integral mode plots it. The theorem says $F$ is an antiderivative of $f$, so integrals can be computed from any antiderivative $G$:

$$\begin{gathered}F'(x)=f(x)\\ \int_a^b f(x)\,dx=G(b)-G(a)\end{gathered}$$

Look at the picture: where $f>0$ the curve $F$ rises, where $f<0$ it falls, and where $f$ crosses zero $F$ has a turning point.

3. Limits and the ε–δ definition

Intuition first: $\lim_{x\to c}f(x)=L$ says $f(x)$ can be made as close as we like to $L$ by taking $x$ close enough to $c$. The precise version reads ($\forall$ = "for every", $\exists$ = "there exists"):

$$\begin{gathered}\lim_{x\to c}f(x)=L \iff\\ \forall\varepsilon>0\ \exists\delta>0:\ 0<|x-c|<\delta \Rightarrow |f(x)-L|<\varepsilon\end{gathered}$$

Read it as a game. Your opponent chooses a tolerance band of half-height $\varepsilon$ around $L$. You must find a window of half-width $\delta$ around $c$ such that the whole graph inside the window (ignoring $x=c$ itself) stays inside the band. If you can always win, the limit is $L$. The value $f(c)$ itself plays no part: $\frac{\sin x}{x}$ is undefined at $0$ but its limit is $1$.

A limit fails to exist when the one-sided limits differ ($\tfrac{|x|}{x}$ at $0$), when the function blows up ($\tfrac1{x^2}$), or when it oscillates without settling ($\sin\tfrac1x$).

4. Taylor series

Near a point $a$, a smooth function is approximated by the polynomial that matches its value and first $n$ derivatives. Here $f^{(k)}$ is the $k$-th derivative, $k! = 1\cdot2\cdots k$, and $R_n$ is the error left over:

$$\begin{gathered}P_n(x)=\sum_{k=0}^{n}\frac{f^{(k)}(a)}{k!}(x-a)^k\\ R_n(x)=\frac{f^{(n+1)}(\xi)}{(n+1)!}(x-a)^{n+1}\end{gathered}$$

for some $\xi$ between $a$ and $x$ (Lagrange remainder). The series converges only inside the radius of convergence $R$, which equals the distance from $a$ to the nearest singularity of $f$ in the complex plane. In practice: inside that distance, more terms give a better fit; outside it, adding terms makes the approximation worse.

FunctionSeries about 0Radius
$e^x$$1+x+\tfrac{x^2}{2!}+\tfrac{x^3}{3!}+\cdots$$\infty$
$\sin x$$x-\tfrac{x^3}{3!}+\tfrac{x^5}{5!}-\cdots$$\infty$
$\cos x$$1-\tfrac{x^2}{2!}+\tfrac{x^4}{4!}-\cdots$$\infty$
$\ln(1+x)$$x-\tfrac{x^2}{2}+\tfrac{x^3}{3}-\cdots$$1$ (singular at $x=-1$)
$\tfrac{1}{1-x}$$1+x+x^2+x^3+\cdots$$1$ (pole at $x=1$)
$\tfrac{1}{1+x^2}$$1-x^2+x^4-\cdots$$1$ (poles at $\pm i$, invisible on the real line)

5. Optimisation

Interior maxima and minima of a differentiable function occur at critical points, where $f'(x)=0$ (or where $f'$ does not exist).

  • First-derivative test: if $f'$ changes from $+$ to $-$ the point is a local maximum; from $-$ to $+$ a local minimum; no sign change means neither.
  • Second-derivative test: $f''(c)<0$ gives a maximum, $f''(c)>0$ a minimum, and $f''(c)=0$ is inconclusive (think $x^3$ and $x^4$ at 0).
  • Inflection points are where $f''$ changes sign and the curve switches between concave up and concave down.
The lab locates critical points numerically: it samples the exact (symbolic) derivative across the visible window, finds sign changes, and refines each one by bisection to about 12 significant figures.

Example 1: a derivative from the definition

Let $f(x)=x^3-3x$ (the default function) and find $f'(2)$.

Secant with $h=0.1$: $f(2.1)=9.261-6.3=2.961$, $f(2)=8-6=2$, slope $=\tfrac{2.961-2}{0.1}=9.61$.

Secant with $h=0.01$: $f(2.01)=8.120601-6.03=2.090601$, slope $=9.0601$.

Exact: $f'(x)=3x^2-3$, so $f'(2)=9$. The secant slope is $9+6h+h^2$, which tends to 9.

In the lab: set $x_0=2$ and move the h slider to 0.1 and 0.01; the HUD shows these secant slopes.

Example 2: Riemann sums for $\int_0^2 x^2\,dx$ with $n=4$

$\Delta x=0.5$, grid $0, 0.5, 1, 1.5, 2$ with $f$ values $0, 0.25, 1, 2.25, 4$.

  • Left: $0.5(0+0.25+1+2.25)=1.75$
  • Right: $0.5(0.25+1+2.25+4)=3.75$
  • Midpoint: $0.5(0.0625+0.5625+1.5625+3.0625)=2.625$
  • Trapezoid: $\tfrac{1.75+3.75}{2}=2.75$
  • Simpson: $\tfrac{0.5}{3}(0+4(0.25)+2(1)+4(2.25)+4)=\tfrac{0.5}{3}(16)=2.6667$

Exact: $\left[\tfrac{x^3}{3}\right]_0^2=\tfrac83\approx 2.6667$. Simpson is exact for any cubic. Midpoint error $-0.0417$ is half the trapezoid error $+0.0833$ with the opposite sign, which is why Simpson $=\tfrac{2M+T}{3}$ works so well.

In the lab: enter x^2, set a = 0, b = 2, n = 4 and switch between methods.

Example 3: a limit with ε and δ

Show $\lim_{x\to 0}\tfrac{\sin x}{x}=1$ with $\varepsilon=0.01$.

From the Taylor series, $\tfrac{\sin x}{x}=1-\tfrac{x^2}{6}+\tfrac{x^4}{120}-\cdots$, so $\left|\tfrac{\sin x}{x}-1\right|<\tfrac{x^2}{6}$ for $x\neq 0$.

We need $\tfrac{x^2}{6}<0.01$, i.e. $|x|<\sqrt{0.06}=0.2449$. So $\delta=0.2449$ works (the lab's Largest δ search returns about 0.245).

Example 4: estimating $e^{0.5}$ with Taylor polynomials

About $a=0$: $P_3(0.5)=1+0.5+\tfrac{0.25}{2}+\tfrac{0.125}{6}=1.645833$. True value $e^{0.5}=1.648721$, error $0.00289$.

Lagrange bound: $|R_3|\le \tfrac{e^{0.5}}{4!}(0.5)^4=0.0043$. The actual error is below the bound, as it must be.

With $n=6$: $P_6(0.5)=1.6487196$, error $1.7\times10^{-6}$ (the bound $\tfrac{e^{0.5}}{7!}(0.5)^7=2.6\times10^{-6}$ again holds).

Example 5: the cheapest 330 ml can

A closed cylinder of radius $r$ and height $h$ holds $V=\pi r^2h=330\ \text{cm}^3$, so $h=\tfrac{V}{\pi r^2}$. Material area:

$$A(r)=2\pi r^2+2\pi r h=2\pi r^2+\frac{2V}{r}$$

$A'(r)=4\pi r-\tfrac{2V}{r^2}=0\Rightarrow r^3=\tfrac{V}{2\pi}=52.52$, so $r=3.745$ cm and $h=\tfrac{330}{\pi(3.745)^2}=7.49$ cm $=2r$.

$A''(r)=4\pi+\tfrac{4V}{r^3}>0$, so this is a minimum: $A=264.4\ \text{cm}^2$.

Real drinks cans are taller and thinner (about 6.6 cm across). One reason: the ends are made of thicker, more expensive metal. If the ends cost $k$ times as much per cm², $C(r)=2\pi k r^2+\tfrac{2V}{r}$ is minimised at $r^3=\tfrac{V}{2\pi k}$, giving $h=2kr$. Try $k=2$ in the lab.

Challenges (checked automatically)

Guided experiments

  1. Corners. Enter abs(x), put $x_0$ at 0 and shrink $h$. The secant slope stays at $+1$ for positive $h$. The derivative does not exist at 0, and the symbolic $f'$ ($\tfrac{x}{|x|}$) is undefined there.
  2. Accumulation. In Integral mode with sin(x) and $a=0$, watch $F(x)$: it is $1-\cos x$. Where is $F$ largest? (At $x=\pi$, where $f$ changes sign.)
  3. Convergence rates. Choose exp(x) on $[0,1]$. Double $n$ from 10 to 20 and note the error for each method: left/right halve, midpoint/trapezoid quarter, Simpson drops by a factor of about 16.
  4. Invisible singularities. In Taylor mode pick $\tfrac{1}{1+x^2}$. It is perfectly smooth on the real line, yet the series about 0 diverges for $|x|>1$. Move the centre to $a=1$ and the radius grows to $\sqrt2$.
  5. Inconclusive test. In Optimisation mode enter x^4 and then x^3. Both have $f'(0)=0$ and $f''(0)=0$; only the first-derivative test can tell them apart.

A tiny computer algebra system

The function box is not passed to JavaScript's eval. A tokenizer splits the text into numbers, names and operators, and a recursive-descent parser builds an expression tree using this grammar (lowest precedence first):

expr := term (("+" | "−") term)* term := unary (("*" | "/") unary | implicit-product)* unary := "−" unary | power power := atom ("^" unary)? (right-associative: 2^3^2 = 2^9) atom := number | x | pi | e | func "(" expr ")" | "(" expr ")"

So $-x^2$ means $-(x^2)$ and $\sin(x)^2$ means $(\sin x)^2$. The tree is compiled into a closure for fast plotting. A real-valued power is used, so x^(1/3) works for negative $x$.

Symbolic differentiation

The derivative is built recursively on the tree with the sum, product, quotient, power and chain rules, then simplified by "smart constructors" that fold constants and remove $0$ and $1$ terms ($u+0\to u$, $1\cdot u\to u$, $u^1\to u$, $x\cdot x^n\to x^{n+1}$). If the result is a polynomial it is put into standard form, so $\frac{d}{dx}(x^2+1)(x-3)$ is shown as $3x^2-6x+1$.

Taylor coefficients by automatic differentiation

Taylor mode does not differentiate symbolically 20 times (the expressions would explode). Instead every node of the tree is evaluated as a truncated power series about $a$, using exact recurrences such as $w=e^u\Rightarrow w_k=\tfrac1k\sum_{j=1}^{k} j\,u_j\,w_{k-j}$. This gives all coefficients $f^{(k)}(a)/k!$ to machine precision in one pass.