Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 68 ยท Multivariable Calculus

Partial Derivatives

Learn partial derivatives of functions of several variables: slopes along each axis, higher-order and mixed partials, the chain rule, and 3D surface plots.

Most real quantities depend on more than one input. The temperature of a metal plate depends on the position (x, y). The pressure of a gas depends on volume and temperature. The cost of a model depends on dozens of parameters. A function of several variables, written f(x, y) or f(x, y, z), takes several numbers and returns one.

To study how such a function changes, we use a simple trick: change one variable at a time and freeze the others. The resulting rate of change is a partial derivative. If you are comfortable with ordinary derivatives from Differentiation Rules, you already know almost everything you need. This lesson shows the notation, the geometry, higher-order derivatives, and the multivariable chain rule.

Functions of two variables as surfaces

The graph of z = f(x, y) is a surface above the xy-plane. For each point (x, y) the height of the surface is f(x, y). A good way to build intuition is to plot one.

Python A surface and its contour map

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

np.meshgrid builds a grid of x and y values so that a formula can be evaluated at every grid point at once. The surface here is a saddle: it curves up along one direction and down along another. The contour plot shows the same function as a map, with each line joining points of equal height. You will meet this shape again in Optimization in Several Variables.

What a partial derivative means

For f(x, y), the partial derivative with respect to x is

f_x = df/dx = limit as h goes to 0 of ( f(x + h, y) - f(x, y) ) / h,

and the partial derivative with respect to y is the same with h added to y. The curly symbol โˆ‚ (written โˆ‚f/โˆ‚x on paper) tells the reader that other variables exist. In code and plain text, f_x or diff(f, x) is fine.

The recipe: to find โˆ‚f/โˆ‚x, treat every other variable as a constant and differentiate with respect to x using the usual rules.

For f(x, y) = x**2 * y + y**3:

  • f_x = 2*x*y (the y is just a constant coefficient, and y**3 vanishes).
  • f_y = x**2 + 3*y**2 (now x**2 is the constant coefficient).

Geometrically, f_x at a point is the slope of the surface in the x direction: slice the surface with a vertical plane parallel to the xz-plane and measure the slope of the resulting curve.

flowchart LR
    F["f(x, y)"] -->|"freeze y, vary x"| FX["f_x : slope along x"]
    F -->|"freeze x, vary y"| FY["f_y : slope along y"]
    FX --> G["together they form<br/>the gradient (f_x, f_y)"]
    FY --> G

Each partial derivative is an ordinary derivative along one axis; together they describe the local tilt of the surface.

Python Partial derivatives with sympy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For g, the chain rule from The Chain Rule still works inside each partial: d/dx sin(x*y) = y*cos(x*y), because the derivative of the inside x*y with respect to x is y.

Checking partial derivatives numerically

The definition suggests a numeric check: nudge one variable by a tiny h and divide the change in f by h. A central difference ( f(x+h) - f(x-h) ) / (2h) is more accurate than the forward difference. This is also how software checks derivative code that is written by hand, which becomes vital in Gradient and Directional Derivatives.

Python Finite-difference partials versus exact

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that a smaller h helps at first: the error drops as h shrinks. Be careful, though: when h becomes extremely tiny (like 1e-13), floating-point round-off takes over and the error grows again. Floating-Point Error and Conditioning explains why.

Higher-order and mixed partials

You can differentiate a partial derivative again. With two variables there are four second derivatives:

  • f_xx: differentiate with respect to x twice.
  • f_yy: differentiate with respect to y twice.
  • f_xy: differentiate with respect to x, then y (this notation reads left to right).
  • f_yx: differentiate with respect to y, then x.

The last two are the mixed partials. A remarkable fact, Clairaut's theorem (also called the symmetry of second derivatives), says that if the second partials are continuous near a point, then f_xy = f_yx there. For almost every function you will meet in engineering, the order does not matter.

Second derivatives measure curvature, and they appear in many physical laws. For example, a steady-state temperature u(x, y) in a plate with no heat sources satisfies Laplace's equation: u_xx + u_yy = 0.

Python Second derivatives, mixed partials and Laplace's equation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first two functions are harmonic (their Laplacian is zero), so they are possible steady temperature patterns. The third one, x**2 + y**2, has Laplacian 4, so it would need a heat source to exist.

The chain rule for several variables

Suppose z = f(x, y) where x and y themselves depend on a parameter t, for example along a moving path. Then z is really a function of t, and

dz/dt = f_x * dx/dt + f_y * dy/dt.

Each input contributes: how sensitive z is to that input, times how fast that input changes. If x and y depend on two parameters s and t, you use the same sum with partials: โˆ‚z/โˆ‚s = f_x * โˆ‚x/โˆ‚s + f_y * โˆ‚y/โˆ‚s.

For example, let a particle move on the path x = cos t, y = sin t through a field f(x, y) = x**2 + 3*x*y. The value of f along the path changes at the rate given by the formula above.

Python Chain rule along a path

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both ways give the same answer, and that agreement is a good test whenever you are unsure of your setup. The chain-rule form wins when the substitution would be messy or when f is only known numerically.

The symbol d and the symbol โˆ‚ are not interchangeable. Write dz/dt only when z depends on a single variable t. If z depends on several variables, use โˆ‚z/โˆ‚t for the change in t with the others held fixed.

Why it matters

Partial derivatives are the building blocks of everything multivariable. Collected into a vector, they form the gradient (next lesson), which points in the direction of fastest increase. Set them to zero, and you find the peaks and valleys of a surface. Machine-learning models, heat flow, fluid motion and structural stress all rest on them.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. To compute the partial derivative of f(x, y) with respect to x, what do you do with y?

    A partial derivative changes one variable only. Every other variable is held fixed, so it behaves like a constant in the differentiation rules.
  2. 2. If f(x, y) = x^2 * y + y^3, what is f_y?

    With x held constant, the derivative of x^2 * y with respect to y is x^2, and the derivative of y^3 is 3y^2.
  3. 3. What does Clairaut's theorem say about mixed partials?

    For functions with continuous second partials, the order of differentiation does not matter, so f_xy = f_yx.
  4. 4. For z = f(x, y) with x = x(t) and y = y(t), what is dz/dt?

    Each variable contributes its sensitivity times its rate of change; adding the contributions gives the total derivative.
  5. 5. Which function satisfies Laplace's equation u_xx + u_yy = 0?

    For x^2 - y^2, u_xx = 2 and u_yy = -2, which add to 0. For x^2 + y^2 they add to 4.

Summary

  • A function of two variables is a surface z = f(x, y); contour lines join points of equal height.
  • A partial derivative differentiates with respect to one variable while treating the others as constants.
  • f_x and f_y are the slopes of the surface along the x and y directions; central differences check them numerically.
  • Second partials include the mixed ones, and f_xy = f_yx when they are continuous (Clairaut).
  • The chain rule adds up contributions: dz/dt = f_x x'(t) + f_y y'(t).
  • sympy.diff(f, x, y) and np.meshgrid cover most of the code you need.

Next: Gradient and Directional Derivatives.