mathcalculus

derivatives

the slope at a point: how fast something changes right now.

report a mistake
.md

the slope between two points of a curve is a secant. slide the second point onto the first and the secant becomes the tangent. its slope is the derivative, how fast f is changing right there.

the secant
(f(x + h) − f(x)) / h rise over run between two points. as h → 0 it becomes f'(x)
power rule
(xⁿ)' = n xⁿ⁻¹ x² has slope 2x, and x³ has 3x²
sums and constants
(f + g)' = f' + g' a constant has slope 0, and c·f has slope c·f'
product rule
(fg)' = f'g + fg' not f'·g'
chain rule
f(g(x))' = f'(g(x)) · g'(x) the inner slope multiplies. sin 2x has slope 2 cos 2x
sin, eˣ, ln x
cos x, eˣ, 1/x eˣ is its own slope
f' = 0
a high point, a low point, or neither x³ is flat at 0 and keeps climbing
reach for it
  • velocity from position, and acceleration from velocity
  • finding where something is biggest or smallest
  • replacing a curve by a line near a point
  • gradient descent, physics, and the fade curves in noise
on this page
  1. the idea
  2. explore
  3. try it
  4. the rules
  5. worked examples
  6. the key idea up close
  7. in code
  8. pitfalls
  9. practice
  10. sources

the idea

a straight line has one slope: rise over run, the same between any two of its points. a curve doesn’t. on y=x2y = x^2 the slope from (1,1)(1, 1) to (2,4)(2, 4) is 33, and from (1,1)(1, 1) to (1.5,2.25)(1.5, 2.25) it’s 2.52.5. a line through two points of a curve is a secant, and its slope is the average rate of change over that stretch.

the derivative asks a sharper question: how fast is ff changing at one point? slide the second point toward the first. the secant swings, its slope settles down, and in the limit the line only touches the curve: the tangent. its slope is the derivative of ff at that point, written f′(x)f'(x) or dydx\frac{dy}{dx}.

−1012301234h = 13(1, 1)(2, 4)
the curve y=x2y = x^2 and the point (1,1)(1, 1) on it. a curve has no single slope, but a line through two of its points does. take a second point one step to the right, (2,4)(2, 4). the line through both is a secant, and its slope is rise over run: (4−1)/(2−1)=3(4 - 1) / (2 - 1) = 3.

an animation on the graph of y = x² from x = −1.5 to 3.5 and y = −0.5 to 4.5: a line through (1, 1) and a second point (1 + h, (1 + h)²), with the run h and the rise drawn under it. h shrinks from 1 to 0.5, 0.1 and 0.01, the line swings as the second point slides in, and a table under the plot collects the slopes: 3, 2.5, 2.1, 2.01, closing in on 2. then the two points meet, the secant becomes the tangent, and its slope is 2: the derivative of x² at 1.

a derivative is a limit, the subject of the limits page. hh never gets to 00, since the quotient would read 0/00/0, but the slopes head somewhere, and that somewhere is f′(x)f'(x).

explore

the derivative is a function of its own: a slope at every xx. pick a curve and drag the point. the tangent follows, and the graph of f′f' below records its slope. where f′f' is above the axis the curve climbs, where it’s below the curve falls, and where f′f' crosses zero the tangent is flat.

−3−2−1012302468f−3−2−10123−5052.00f'

drag the point along the curve, or tab to it and use the arrow keys: 0.1 a step

x
1
f(x) = x²
1.00
f'(x) = 2x, the slope
2.00
the tangent
y = 1 + 2(x − 1)

f' > 0: the curve climbs here, left to right

two plots stacked, with a button for each of four curves: x², x³ − 3x, sin x and eˣ. on top, the curve in cyan from x = −3 to 3, with a point to drag along it and the tangent line through the point. below, the graph of the derivative in amber over the same x, with the same x marked and its height drawn as a bar, so the slope on top is the height below. a readout gives x, f(x), f'(x), the tangent's equation, and whether the curve is climbing, falling or flat there. it opens on x² at x = 1: f(1) = 1, slope 2, tangent y = 1 + 2(x − 1), climbing. on x³ − 3x the slope is 0 at x = −1, a high point at (−1, 2), and at x = 1, a low point at (1, −2). on eˣ the two plots show the same curve. the arrow keys move the point by 0.1.

on eˣ the two plots are the same curve: the slope of eˣ at any x is eˣ.

try it

what is the derivative of x³?

pick one.

0 / 0 right

a practice exercise with four kinds of question: pick the derivative of a function like x³ or sin(2x), give the slope at a point, say where a function's slope is 0, and say whether a curve is climbing, falling or flat at a point. it opens on the derivative of x³, which is 3x², then the slope of x² at x = 3, which is 6. a slope question draws its curve with the tangent after the answer.

the rules

the definition

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

the slope of the secant from xx to x+hx + h, as hh shrinks to nothing. f′(x)f'(x), dydx\frac{dy}{dx} and ddxf(x)\frac{d}{dx} f(x) all name it. the dd‘s stand for small changes: dy/dxdy/dx is the rise over the run of a step so short that the curve is straight along it.

constants and multiples

(c)′=0(c⋅f)′=c⋅f′(c)' = 0 \qquad (c \cdot f)' = c \cdot f'

a constant is a flat line: f(x+h)−f(x)f(x + h) - f(x) is 00 for every hh, so the quotient is 00. a multiple scales every rise by cc and leaves the run alone, so the slope scales by cc.

the power rule

(xn)′=n xn−1(x^n)' = n\,x^{n-1}

expand (x+h)n(x + h)^n. the first term is xnx^n, the next is nxn−1hn x^{n-1} h, and every term after that carries h2h^2 or more. subtract xnx^n, divide by hh, and all that survives as h→0h \to 0 is nxn−1n x^{n-1}. the key idea below does it in full. the rule holds for every real nn, not only whole ones: x=x1/2\sqrt{x} = x^{1/2} has slope 12x\frac{1}{2\sqrt{x}}, and 1/x=x−11/x = x^{-1} has slope −1/x2-1/x^2.

sums

(f+g)′=f′+g′(f + g)' = f' + g'

the rise of a sum is the sum of the rises, so the quotient splits in two. with the two rules above, a polynomial differentiates term by term: 3x4−5x2+73x^4 - 5x^2 + 7 has slope 12x3−10x12x^3 - 10x.

the product rule

(fg)′=f′g+fg′(fg)' = f'g + fg'

think of f⋅gf \cdot g as the area of a rectangle with sides ff and gg. when xx moves by hh, one side grows by about f′hf'h and the other by g′hg'h. the area gains a strip f′h⋅gf'h \cdot g along one edge and a strip f⋅g′hf \cdot g'h along the other, plus a corner f′h⋅g′hf'h \cdot g'h that carries h2h^2 and vanishes in the quotient. each factor changes while the other holds still, and the two changes add. a check: x⋅x2x \cdot x^2 has slope 1⋅x2+x⋅2x=3x21 \cdot x^2 + x \cdot 2x = 3x^2, which is (x3)′(x^3)'.

the quotient rule

(fg)′=f′g−fg′g2\left(\frac{f}{g}\right)' = \frac{f'g - fg'}{g^2}

f/gf / g is f⋅g−1f \cdot g^{-1}. the power rule with the chain rule below gives (g−1)′=−g′/g2(g^{-1})' = -g' / g^2, and the product rule then gives f′/g−fg′/g2f'/g - fg'/g^2. put both over g2g^2. the order in the numerator matters: f′gf'g first, then minus fg′fg'.

the chain rule

(f(g(x)))′=f′(g(x))⋅g′(x)\big(f(g(x))\big)' = f'(g(x)) \cdot g'(x)

move xx by hh. the inside moves by about g′(x) hg'(x)\,h, and ff sees that as its own step, so the outside moves by about f′(g(x))f'(g(x)) times it. the rates multiply. it’s composition with slopes: gg runs first, then ff, and the slope is read inside out. sin⁡(2x)\sin(2x) is sin⁡\sin of 2x2x, so its slope is cos⁡(2x)⋅2=2cos⁡(2x)\cos(2x) \cdot 2 = 2\cos(2x). (x2+1)3(x^2 + 1)^3 has slope 3(x2+1)2⋅2x=6x(x2+1)23(x^2 + 1)^2 \cdot 2x = 6x(x^2 + 1)^2.

sin and cos

(sin⁡x)′=cos⁡x(cos⁡x)′=−sin⁡x\begin{gathered} (\sin x)' = \cos x \\[6pt] (\cos x)' = -\sin x \end{gathered}

the angle sum opens up sin⁡(x+h)\sin(x + h) as sin⁡xcos⁡h+cos⁡xsin⁡h\sin x \cos h + \cos x \sin h. subtract sin⁡x\sin x and divide by hh:

sin⁡x⋅cos⁡h−1h+cos⁡x⋅sin⁡hh\sin x \cdot \frac{\cos h - 1}{h} + \cos x \cdot \frac{\sin h}{h}

as h→0h \to 0, sin⁡h/h→1\sin h / h \to 1 and (cos⁡h−1)/h→0(\cos h - 1) / h \to 0. at h=0.01h = 0.01 they read 0.999980.99998 and −0.0050-0.0050. so the slope is cos⁡x\cos x, which is where the trig page left off: 11 at 00, where the wave starts out steepest. cos is sin a quarter turn ahead, so its slope is cos a quarter turn ahead: −sin⁡x-\sin x. this is in radians. in degrees, the slope of sin at 0 would be π/180≈0.01745\pi / 180 \approx 0.01745.

exponentials and logs

(ex)′=ex(bx)′=bxln⁡b(ln⁡x)′=1x\begin{gathered} (e^x)' = e^x \qquad (b^x)' = b^x \ln b \\[6pt] (\ln x)' = \frac{1}{x} \end{gathered}

for any base, bx+h−bx=bx(bh−1)b^{x + h} - b^x = b^x (b^h - 1), so the quotient is bxb^x times (bh−1)/h(b^h - 1) / h, a number that depends on the base and not on xx. at h=0.001h = 0.001 that number is 0.69340.6934 for base 2 and 1.09921.0992 for base 3, closing in on ln⁡2≈0.6931\ln 2 \approx 0.6931 and ln⁡3≈1.0986\ln 3 \approx 1.0986. exactly one base makes it 11, and that base is ee: at h=0.001h = 0.001 its factor reads 1.00051.0005. so exe^x is its own slope, and every other bxb^x is its own slope times ln⁡b\ln b. that is why ee is the natural base the exponents page promised: it grows at a rate equal to its size.

ln⁡x\ln x undoes exe^x: y=ln⁡xy = \ln x means ey=xe^y = x. differentiate both sides, the left one with the chain rule: ey⋅y′=1e^y \cdot y' = 1, so y′=1/ey=1/xy' = 1 / e^y = 1 / x.

the second derivative

f′′=(f′)′f'' = (f')'

the slope of the slope. where f′′>0f'' > 0 the slope is increasing and the curve bends up, like a bowl. where f′′<0f'' < 0 it bends down. at a point where f′=0f' = 0, that settles which kind of flat it is: bending up means a low point, bending down a high one, and f′′=0f'' = 0 means look closer. x3−3xx^3 - 3x has f′=3x2−3f' = 3x^2 - 3, zero at ±1\pm 1, and f′′=6xf'' = 6x: −6-6 at −1-1, a high point at (−1,2)(-1, 2), and 66 at 11, a low point at (1,−2)(1, -2). x3x^3 has f′=3x2f' = 3x^2 and f′′=6xf'' = 6x, both 00 at 00, and it is neither: the curve flattens for an instant and keeps climbing.

the noise in a shader blends with the fade curve 6t5−15t4+10t36t^5 - 15t^4 + 10t^3 because both its slope, 30t2(t−1)230t^2(t - 1)^2, and its second derivative, 60t(2t−1)(t−1)60t(2t - 1)(t - 1), are 00 at t=0t = 0 and at t=1t = 1. the cubic it replaced, 3t2−2t33t^2 - 2t^3, has a flat slope at both ends too, but its second derivative is 6−12t6 - 12t, which is 66 at 00 and −6-6 at 11, and the bend jumped where cells met.1

motion

v(t)=s′(t)a(t)=v′(t)=s′′(t)\begin{gathered} v(t) = s'(t) \\[6pt] a(t) = v'(t) = s''(t) \end{gathered}

the slope of position is velocity: a rise in meters over a run in seconds. the slope of velocity is acceleration. a ball thrown straight up at 20 m/s, with gravity rounded to 10 m/s², is at height s(t)=20t−5t2s(t) = 20t - 5t^2 after tt seconds. then v(t)=20−10tv(t) = 20 - 10t and a(t)=−10a(t) = -10. at t=1t = 1 it’s 15 m up and climbing at 10 m/s. at t=2t = 2 it’s at the top, 20 m, with v=0v = 0. at t=3t = 3 it’s back at 15 m, falling at 10 m/s. the top is where the velocity crosses zero, a high point of ss. the integrals page runs this backwards, from velocity to distance.

linear approximation

f(a+h)≈f(a)+f′(a) hf(a + h) \approx f(a) + f'(a)\,h

the definition, turned around: for a small hh the quotient is close to f′(a)f'(a), so f(a+h)f(a + h) is close to f(a)f(a) plus f′(a)f'(a) times hh. that’s the value of the tangent line at a+ha + h, the line the explore figure’s readout writes out. 17\sqrt{17}: take f(x)=xf(x) = \sqrt{x} at a=16a = 16, where f=4f = 4 and f′=1/(216)=1/8f' = 1 / (2\sqrt{16}) = 1/8. then 17≈4+1/8=4.125\sqrt{17} \approx 4 + 1/8 = 4.125, against 4.12314.1231. sin⁡0.1≈0+1⋅0.1=0.1\sin 0.1 \approx 0 + 1 \cdot 0.1 = 0.1, against 0.09980.0998. 1.025≈1+5⋅0.02=1.11.02^5 \approx 1 + 5 \cdot 0.02 = 1.1, against 1.10411.1041.

this is why a small enough piece of a smooth curve looks straight. the gap between the curve and its tangent is about 12f′′(a) h2\tfrac{1}{2} f''(a)\, h^2, so it shrinks like h2h^2 while the piece shrinks like hh. on x2x^2 at 11, a step of 0.10.1 rises 0.210.21 against the tangent’s 0.20.2: a gap of 0.010.01, about a twentieth of the rise. a step of 0.010.01 rises 0.02010.0201 against 0.020.02: a gap of 0.00010.0001, about a two-hundredth. every zoom by 10 makes the curve look 10 times straighter. the series page keeps going, adding the h2h^2 term and the ones after it.

worked examples

a polynomial, term by term

f(x)=3x4−5x2+7f(x) = 3x^4 - 5x^2 + 7. the power rule on each term, with the constants in front riding along and the 7 dropping out: f′(x)=12x3−10xf'(x) = 12x^3 - 10x. at x=1x = 1 the slope is 12−10=212 - 10 = 2, and f(1)=5f(1) = 5, so the tangent there is y=5+2(x−1)y = 5 + 2(x - 1).

a product with a chain inside

g(x)=x2sin⁡(3x)g(x) = x^2 \sin(3x). the product rule first, with f=x2f = x^2 and the second factor sin⁡(3x)\sin(3x): 2xsin⁡(3x)+x2⋅(sin⁡3x)′2x \sin(3x) + x^2 \cdot (\sin 3x)'. the chain rule for that last slope: cos⁡(3x)⋅3\cos(3x) \cdot 3. so g′(x)=2xsin⁡(3x)+3x2cos⁡(3x)g'(x) = 2x \sin(3x) + 3x^2 \cos(3x).

a quotient

q(x)=xx2+1q(x) = \dfrac{x}{x^2 + 1}, so f=xf = x, g=x2+1g = x^2 + 1, f′=1f' = 1 and g′=2xg' = 2x:

q′(x)=1⋅(x2+1)−x⋅2x(x2+1)2=1−x2(x2+1)2\begin{aligned} q'(x) &= \frac{1 \cdot (x^2 + 1) - x \cdot 2x}{(x^2 + 1)^2} \\[6pt] &= \frac{1 - x^2}{(x^2 + 1)^2} \end{aligned}

the slope is 00 at x=±1x = \pm 1: a high point at (1,1/2)(1, 1/2) and a low one at (−1,−1/2)(-1, -1/2).

where a curve turns

f(x)=x3−3xf(x) = x^3 - 3x. f′=3x2−3=3(x−1)(x+1)f' = 3x^2 - 3 = 3(x - 1)(x + 1), zero at x=−1x = -1 and x=1x = 1. f′′=6xf'' = 6x: −6-6 at −1-1, so the curve bends down there, a high point at (−1,2)(-1, 2). 66 at 11, bending up, a low point at (1,−2)(1, -2). between them f′<0f' < 0 and the curve falls. drag the explore figure’s point across it.

a tangent line as a calculator

9.3\sqrt{9.3}: take f(x)=xf(x) = \sqrt{x} at a=9a = 9, where f(9)=3f(9) = 3 and f′(9)=1/(2⋅3)=1/6f'(9) = 1 / (2 \cdot 3) = 1/6. then 9.3≈3+0.3/6=3.05\sqrt{9.3} \approx 3 + 0.3 / 6 = 3.05. the true value is 3.04963.0496.

the key idea up close

the power rule from the limit

x2x^2 first. expand, subtract, divide:

(x+h)2=x2+2xh+h2(x+h)2−x2=2xh+h22xh+h2h=2x+h\begin{gathered} (x + h)^2 = x^2 + 2xh + h^2 \\[4pt] (x + h)^2 - x^2 = 2xh + h^2 \\[6pt] \frac{2xh + h^2}{h} = 2x + h \end{gathered}

the x2x^2 cancels, the hh divides out, and what’s left is 2x+h2x + h, which heads to 2x2x as h→0h \to 0. at x=1x = 1 that’s the movie’s 2+h2 + h.

then xnx^n. the binomial theorem expands (x+h)n(x + h)^n as xn+nxn−1h+(n2)xn−2h2+⋯+hnx^n + n x^{n-1} h + \binom{n}{2} x^{n-2} h^2 + \cdots + h^n, and every term after the second carries h2h^2 or more. call that tail h2rh^2 r, where rr is what’s left when h2h^2 is pulled out of it, a polynomial in hh:

(x+h)n−xn=nxn−1h+h2r(x+h)n−xnh=nxn−1+hr\begin{gathered} (x + h)^n - x^n = n x^{n-1} h + h^2 r \\[6pt] \frac{(x + h)^n - x^n}{h} = n x^{n-1} + h r \end{gathered}

rr stays finite as h→0h \to 0, so hrhr goes to 00, and (xn)′=nxn−1(x^n)' = n x^{n-1}. the point of the proof is bigger than the rule. the change f(x+h)−f(x)f(x + h) - f(x) is a pile of terms in hh, and the derivative is the coefficient of the one that’s linear in hh. everything with h2h^2 or more is lost in the quotient and the limit. that is also what the linear approximation says: f(x+h)=f(x)+f′(x) h+(terms with h2)f(x + h) = f(x) + f'(x)\,h + (\text{terms with } h^2).

in code

the forward difference is the secant’s slope from xx to x+hx + h. the central difference is the secant from x−hx - h to x+hx + h: the hh terms in its error cancel, so it’s off by about h2h^2 where the forward one is off by about hh. the run takes the slope of x3x^3 at 11, where the answer is 33, with hh from 10−110^{-1} down to 10−1610^{-16}.

python/math/derivative.py
"""numerical derivatives: the forward difference (f(x + h) - f(x)) / h and the central difference (f(x + h) - f(x - h)) / (2h), with a run that shows their error as h shrinks. it falls with h, then climbs again once rounding takes over, because f(x + h) - f(x) loses digits when the two values are close. run the file to print the table for x³ at 1, where the slope is 3."""

from __future__ import annotations

from collections.abc import Callable
from typing import NamedTuple

Fn = Callable[[float], float]


def forward(f: Fn, x: float, h: float) -> float:
    """Return the slope of the secant from x to x + h: (f(x + h) - f(x)) / h.

    Off by about h · f''(x) / 2, so the error shrinks like h.
    """
    return (f(x + h) - f(x)) / h


def central(f: Fn, x: float, h: float) -> float:
    """Return the slope of the secant from x - h to x + h: (f(x + h) - f(x - h)) / (2h).

    The h terms cancel, leaving about h² · f'''(x) / 6, so the error shrinks like h².
    """
    return (f(x + h) - f(x - h)) / (2 * h)


def cube(x: float) -> float:
    """Return x³ by two multiplies, the same two in any language, so the run matches the page's chart bit for bit."""
    return x * x * x


class Row(NamedTuple):
    """One step size, and how far each estimate lands from the exact slope."""

    h: float
    forward_error: float
    central_error: float


def error_table(f: Fn, x: float, exact: float, smallest: int = 16) -> list[Row]:
    """Return a row for h = 1e-1, 1e-2, ... down to 10**-smallest, each error measured against `exact`.

    Each h is parsed from its decimal spelling, so it's the same double everywhere: 10.0 ** -k would go through pow.
    """
    rows = []
    for k in range(1, smallest + 1):
        h = float(f"1e-{k}")
        rows.append(Row(h, abs(forward(f, x, h) - exact), abs(central(f, x, h) - exact)))
    return rows


def best(rows: list[Row], column: str) -> Row:
    """Return the row where `column` ("forward_error" or "central_error") is smallest: where that method bottoms out."""
    return min(rows, key=lambda r: getattr(r, column))


def main() -> None:
    """Print the table for x³ at 1, where the slope is 3, and where each method bottoms out."""
    rows = error_table(cube, 1.0, 3.0)
    print(f"{'h':>6}  {'forward error':>14}  {'central error':>14}")
    for r in rows:
        print(f"{r.h:>6.0e}  {r.forward_error:>14.2e}  {r.central_error:>14.2e}")
    for column in ("forward_error", "central_error"):
        r = best(rows, column)
        print(f"{column.split('_')[0]} bottoms out at h = {r.h:.0e}, off by {getattr(r, column):.1e}")


if __name__ == "__main__":
    main()

the forward difference is off by 0.310.31 at h=0.1h = 0.1, 0.0300.030 at 0.010.01 and 0.00300.0030 at 0.0010.001: a tenth of the error per decade, like 3h3h. it bottoms out at h=10−8h = 10^{-8}, off by 4.0×10−94.0 \times 10^{-9}, and then the error climbs back: 2.5×10−72.5 \times 10^{-7} at 10−910^{-9}, 2.7×10−42.7 \times 10^{-4} at 10−1210^{-12}, 0.330.33 at 10−1510^{-15}, and at 10−1610^{-16} the quotient reads 00, off by the whole 33. the central difference is off by 0.0100.010, then 1.0×10−41.0 \times 10^{-4}, then 1.0×10−61.0 \times 10^{-6}: a hundredth per decade, like h2h^2. it bottoms out at 10−610^{-6}, off by 2.5×10−112.5 \times 10^{-11}, and climbs the same way.

the climb is rounding. a double carries 53 bits, about 16 decimal digits,2 and f(x+h)−f(x)f(x + h) - f(x) throws most of them away: when two numbers share their first kk digits, their difference keeps only the rest. at h=10−8h = 10^{-8} the two values of x3x^3 agree to 8 digits, the difference has 8 left, and dividing by 10−810^{-8} turns the digits that were lost into an error around 10−810^{-8}. at 10−1610^{-16} nothing is left. the gap between 1.01.0 and the next double up is sys.float_info.epsilon, 2.2×10−162.2 \times 10^{-16},3 so 1+10−161 + 10^{-16} is 11, f(1+h)−f(1)f(1 + h) - f(1) is 00, and so is the quotient. the best hh sits where the two errors meet: about ε≈1.5×10−8\sqrt{\varepsilon} \approx 1.5 \times 10^{-8} for the forward difference and ε3≈6.1×10−6\sqrt[3]{\varepsilon} \approx 6.1 \times 10^{-6} for the central one.

10⁻¹10⁻⁴10⁻⁸10⁻¹²10⁻¹⁶10⁻¹²10⁻⁹10⁻⁶10⁻³1forwardcentralbest at h = 10⁻⁸best at h = 10⁻⁶herror

a chart of the error of two difference quotients for the slope of x³ at 1, against h from 10⁻¹ down to 10⁻¹⁶, both axes logarithmic. the forward difference, in cyan, is off by 0.31 at h = 0.1 and falls like h to 4.0 × 10⁻⁹ at h = 10⁻⁸, then climbs back as rounding takes over, to 3 at 10⁻¹⁶, where 1 + h is 1 and the quotient reads 0. the central difference, in amber, is off by 0.010 at 0.1 and falls like h² to 2.5 × 10⁻¹¹ at h = 10⁻⁶, then climbs the same way.

h shrinks to the right. each error falls, bottoms out, and climbs again once rounding takes over.

pitfalls

practice

  1. differentiate f(x)=3x4−5x2+7f(x) = 3x^4 - 5x^2 + 7, and give the slope at x=1x = 1.

    answer

    term by term with the power rule: f′(x)=12x3−10xf'(x) = 12x^3 - 10x. the 77 is a constant and drops out. at x=1x = 1: 12−10=212 - 10 = 2.

  2. find the slope of y=xy = \sqrt{x} at x=9x = 9, write the tangent line there, and use it to estimate 9.3\sqrt{9.3}.

    answer

    x=x1/2\sqrt{x} = x^{1/2}, so y′=12x−1/2=12xy' = \tfrac{1}{2} x^{-1/2} = \dfrac{1}{2\sqrt{x}}, and at 99 that’s 1/61/6. the tangent is y=3+16(x−9)y = 3 + \tfrac{1}{6}(x - 9). at x=9.3x = 9.3 it gives 3+0.3/6=3.053 + 0.3/6 = 3.05, against the true 3.04963.0496.

  3. differentiate (x2+1)5(x^2 + 1)^5, xexx e^x and cos⁡(5x)\cos(5x).

    answer

    chain rule: 5(x2+1)4⋅2x=10x(x2+1)45(x^2 + 1)^4 \cdot 2x = 10x(x^2 + 1)^4. product rule: 1⋅ex+x⋅ex=ex+xex1 \cdot e^x + x \cdot e^x = e^x + x e^x. chain rule again: −sin⁡(5x)⋅5=−5sin⁡(5x)-\sin(5x) \cdot 5 = -5\sin(5x).

  4. a particle’s position is s(t)=t3−6t2+9ts(t) = t^3 - 6t^2 + 9t meters after tt seconds. find its velocity, the times it’s at rest, and its acceleration at those times.

    answer

    v(t)=s′(t)=3t2−12t+9=3(t−1)(t−3)v(t) = s'(t) = 3t^2 - 12t + 9 = 3(t - 1)(t - 3), which is 00 at t=1t = 1 and t=3t = 3: the particle stops at s(1)=4s(1) = 4 m and again at s(3)=0s(3) = 0 m. a(t)=v′(t)=6t−12a(t) = v'(t) = 6t - 12, so a(1)=−6a(1) = -6 and a(3)=6a(3) = 6 m/s². at t=1t = 1 it’s being pushed back toward the start, and between the two stops it moves backwards: v(2)=−3v(2) = -3.

  5. f(x)=x2−4x+1f(x) = x^2 - 4x + 1. where is its lowest point, and how do you know it’s the lowest?

    answer

    f′(x)=2x−4f'(x) = 2x - 4, which is 00 at x=2x = 2, so that’s the only flat point. f′′(x)=2>0f''(x) = 2 > 0: the curve bends up there, a low point. f(2)=4−8+1=−3f(2) = 4 - 8 + 1 = -3, so the lowest point is (2,−3)(2, -3). a parabola that opens up has one low point and no high point.

  6. estimate e0.05e^{0.05} with a tangent line. then compute the forward and central differences of x3x^3 at 11 with h=0.1h = 0.1, and say why one is closer.

    answer

    f(x)=exf(x) = e^x at a=0a = 0: f(0)=1f(0) = 1 and f′(0)=1f'(0) = 1, so e0.05≈1+0.05=1.05e^{0.05} \approx 1 + 0.05 = 1.05, against 1.05131.0513.

    forward: (1.13−1)/0.1=3.31(1.1^3 - 1) / 0.1 = 3.31. central: (1.13−0.93)/0.2=3.01(1.1^3 - 0.9^3) / 0.2 = 3.01. the exact slope is 33. the forward quotient is 3+3h+h23 + 3h + h^2, off by about 3h3h, and the central one is 3+h23 + h^2: the hh terms from the two sides cancel, so only h2=0.01h^2 = 0.01 is left.

sources

  1. ken perlin, improving noise, acm transactions on graphics 21(3), 2002, doi 10.1145/566654.566636 (opens in a new tab), open copy on his site (opens in a new tab): the cubic interpolant 3t² − 2t³ has the second derivative 6 − 12t, which isn’t zero at t = 0 or t = 1 and puts second order discontinuities across the faces of adjoining cells, so it’s replaced by 6t⁵ − 15t⁴ + 10t³, whose first and second derivatives are zero at both ends. ↩

  2. python’s tutorial, floating-point arithmetic: issues and limitations (opens in a new tab): almost all platforms map python floats to ieee 754 binary64 doubles, which carry 53 bits of precision, and each operation’s rounding error is about 1 part in 2⁵³ at most. ↩

  3. python’s sys.float_info (opens in a new tab) docs: epsilon is the difference between 1.0 and the least float above it, c’s DBL_EPSILON, and dig, the most decimal digits a float represents faithfully, is 15. ↩