Open any fluid simulator and look at what it stores: a pressure value in every cell, a temperature in every cell, a density in every cell. Each of these is a number that depends on where you are (and usually when). In Calc I and II every function had one input, . A temperature field has four. This lesson is your first step into multivariable calculus, the language in which every law of fluid motion is written. The good news is that the first big idea, the partial derivative, is an ordinary derivative in disguise: freeze all inputs but one and take the slope you already know how to take. In 1.1 Vectors, Linear Combinations & Span we put a vector at every grid cell. Now we put a number at every point and ask how fast it changes.
Transcript
- Welcome to Module Two. Until now, every function you have differentiated had one input. Out in the physical world, almost nothing does.
- Think of the temperature across a metal plate, or the pressure around a wing. At every point x comma y there is one number. A function like that, f of x and y, is called a scalar field.
- The first way to see it is a heatmap. Color each point by its value: bright means high, dark means low. This is exactly how a fluid simulator shows you a pressure field.
- The second way is a contour map. Connect all the points that share the same value, and you get level curves, just like the contour lines on a hiking map.
- Where the contours crowd together, the function changes quickly. Where they spread out, the landscape is nearly flat.
- The third view uses a third dimension. Make the value a height, z equals f of x and y, and the field becomes a surface: a landscape of hills and valleys.
- Every contour line is a horizontal slice of this landscape at one fixed height. Same function, three pictures, and you should get used to switching between them.
- Now the big question of calculus: how fast does f change? With two inputs, the answer depends on which way you walk.
- So we do the simplest thing possible. Freeze y at one value, and walk only in the x direction. That means slicing the surface with the vertical plane y equals a constant.
- The slice cuts out an ordinary curve: f as a function of x alone. And an ordinary curve has an ordinary slope.
- That slope is the partial derivative of f with respect to x. Walk along the slice and watch the tangent line tilt. Uphill it is positive, at the top it is zero, and downhill it is negative.
- Written as a limit, it is the difference quotient you already know, f at x plus h, minus f at x, over h, with y held fixed the whole time.
- Now freeze x instead, and walk in the y direction. A different slice gives a different curve, and a different slope: the partial derivative of f with respect to y.
- Watch the y slope change sign as we cross the ridge. Two slices, two slopes, one surface.
- At one point, the two partial derivatives can be completely different. Here, at x equals zero and y equals zero point six, the surface climbs steeply in the x direction, but is almost level in the y direction.
- Each partial derivative only sees one direction. Combining them into a full picture of how the surface tilts is the job of the next few lessons.
- So a partial derivative is just an ordinary derivative along a slice. Freeze every input but one, and take the slope.
- Next, we will compute partial derivatives by hand, take them twice, and teach a computer to estimate them on a grid.
Scalar fields: one number at every point
A function of two variables takes a point of the plane and returns one real number. A function of three variables does the same for a point in space. Physicists call such functions scalar fields (“scalar” because the output is a single number, as opposed to the vector fields of 2.6 Vector Fields, Flow Lines & Streamlines). Examples:
- the temperature across a heated metal plate;
- the pressure around an aircraft wing;
- the height of terrain above sea level;
- the density of smoke in a room, which also changes with time.
The set of allowed inputs is the domain. For it’s the disk . For most fields in this course, it’s simply the region your simulation covers.
Three ways to see
You can’t draw a function of two variables as a curve, so we use three pictures. You need all three, and you should be able to switch between them at will.
1. The graph (a surface). Plot the value as a height: the points with form a surface over the -plane. Hills are where is large and valleys where it is small. This is the most intuitive picture, but it needs a 3D view, and it is useless for functions of three variables (you’d need four dimensions).
2. The contour map (level curves). For a constant , the level curve is the set of points where the function has the value . Draw level curves for evenly spaced values and you get a hiking map. Each level curve is the “shoreline” you’d see if you flooded the surface up to height . Where the curves crowd together, the surface is steep; where they spread out, it is flat. For the same idea gives level surfaces (isosurfaces). Those are what volume renderers draw when they show you a smoke plume.
3. The heatmap. Color each point by its value with a colormap (dark is low, bright is high). It’s a flattened graph. It is how simulators display a 2D field, since it is literally an image with one pixel per grid cell.
Worked example: a paraboloid. Take .
- Graph: an upside-down bowl with its top at .
- Level curves: means . For this is an ellipse with semi-axes along and along . For it is a single point, and for the level set is empty. The ellipses are squashed in the direction, so the contours are closer together along , which tells you the bowl is steeper in than in . We’ll confirm that with derivatives in a moment.
- Heatmap: a bright elliptical spot in the middle fading to dark at the edges.
Partial derivatives: slopes of slices
How fast does change? With one input, there was only one way to move. With two, you can walk in any direction, and the rate of change depends on the direction. We start with the two simplest directions: along the -axis and along the -axis.
Freeze . Fix . The vertical plane slices the surface along a curve, namely the graph of the one-variable function
This is an ordinary function of one variable, and its ordinary derivative at is the slope of the slice. That slope is the partial derivative of with respect to at :
Freeze . Likewise, fixing slices the surface with the plane , and the slope of that slice is
The curly (“partial”, or “del”) warns you that has other inputs that are being held fixed. Geometrically, is the slope of the surface if you stand at and face the direction; is the slope facing .
Notation
You will meet all of these, and they mean the same thing:
For a field that depends on position and time, is the rate of change at a fixed location, and is the rate of change in space at a fixed instant. Subscripts are the dialect of PDEs, and you’ll be reading them constantly from now on.
Computing partials: treat the others as constants
No new rules are needed. To compute , pretend is a number like 7 and differentiate with respect to using everything you know from Calc I: power rule, product rule, chain rule.
Worked example. Let .
- For , is a constant. Then is () times , so its derivative is . The term gives , and is a constant, so it gives :
- For , is a constant. Then is () times , giving . The term is a constant, so it gives , and gives :
At the point : and .
Worked example: the paraboloid again. For we get and . At , where :
- The slice is the parabola . Its slope at is , which matches .
- The slice is the parabola . Its slope at is , which matches .
Walking in you descend twice as fast as walking in , just as the squashed ellipses predicted.
Three variables work the same way. For a temperature blob , the chain rule gives , and by symmetry and have and in place of . At , degrees per unit length: moving outward along , it gets colder fast.
Now explore it yourself. The probe shows the heatmap with contours on the left. The amber line is the slice , and the cyan line is the slice . On the right are the two slice graphs, each with its tangent line in red.
Try these:
- Drag the probe to the top of the tall hill. Both tangent lines go flat: at a peak.
- Put the probe on the left flank of the tall hill, around . The amber slice climbs steeply and the cyan slice is almost level: a large and a tiny at the same point.
- Switch to the saddle. At the origin both partials are zero, yet it is neither a peak nor a valley: the -slice is a smile and the -slice is a frown. (Lesson 2.3 Gradient & Directional Derivatives classifies such points.)
- Turn on Finite-difference estimate and slide from large to small. Compare forward with central. We’ll explain what you see in the section on grids below.
Compute the indicated partial derivatives.
- : find and .
- : find , and .
- : find and (for ).
Show worked solution
- Freezing : (the term is a constant). Freezing : (chain rule on ).
- (both and the factor are constants in ). For : , by the chain rule with inner derivative . For : .
- Quotient rule with frozen: . With frozen the numerator is a constant: .
Higher-order and mixed partials
The partial derivatives and are themselves functions of , so we can differentiate them again. There are four second-order partials:
Mind the ordering conventions. In subscript notation, you differentiate left to right: means “first , then ”. In fraction notation you read right to left: means “first , then ”. The good news is that for the functions in this course the order won’t matter, as we’ll see in a moment.
is the concavity of the -slice: positive where the slice curves up like a smile, negative where it curves down. The mixed partial measures twist: how the -slope changes as you step in the direction.
Worked example. Continue with , where and :
The two mixed partials came out equal, even though we computed them along completely different routes. That is not a coincidence.
Worked example. Let . With the product and chain rules,
Then
Equal again.
Why should it be true? Look at the four corners of a tiny square with side and form the “double difference”
Group it as . That is the change in the -differences as you step up in , so . Group it the other way, . That is the change in the -differences as you step right in , so . It’s the same number either way. Dividing by and letting gives . Continuity is exactly what makes both approximations valid in the limit. The formal proof applies the mean value theorem twice.
For (from the first problem), compute , , and , and confirm that Clairaut’s theorem holds.
Show worked solution
From and :
The mixed partials agree everywhere, as they must: is built from polynomials and exponentials, so all of its partials are continuous.
Partial derivatives on a grid
A simulator never has the formula for . It has samples on a grid: with and . To get derivatives, it replaces the limit in the definition with a small but finite , the grid spacing. This is the finite-difference method, and you’ll build whole PDE solvers out of it in 10.1 Finite Differences: Discretizing Derivatives.
For at cell , only the index moves:
For , only the index moves: . Freezing a variable on a grid means keeping its index fixed.
Which is better? Expand in a Taylor series along the -slice (all derivatives evaluated at ):
Using only the plus sign,
so the forward difference has error proportional to (first order). Subtracting the minus expansion from the plus one cancels the even terms:
so the central difference has error proportional to (second order). Halve , and the forward error halves while the central error drops by a factor of four. Adding the two expansions instead cancels the odd terms and gives the second-derivative stencil
also second order. Add the and versions and you have the five-point Laplacian , the most important stencil in fluid simulation (2.11 The Laplacian & Vector Identities). A mixed partial uses the four diagonal neighbors: it’s the double difference from the Clairaut argument, centered:
In the probe sim, turn on the finite-difference estimate and watch the error readout as you shrink . With central differences, each tenfold reduction of cuts the error about a hundredfold, until gets so tiny (around is fine, but far smaller is not) that floating-point round-off in starts to win.
Here’s the same experiment in code, as a log-log plot:
Exercise: derivatives of a sampled field
In NumPy, a 2D field sampled with X, Y = np.meshgrid(x, y) is stored as F[j, i] = f(x[i], y[j]). Axis 0 is (rows) and axis 1 is (columns). Mixing them up is the single most common bug in grid codes, so keep this in mind. NumPy’s np.gradient(F, h, axis=...) computes central differences in the interior and one-sided differences at the edges. You’ll write your own and check it against both np.gradient and the exact partials, then verify Clairaut numerically.
Notice that the discrete and agree to round-off, not just approximately. Differencing along rows and differencing along columns are operations that commute, which is a discrete Clairaut theorem. You can check the symbolic version too:
A temperature field is sampled on a grid with spacing :
| 10.625 | 12.5 | 15.625 | |
| 10.5 | 12.0 | 14.5 | |
| 10.375 | 11.5 | 13.375 |
- Estimate and at with central differences.
- Estimate with a forward difference.
- Estimate and .
- The data actually come from . Compare with the exact values, and explain why the central estimates are exact here while the forward one is not.
Show worked solution
- , and .
- .
- . For the mixed partial, use the four corners: .
- Exactly: , , , . All the central estimates are exact. The central-difference error starts with , and for a function that is quadratic in . (Similarly is linear in .) The forward error starts with , which is exactly the gap between 5 and 4.
PDE notation: equations about partial derivatives
An ordinary differential equation relates a function of one variable to its derivatives. A partial differential equation (PDE) relates a function of several variables to its partial derivatives. You can now read the three classics:
Each says something you can now picture. Take the heat equation: is the temperature along a rod. At a fixed location, the temperature rises () wherever the profile is concave up (, a local dip that gets filled in) and falls wherever it is concave down (a hot bump that melts away). The constant is the diffusivity. The second video animates exactly this.
Transcript
- Let's compute partial derivatives, first with a pencil, and then the way a simulator does it, on a grid.
- Computing a partial derivative needs no new rules. Treat every other variable as a constant, and differentiate exactly as in Calc One.
- For the partial with respect to x, y is frozen. So y cubed is just a constant multiplier, and minus four y is a constant that disappears. We get two x y cubed, plus cosine x.
- For the partial with respect to y, x is frozen instead. Now x squared is the constant, sine x vanishes, and we get three x squared y squared, minus four.
- The notation varies. You will see the curly d fraction, or a subscript: f sub x. In physics, u sub t is the rate of change in time, and u sub x x is the second derivative in space.
- A partial derivative is itself a function of x and y, so we can differentiate it again. That gives f x x, f y y, and two mixed partials, f x y and f y x.
- Look: the two mixed partials agree. That is no accident. Clairaut's theorem says that if the second partials are continuous, the order of differentiation does not matter.
- Now to simulation. A computer never stores the formula. It stores samples on a grid, one number per cell, with spacing h between them.
- To estimate the x partial at this cell, look at its left and right neighbors. Their difference, divided by two h, is the central difference.
- For the y partial, use the neighbors above and below instead. It is the same idea, rotated by ninety degrees.
- Second derivatives work the same way: neighbor plus neighbor, minus twice the center, over h squared. Add the x and y versions, and you have the five point Laplacian, the workhorse of every fluid solver.
- How good is the estimate? On a single slice, the central difference is the slope of the amber line through two neighbors. The red line is the true tangent.
- Shrink h, and the amber line rotates onto the tangent. Halve h, and the error drops by about a factor of four. We say the central difference is second order accurate.
- A partial differential equation ties these derivatives together. The heat equation says u sub t equals alpha times u sub x x.
- Read it out loud: temperature rises wherever the profile curves upward, and falls wherever it curves downward. Bumps melt away.
- Every fluid simulation in this course is, at its core, an equation like this one, discretized on a grid with exactly the stencils you just saw.
- To recap: freeze the other inputs and differentiate. Mixed partials agree for smooth functions. And on a grid, neighbors give you derivatives.
- Next time, we combine the two partial derivatives into a tangent plane, the best linear approximation of a surface, and meet the multivariable chain rule.
Checking a solution is pure partial differentiation. Is a solution of the heat equation? With frozen, . With frozen, and . So . ✓ It’s a sine-shaped temperature profile that decays exponentially in time, and the wigglier the profile, the faster it decays. That’s the seed of Fourier’s method in 9.3 Solving the Heat Equation: Separation of Variables.
- Show that satisfies the wave equation . What does the solution look like as time passes?
- For which constant does satisfy ?
- Show that and both satisfy Laplace’s equation .
Show worked solution
- and . Also and . So . ✓ The profile at time is the initial sine wave shifted right by : a wave traveling at speed without changing shape.
- and . The equation requires , so . A profile with spatial frequency 3 decays at rate .
- For : and , which sum to . ✓ For : and , which sum to . ✓ Notice that in both cases, where the -slice is concave up the -slice is concave down by the same amount. Harmonic functions are “saddle-like” everywhere and have no interior peaks.
Let
- Using the limit definition, show that for all and for all .
- Conclude that while .
- Which hypothesis of Clairaut’s theorem fails?
Show worked solution
- For : . Since and , the quotient is . For : , so . ✓ Similarly, (and at ).
- , while .
- The mixed partials exist everywhere but are not continuous at the origin. Away from the origin, a computation shows . Along the -axis this equals and along the -axis it equals , so it has no limit at .
Where this goes next
Partial derivatives only look along the coordinate axes. In 2.2 Linearization, the Chain Rule & the Jacobian we combine and into a tangent plane, the best linear approximation of a surface, and develop the multivariable chain rule. That gives the material derivative that every fluid equation uses. In 2.3 Gradient & Directional Derivatives the pair becomes the gradient vector, which points uphill. The PDEs you just read are derived properly in 9.2 The Heat (Diffusion) Equation, and the Navier–Stokes equations (11.4 Viscosity & the Navier–Stokes Equations) are just a larger system of the same kind of statement.
Key Takeaways
- A scalar field assigns one number to each point. See it as a surface , a contour map of level curves , or a heatmap. Crowded contours mean steep change.
- The partial derivative is the slope of the slice at : freeze every other input and differentiate as usual. freezes instead.
- Notation: . In PDEs, is the rate of change in time at a fixed place, and is the spatial concavity.
- Second partials measure the concavity of slices and the twist between them. Clairaut’s theorem: whenever these are continuous, which is a free check on hand computations.
- On a grid, freezing a variable means fixing its index. The central difference is second-order accurate, while the forward difference is only first order. The stencil gives .
- In NumPy’s
meshgridlayout, axis 0 is and axis 1 is , and every fluid-solver operator (pressure gradient, divergence, Laplacian) is built from these stencils. - A PDE is an equation relating partial derivatives. Checking a proposed solution is just computing partials and substituting.