---
title: Functions of several variables and partial derivatives
heading: Slopes on a surface, one direction at a time
eyebrow: A9 · Lesson 4 · Partial derivatives
xp: 40
---

::: hook
The voltage in a circuit lives on a few nodes, but the voltage in space around a charged wire is different at every point: it depends on where you stand, in two or three directions at once. A function of several variables is a landscape, and asking "how steep is it?" gets a different answer depending on which way you face. Partial derivatives answer it one direction at a time.

::: play
- The map shows a hill, $h(x, y) = 6 - \tfrac12x^2 - y^2$ (in meters), with contour lines at equal heights. The dot is where you stand.
- The two short arrows point in the $+x$ and $+y$ directions from where you stand. The readouts give the slope you'd feel walking each way.
- Move $x_0$ and $y_0$. Where are the contour lines close together? What does that mean about the slope there?
- The graph below is a slice through the hill along the line $y = y_0$, with the tangent at your spot. Its slope is the readout $\partial h/\partial x$.
:::
:::

```sim plot
view: flow
x: x = -3..3 m
y: y = -2.5..2.5 m
slider: x0 = -2.5..2.5 step 0.1 = 1.5 m
slider: y0 = -2..2 step 0.1 = 0.5 m
shade: 6 - x^2/2 - y^2 | contours: 12 | scale: 6
dot: x0, y0 | label: you
vec: x0, y0, 0.8, 0 | color: ch3
vec: x0, y0, 0, 0.8 | color: ch4
readout: height h = 6 - x0^2/2 - y0^2 m
readout: ∂h/∂x = -x0
readout: ∂h/∂y = -2*y0
```

```sim plot
view: graph
x: x = -3..3 m
y: h = -2..7 m
slider: x0 = -2.5..2.5 step 0.1 = 1.5 m
slider: y0 = -2..2 step 0.1 = 0.5 m
plot: 6 - x^2/2 - y0^2 | label: slice at y = y0
plot: 6 - x0^2/2 - y0^2 - x0*(x - x0) | dashed | color: ch2 | label: tangent
point: x0, 6 - x0^2/2 - y0^2
readout: slope of the slice = -x0
```

::: predict
## You stand at $(1, 1)$ on this hill. Is it steeper to walk in the $x$ direction or in the $y$ direction?

- [ ] The $x$ direction
- [x] The $y$ direction
- [ ] They're equally steep
- [ ] It's flat both ways

::: reveal
The $y$ direction. $\partial h/\partial x = -x = -1$ there, but $\partial h/\partial y = -2y = -2$, twice as steep. The hill falls off faster in $y$, which you can see on the map: the contour lines are closer together in the $y$ direction.
:::
:::

::: nameit
## Partial derivatives

A **function of two variables** $f(x, y)$ gives a number at every point of a plane: a height, a temperature, a voltage. You can draw it as a surface, or as a map with **contour lines** joining points of equal value (the lines on a hiking map). Where contours crowd together, the function changes quickly.

**The partial derivative** with respect to $x$ is the ordinary derivative you get by holding $y$ fixed:

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

Geometrically it's the slope of the slice through the surface along the $x$ direction. $\partial f/\partial y$ is the same with $x$ held fixed. The curly $\partial$ is a reminder that the other variables are frozen.

**Working them out** uses the rules from A5, treating every other variable as a constant:

$$f = x^2y^3 + 5x \qquad \frac{\partial f}{\partial x} = 2xy^3 + 5 \qquad \frac{\partial f}{\partial y} = 3x^2y^2$$

**In engineering.** The voltage around charges is $V(x, y, z)$, and $-\partial V/\partial x$ is the electric field's $x$ part (lesson 9). A transistor's current depends on two voltages, and its small-signal parameters are partial derivatives: the transconductance $g_m = \partial I_C/\partial V_{BE}$ with $V_{CE}$ held fixed.

**Second partials** work the same way. $\partial^2f/\partial x^2$ is the bend along $x$, and the mixed partials $\partial^2f/\partial x\,\partial y$ and $\partial^2f/\partial y\,\partial x$ come out equal for any smooth function, which saves work and checks it.

**Small changes.** Moving a little in both directions changes $f$ by about

$$\Delta f \approx \frac{\partial f}{\partial x}\Delta x + \frac{\partial f}{\partial y}\Delta y$$

the two-variable version of A6's linearization. It's how tolerances in two components combine into the tolerance of a result.
:::

::: example
## Find the partial derivatives of $f = x^2y + 3y$ at $(2, 1)$.

::: solution
1. **Hold $y$ fixed.**
   $$\begin{aligned} f_x &= 2xy \\ &= 4 \end{aligned}$$
2. **Hold $x$ fixed.**
   $$\begin{aligned} f_y &= x^2 + 3 \\ &= 7 \end{aligned}$$
3. **Read them.** Near $(2, 1)$, $f$ rises 4 units per unit step in $x$ and 7 per unit step in $y$.

**Answer:** $f_x = 4$ and $f_y = 7$ at $(2, 1)$.
:::
:::

::: example
## A hill's height is $h = 100 - x^2 - 2y^2$ meters ($x$, $y$ in km). How steep is it at $(3, 2)$ in each direction?

::: solution
1. **Slope in $x$.**
   $$\begin{aligned} h_x &= -2x \\ &= -6\ \text{m per km} \end{aligned}$$
2. **Slope in $y$.**
   $$\begin{aligned} h_y &= -4y \\ &= -8\ \text{m per km} \end{aligned}$$
3. **Read them as directions.** Walking east you descend 6 m per km; walking north, 8 m per km.

**Answer:** the hill drops 6 m per km going east and 8 m per km going north.
:::
:::

::: example
## Find $f_x$, $f_y$ and $f_{xy}$ for $f = e^{-x}\sin y$ at $(0, \pi/4)$.

::: solution
1. **First partials.** At $(0, \pi/4)$:
   $$\begin{aligned} f_x &= -e^{-x}\sin y \\ &= -0.707 \\ f_y &= e^{-x}\cos y \\ &= 0.707 \end{aligned}$$
2. **Mixed partial one way.** Differentiate $f_x$ with respect to $y$:
   $$\begin{aligned} f_{xy} &= -e^{-x}\cos y \\ &= -0.707 \end{aligned}$$
3. **Mixed partial the other way.** Differentiating $f_y$ with respect to $x$ gives the same:
   $$f_{yx} = -e^{-x}\cos y$$
   The mixed partials agree, as they do for every function whose second partials are continuous (Clairaut's theorem).
4. **Check that it's harmonic.**
   $$\begin{aligned} f_{xx} + f_{yy} &= e^{-x}\sin y - e^{-x}\sin y \\ &= 0 \end{aligned}$$

**Answer:** $f_x = -0.707$, $f_y = 0.707$ and $f_{xy} = -0.707$ at $(0, \pi/4)$.
:::
:::

::: check
kind: expression
given: a = 2..9 int; b = 2..5 int
answer: 2*a*x*y^b
vars: x = 0.5..2, y = 0.5..2

## Find $\dfrac{\partial}{\partial x}\left(\given{a}x^2y^{\given{b}}\right)$.

::: right
Right. Hold $y$ fixed: $y^{\given{b}}$ is just a constant factor, and $\frac{d}{dx}x^2 = 2x$.
:::

::: misses
- [a*b*x^2*y^(b - 1)] That's the derivative with respect to y.
- [2*a*x] Keep $y^{\given{b}}$: it's a constant factor, not a term that drops out.
- [any] Not yet. Treat $y$ as a constant and differentiate with respect to $x$.
:::
:::

::: check
given: x0 = -3 | -1 | 1 | 3; y0 = -2 | 2; c = 2..5 int
answer: 2*c*y0
tolerance: 0.5%

## For $f(x, y) = x^2 + \given{c}y^2$, what is $\partial f/\partial y$ at $(\given{x0}, \given{y0})$?

::: right
Right. $\partial f/\partial y = 2\cdot\given{c}\,y$, which is {answer} there. The $x^2$ term doesn't change with $y$, so it drops out.
:::

::: misses
- [2*x0] That's $\partial f/\partial x$.
- [2*x0 + 2*c*y0] Only $y$ is changing: the $x^2$ term has zero partial derivative with respect to $y$.
- [x0^2 + c*y0^2] That's the value of f. Differentiate first.
- [any] Not yet. Hold $x$ fixed and differentiate with respect to $y$.
:::
:::

::: check
given: dV1 = 0.1 | 0.2; dV2 = 0.3 | 0.5
answer: 3*dV1 - 2*dV2
unit: V
tolerance: 0.5%

## A circuit's output is $V_o = 3V_1 - 2V_2$. If $V_1$ rises by {dV1} V and $V_2$ by {dV2} V, how much does $V_o$ change?

::: right
Right. $\Delta V_o = \frac{\partial V_o}{\partial V_1}\Delta V_1 + \frac{\partial V_o}{\partial V_2}\Delta V_2 = 3(\given{dV1}) - 2(\given{dV2})$ = {answer}.
:::

::: misses
- [3*dV1 + 2*dV2] The partial derivative with respect to $V_2$ is −2.
- [dV1 - dV2] Weight each change by its partial derivative.
- [any] Not yet. Use $\Delta V_o \approx \frac{\partial V_o}{\partial V_1}\Delta V_1 + \frac{\partial V_o}{\partial V_2}\Delta V_2$.
:::
:::

::: check
kind: choice

## On a contour map, the lines are packed tightly together in one area. What does that tell you?

- [ ] The function is large there
- [x] The function changes quickly there
- [ ] The function is zero there
- [ ] The function is flat there

::: right
Right. Each line is one step in value, so lines close together mean you cross many steps in a short distance: a steep slope.
:::

::: misses
- [1] The spacing shows how fast the value changes, not how big it is.
- [3] Spacing shows the slope. Zero could be anywhere.
- [4] Flat ground has contours far apart, or none at all.
:::
:::

::: check
kind: expression
given: a = 2..6 int
answer: a*y*cos(a*x*y)
vars: x = -1..1, y = -1..1

## Find $\dfrac{\partial}{\partial x}\sin(\given{a}xy)$.

::: right
Right. The chain rule, with $y$ held constant: the inside $\given{a}xy$ has $x$-derivative $\given{a}y$.
:::

::: misses
- [cos(a*x*y)] Multiply by the derivative of the inside, $\given{a}y$.
- [a*x*cos(a*x*y)] That's the partial with respect to y.
- [any] Not yet. Use the chain rule, treating $y$ as a constant.
:::
:::

::: check
kind: parts
given: a = 2 | 3; x = 1 | 2; y = 1 | 3

## Take $f = \given{a}x^2y + xy^3$ at $(\given{x}, \given{y})$.

::: part
answer: 2*a*x*y + y^3
tolerance: 0.5%

### What is $f_x$?

::: misses
- [any] Treat $y$ as a constant.
:::
:::

::: part
answer: 2*a*x + 3*y^2
tolerance: 0.5%

### What is $f_{xy}$?

::: misses
- [any] Differentiate $f_x$ with respect to $y$.
:::
:::
:::

::: check
kind: derivation
vars: x = 0..2, y = 0..3

## Take $f = e^{-x}\sin y$.

::: step
answer: exp(-x)*sin(y)

### What is $f_{xx}$?
:::

::: step
answer: -exp(-x)*sin(y)

### What is $f_{yy}$?
:::

::: right
Right. They cancel, so $f_{xx} + f_{yy} = 0$: $f$ is harmonic.
:::
:::

::: explain
## What does $\partial f/\partial x$ measure, and why do we have to hold the other variables fixed to define it?

::: model
It measures how fast $f$ changes as you move in the $x$ direction only: the slope of the slice through the surface along $x$. A function of several variables has a different slope in every direction you could move, so "the slope" isn't one number. Fixing all the other variables picks out a single direction, along $x$, and turns $f$ into an ordinary function of one variable whose derivative we already know how to take.
:::
:::

::: practice

::: check
kind: expression
given: a = 2..9 int; b = 2..9 int
answer: 3*a*x^2*y^2
vars: x = 0.5..2, y = 0.5..2

## Find $\dfrac{\partial}{\partial y}\left(\given{a}x^2y^3 + \given{b}x\right)$.

::: misses
- [2*a*x*y^3 + b] That's $\partial/\partial x$.
- [3*a*x^2*y^2 + b] The $\given{b}x$ term doesn't depend on y.
- [any] Hold $x$ fixed.
:::
:::

::: check
given: x0 = 1 | 3; y0 = 2 | 4; a = 2..4 int
answer: a*y0*exp(a*x0*y0/10)/10
tolerance: 0.5%

## For $f = e^{\given{a}xy/10}$, what is $\partial f/\partial x$ at $(\given{x0}, \given{y0})$?

::: misses
- [exp(a*x0*y0/10)] Multiply by the inside's x-derivative, $\given{a}y/10$.
- [a*x0*exp(a*x0*y0/10)/10] That's $\partial f/\partial y$.
- [any] Chain rule with y held fixed.
:::
:::

::: check
given: R = 2 | 4 | 6 | 8; I = 3 | 5 | 7 | 9; dR = 0.1 | 0.3; dI = 0.2 | 0.4
answer: I*dR + R*dI
unit: V
tolerance: 0.5%

## $V = IR$, with I = {I} A and R = {R} Ω. If R rises by {dR} Ω and I by {dI} A, about how much does V rise?

::: misses
- [dR*dI] Use the partial derivatives: $\partial V/\partial R = I$ and $\partial V/\partial I = R$.
- [R*dR + I*dI] Each change is weighted by the other factor.
- [any] $\Delta V \approx I\,\Delta R + R\,\Delta I$.
:::
:::
:::
