---
title: The derivative as a function
heading: The slope at every point makes a new curve
eyebrow: A5 · Lesson 9 · The derivative as a function
xp: 40
---

::: hook
The slope of a curve is different at every point. Record it at every point and you get a second curve, the derivative, which says how fast the first one is changing everywhere at once. Reading one curve from the other is a skill engineers use constantly: a voltage from its current, a position from its speed.

::: play
- The top curve is $f(x) = x^3 - 3x$; the dashed line is its tangent at $x_0$. The second curve records the tangent's slope at every $x$: that's $f'(x)$.
- Slide $x_0$ along. Where the tangent is flat, where does the slope curve sit?
- Where $f$ is climbing, is $f'$ above or below zero?
:::
:::

```sim plot
view: graph
x: x = -2.5..2.5
y: y = -6..10
slider: x0 = -2.5..2.5 step 0.05 = 0.5
plot: x^3 - 3*x | label: f(x)
plot: 3*x^2 - 3 | color: ch2 | label: f′(x)
plot: x0^3 - 3*x0 + (3*x0^2 - 3)*(x - x0) | dashed | color: ch3
point: x0, x0^3 - 3*x0
point: x0, 3*x0^2 - 3 | color: ch2
readout: slope at x0 = 3*x0^2 - 3
```

::: predict
## Where does the slope curve $f'(x)$ cross zero?

- [ ] Where $f(x)$ crosses zero
- [x] Where $f(x)$ has its peak and its dip
- [ ] Where $f(x)$ is steepest
- [ ] Nowhere

::: reveal
At the peak and the dip, $x = \pm 1$. There the tangent is flat, so the slope is zero. Between them $f$ falls, so $f'$ is negative; outside them $f$ climbs, so $f'$ is positive. That's how you find the highest and lowest points of a curve: solve $f'(x) = 0$, the idea behind lesson 27.
:::
:::

::: nameit
## The derivative function

The **derivative** of $f$ is the function $f'$ whose value at each $x$ is the slope of $f$ there:

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

Other ways to write it: $\dfrac{df}{dx}$, $\dfrac{dy}{dx}$ when $y = f(x)$, and $\dfrac{dv}{dt}$ for a voltage changing in time. Engineers and physicists often write a dot for a time derivative: $\dot v = dv/dt$.

**The power rule.** Working the limit for $x^2$ gave $2x$, and for $x^3$ gave $3x^2$. The pattern holds for every power:

$$\frac{d}{dx}x^n = n\,x^{n-1}$$

for any $n$, including negative and fractional ones: $\frac{d}{dx}\frac1x = -\frac{1}{x^2}$ and $\frac{d}{dx}\sqrt{x} = \frac{1}{2\sqrt x}$.

**Two more rules** follow straight from the definition: constants scale through, $(cf)' = cf'$, and sums differentiate term by term, $(f + g)' = f' + g'$. A constant on its own has slope zero. So any polynomial differentiates term by term: $\frac{d}{dx}(x^3 - 3x) = 3x^2 - 3$.

**Reading one graph from the other:**

| Where $f$ is... | $f'$ is... |
|---|---|
| climbing | positive |
| falling | negative |
| flat (peak, dip) | zero |
| steepest | at its largest size |

**The second derivative** $f''$ is the derivative of $f'$: how fast the slope changes, which shows as the curve's bend. For a position it's acceleration. $f''(x) > 0$ means the curve bends upward, like a cup.
:::

::: example
## Differentiate $f(x) = 4x^3 - 2x^2 + 7$ and find the slope at $x = 1$.

::: solution
1. **Differentiate term by term.**
   $$f'(x) = 12x^2 - 4x$$
2. **Evaluate at $x = 1$.**
   $$\begin{aligned} f'(1) &= 12 - 4 \\ &= 8 \end{aligned}$$

**Answer:** $f'(x) = 12x^2 - 4x$, and the slope at $x = 1$ is 8.
:::
:::

::: example
## Find the derivative of $f(x) = 1/x$ from the definition.

::: solution
1. **Write the definition.**
   $$f'(x) = \lim_{h \to 0}\frac{\frac{1}{x + h} - \frac{1}{x}}{h}$$
2. **Combine the fractions on top.**
   $$\begin{aligned} f'(x) &= \lim_{h \to 0}\frac{x - (x + h)}{h\,x(x + h)} \\ &= \lim_{h \to 0}\frac{-1}{x(x + h)} \end{aligned}$$
3. **Let $h \to 0$.**
   $$f'(x) = -\frac{1}{x^2}$$
4. **Check.** The same answer as the power rule with $n = -1$: $-1 \cdot x^{-2}$.

**Answer:** $f'(x) = -\dfrac{1}{x^2}$.
:::
:::

::: example
## Differentiate $\sqrt{x}$ from the definition, and find its slope at $x = 4$.

::: solution
1. **Write the definition.**
   $$f'(x) = \lim_{h \to 0}\frac{\sqrt{x + h} - \sqrt{x}}{h}$$
2. **Remove the $0/0$.** Multiply the top and bottom by $\sqrt{x + h} + \sqrt{x}$:
   $$f'(x) = \lim_{h \to 0}\frac{(x + h) - x}{h(\sqrt{x + h} + \sqrt{x})}$$
3. **Let $h \to 0$.**
   $$f'(x) = \frac{1}{2\sqrt{x}}$$
4. **Slope at $x = 4$.**
   $$\begin{aligned} f'(4) &= \frac{1}{2 \times 2} \\ &= 0.25 \end{aligned}$$

**Answer:** the derivative of $\sqrt{x}$ is $\dfrac{1}{2\sqrt{x}}$, and its slope at $x = 4$ is 0.25.
:::
:::

::: check
kind: expression
given: a = 2..9 int; b = 2..9 int; c = 1..9 int
answer: 3*a*x^2 - 2*b*x
vars: x = -3..3

## Differentiate $f(x) = \given{a}x^3 - \given{b}x^2 + \given{c}$.

::: right
Right. Term by term: $3\cdot\given{a}x^2 - 2\cdot\given{b}x$, and the constant {c} has slope zero.
:::

::: misses
- [3*a*x^2 - 2*b*x + c] The constant term has slope zero; it drops out.
- [a*x^2 - b*x] The power rule brings the exponent down as a factor: $3x^2$ from $x^3$, $2x$ from $x^2$.
- [3*a*x^3 - 2*b*x^2] Bring the exponent down and also lower it by one.
- [any] Not yet. Use $\frac{d}{dx}x^n = nx^{n-1}$ on each term.
:::
:::

::: check
given: a = 2 | 3 | 4 | 5
answer: -1/a^2
tolerance: 0.5%

## What is the slope of $y = 1/x$ at $x = \given{a}$?

::: right
Right. $\frac{d}{dx}x^{-1} = -x^{-2}$, which is {answer} at $x = \given{a}$.
:::

::: misses
- [1/a^2] The slope is negative: $1/x$ falls as $x$ grows.
- [-1/a] Bring down the −1 and lower the exponent to −2: $-1/x^2$.
- [any] Not yet. Write $1/x$ as $x^{-1}$ and use the power rule.
:::
:::

::: check
kind: choice

## A capacitor's voltage climbs from 0 and levels off at 5 V. What does the graph of its rate of change $dv/dt$ look like?

- [ ] Climbing from 0 to a steady value
- [x] Starting high and falling toward zero
- [ ] Constant
- [ ] Negative throughout

::: right
Right. The voltage climbs fastest at the start and flattens out, so its slope starts at its largest and dies away to zero.
:::

::: misses
- [1] That's the shape of the voltage itself. Its slope is biggest where it's steepest, at the start.
- [3] A constant slope would be a straight line. This curve flattens out.
- [4] The voltage is rising throughout, so the slope is positive.
:::
:::

::: check
given: a = -3 | -2 | 2 | 3
answer: 6*a
tolerance: 0.5%

## What is $f''(\given{a})$ for $f(x) = x^3 - 3x$?

::: right
Right. $f' = 3x^2 - 3$, then $f'' = 6x$, which is {answer} at {a}.
:::

::: misses
- [3*a^2 - 3] That's $f'(\given{a})$. Differentiate once more.
- [6] Differentiate $3x^2$: you get $6x$, then put $x = \given{a}$ in.
- [any] Not yet. Differentiate twice, then evaluate.
:::
:::

::: check
kind: parts
given: a = 2 | 3 | -1; b = 1 | 4; x0 = 1 | 2

## Let $f(x) = \given{a}x^3 + \given{b}x$.

::: part
answer: 3*a*x0^2 + b
tolerance: 0.5%

### What is $f'(\given{x0})$?

::: misses
- [3*a*x0^2] The $\given{b}x$ term has slope {b}.
- [any] $f'(x) = 3ax^2 + b$.
:::
:::

::: part
answer: 6*a*x0
tolerance: 0.5%

### What is $f''(\given{x0})$?

::: misses
- [any] Differentiate $f'$ again.
:::
:::

::: part
answer: -2*a*x0^3
tolerance: 0.5%

### The tangent line at $x$ = {x0} is $y = f'(x_0)(x - x_0) + f(x_0)$. Where does it cross the $y$ axis?

::: misses
- [a*x0^3 + b*x0] That's $f(x_0)$, the height at the point itself.
- [any] Put $x = 0$ in the tangent line.
:::
:::
:::

::: check
kind: derivation
vars: x = 0.5..3, h = 0.01..0.2

## Differentiate $1/x^2$ from the definition.

::: step
answer: -(2*x + h)/(x^2*(x + h)^2)

### Simplify $\dfrac{1/(x + h)^2 - 1/x^2}{h}$ to a single fraction.
:::

::: step
answer: -2/x^3

### Let $h \to 0$.
:::

::: right
Right. The slope of $x^{-2}$ is $-2x^{-3}$, as the power rule says.
:::
:::

::: explain
## How can you tell, from the graph of $f$ alone, where $f'$ is positive, negative and zero?

::: model
$f'(x)$ is the slope of $f$ at $x$. Wherever the graph of $f$ climbs from left to right, its slope is positive, so $f'$ is above zero there; wherever it falls, $f'$ is below zero. At the tops of hills and the bottoms of valleys the graph is momentarily flat, so $f'$ is zero, and where the graph is steepest, $f'$ is at its largest size.
:::
:::

::: practice

::: check
kind: expression
given: n = 3..9 int; a = 2..9 int
answer: a*n*x^(n - 1)
vars: x = 0.5..2

## Differentiate $\given{a}x^{\given{n}}$.

::: misses
- [a*x^(n - 1)] Bring the exponent down as a factor too.
- [a*n*x^n] Lower the exponent by one.
- [any] Use $\frac{d}{dx}x^n = nx^{n-1}$.
:::
:::

::: check
kind: expression
given: k = 2..9 int
answer: k/(2*sqrt(x))
vars: x = 0.5..4

## Differentiate $\given{k}\sqrt{x}$.

::: misses
- [k*sqrt(x)/2] Lower the exponent: $x^{1/2}$ becomes $\tfrac12 x^{-1/2}$.
- [any] Write $\sqrt x = x^{1/2}$ and use the power rule; the constant stays in front.
:::
:::

::: check
given: a = 2..9 int; b = 1 | 3 | 5 | 7 | 9; x0 = -2 | 2
answer: 2*a*x0 + b
tolerance: 0.5%

## What is the slope of $\given{a}x^2 + \given{b}x$ at $x = \given{x0}$?

::: misses
- [a*x0^2 + b*x0] That's the value. Differentiate first.
- [any] The derivative is $2ax + b$; evaluate it at {x0}.
:::
:::

::: check
kind: expression
given: a = 2..6 int; b = 2..9 int
answer: 6*a*x
vars: x = -3..3

## Find the second derivative of $\given{a}x^3 + \given{b}x$.

::: misses
- [3*a*x^2 + b] That's the first derivative. Differentiate again.
- [any] Differentiate twice.
:::
:::
:::
