MATH-209 · Lesson 2 of 5 · 47 min
Partial derivatives and gradients
In single-variable calculus, the derivative measures how fast a function changes. With several variables, the function can change at different rates in different directions: the temperature in a plate may rise steeply toward a heater and barely change along an insulated edge. Partial derivatives measure the rate of change in each coordinate direction; the gradient packages them into a vector that points uphill and tells you how steep the hill is.
This chapter defines partial derivatives and their meaning, extends linear approximation to several variables (and uses it to estimate measurement errors), develops the multivariable chain rule, introduces directional derivatives and the gradient, and applies them to finding maxima and minima, including constrained optimization with Lagrange multipliers. These ideas are behind heat flow, fluid pressure gradients, error analysis of experiments and every gradient-based optimization algorithm.
Partial derivatives
The partial derivative of \(f(x, y)\) with respect to \(x\) is the ordinary derivative obtained by treating \(y\) as a constant:
Similarly, \(f_y = \partial f/\partial y\) treats \(x\) as a constant. In practice you use all the single-variable rules, holding the other variables fixed.
Worked problem
Computing partial derivatives
For \(f(x, y) = x^2y + 3xy^3\), find \(f_x\) and \(f_y\), and evaluate them at (1, 2).
Show solution
- Treat y as a constant: \(f_x = 2xy + 3y^3\).
- Treat x as a constant: \(f_y = x^2 + 9xy^2\).
- At (1, 2): \(f_x = 4 + 24 = 28\) and \(f_y = 1 + 36 = 37\).
Answer: fₓ = 2xy + 3y³ = 28 and f_y = x² + 9xy² = 37 at (1, 2)
Geometrically, \(f_x(a, b)\) is the slope of the surface \(z = f(x, y)\) at the point above \((a, b)\), in the x-direction: slice the surface with the plane \(y = b\) and measure the slope of the resulting curve. \(f_y\) is the slope in the y-direction.
Worked problem
Temperature gradients in a plate
For the plate in Lesson 1, \(T(x, y) = 100 - x^2 - 2y^2\) (°C, with x and y in cm). Find the rates of change of temperature in the x and y directions at (1, 2).
Show solution
- \(T_x = -2x = -2\) °C/cm at (1, 2).
- \(T_y = -4y = -8\) °C/cm at (1, 2).
Answer: Moving in +x, the temperature falls 2 °C per cm; moving in +y, it falls 8 °C per cm. The plate cools four times faster in the y-direction at that point
Worked problem
Sensitivity of gas pressure
For one mole of ideal gas, \(P = RT/V\). At \(T = 300\) K and \(V = 0.025\) m³, find \(\partial P/\partial T\) and \(\partial P/\partial V\) and interpret them.
Show solution
- \(\partial P/\partial T = R/V = 8.314/0.025 = 332.6\) Pa/K.
- \(\partial P/\partial V = -RT/V^2 = -8.314 \times 300/0.025^2 = -3.99 \times 10^6\) Pa/m³, which is −3.99 kPa per liter.
Answer: Warming the gas by 1 K at constant volume raises the pressure about 333 Pa; expanding it by 1 L at constant temperature drops the pressure about 4.0 kPa. Partial derivatives are sensitivities: how much the output responds to each input separately
Higher derivatives
Partial derivatives can be differentiated again: \(f_{xx}\), \(f_{yy}\), and the mixed partials \(f_{xy} = (f_x)_y\) and \(f_{yx} = (f_y)_x\). For the functions met in engineering (with continuous second partials), Clairaut's theorem guarantees the mixed partials are equal: the order does not matter.
Worked problem
Checking Clairaut
Verify \(f_{xy} = f_{yx}\) for \(f = x^2y + 3xy^3\).
Show solution
- \(f_{xy} = \partial(2xy + 3y^3)/\partial y = 2x + 9y^2\).
- \(f_{yx} = \partial(x^2 + 9xy^2)/\partial x = 2x + 9y^2\).
Answer: Both equal 2x + 9y². Second partial derivatives appear in all the major equations of engineering physics, such as the heat equation and the wave equation
Tangent planes and linear approximation
Close to a point, a smooth surface looks like a plane, just as a smooth curve looks like its tangent line. The tangent plane at \((a, b)\) gives the linear approximation:
Worked problem
Linear approximation
Use a linear approximation of \(f(x, y) = \sqrt{x^2 + y^2}\) at (3, 4) to estimate \(f(3.02, 3.97)\).
Show solution
- \(f(3, 4) = 5\). \(f_x = x/\sqrt{x^2 + y^2} = 3/5 = 0.6\); \(f_y = 4/5 = 0.8\).
- \[f(3.02, 3.97) \approx 5 + 0.6(0.02) + 0.8(-0.03) = 5 + 0.012 - 0.024 = 4.988\]
Answer: 4.988. The exact value is 4.98812, so the approximation is excellent for small changes
The total differential and error propagation
Writing the small changes as differentials gives the total differential:
This is one of the most useful formulas in experimental engineering. If inputs are measured with small uncertainties \(dx\) and \(dy\), the differential estimates the resulting uncertainty in a calculated result. Taking absolute values of each term gives a conservative (worst-case) estimate.
Worked problem
Uncertainty in a tank volume
A cylindrical tank is measured as radius 1.50 ± 0.01 m and height 4.00 ± 0.02 m. Estimate its volume and the uncertainty in the volume.
Show solution
- \(V = \pi r^2 h = \pi(1.5)^2(4) = 28.27\) m³.
- \(dV = V_r\,dr + V_h\,dh = 2\pi rh\,dr + \pi r^2\,dh\).
- \[|dV| \le 2\pi(1.5)(4)(0.01) + \pi(1.5)^2(0.02) = 0.377 + 0.141 = 0.518 \text{ m}^3\]
- Relative uncertainty: \(0.518/28.27 = 1.8\%\). In relative form, \(dV/V = 2\,dr/r + dh/h = 1.33\% + 0.50\% = 1.83\%\).
Answer: V = 28.3 ± 0.5 m³ (about 1.8%). The radius contributes most because it is squared: its 0.67% error counts twice. To improve the estimate, measure the radius more precisely
The chain rule
If \(z = f(x, y)\) and both \(x\) and \(y\) change with time, the rate of change of \(z\) collects a contribution from each path:
A tree diagram helps: draw \(z\) at the top, branches to each intermediate variable, branches from those to \(t\), multiply along each path and add the paths.
Worked problem
Pressure in a compressor
In a compressor, one mole of gas is at \(T = 300\) K and \(V = 0.025\) m³. The temperature is rising at 2 K/s and the volume falling at \(1.0 \times 10^{-4}\) m³/s. How fast is the pressure rising?
Show solution
- From the earlier example: \(\partial P/\partial T = 332.6\) Pa/K and \(\partial P/\partial V = -3.991 \times 10^6\) Pa/m³.
- \[\frac{dP}{dt} = (332.6)(2) + (-3.991 \times 10^6)(-1.0 \times 10^{-4}) = 665.1 + 399.1 = 1064 \text{ Pa/s}\]
Answer: About 1.06 kPa/s, with roughly 60% coming from heating and 40% from compression
Directional derivatives and the gradient
Partial derivatives give rates of change along the axes. The rate of change in any direction, given by a unit vector \(\mathbf{u} = (u_1, u_2)\), is the directional derivative:
where the gradient is the vector of partial derivatives:
Because \(D_{\mathbf{u}} f = |\nabla f|\cos\theta\), where \(\theta\) is the angle between \(\mathbf{u}\) and the gradient, three facts follow immediately:
- The gradient points in the direction of fastest increase of \(f\), and its magnitude \(|\nabla f|\) is that fastest rate.
- The direction of fastest decrease is \(-\nabla f\).
- The rate of change is zero perpendicular to the gradient, which is the direction along a level curve. So the gradient is always perpendicular to the level curves (and, in 3D, to level surfaces).
Worked problem
Directional derivative on the plate
At (1, 2) on the plate, find (a) the rate of change of temperature toward the point (4, 6), and (b) the direction and value of the fastest increase.
Show solution
- \(\nabla T = (-2x, -4y) = (-2, -8)\) at (1, 2).
- (a) Direction from (1, 2) to (4, 6): \((3, 4)\), length 5, so \(\mathbf{u} = (0.6, 0.8)\).
- \[D_{\mathbf{u}}T = (-2)(0.6) + (-8)(0.8) = -1.2 - 6.4 = -7.6 \text{ °C/cm}\]
- (b) Fastest increase is along \(\nabla T = (-2, -8)\), toward the center, at a rate \(|\nabla T| = \sqrt{4 + 64} = 8.25\) °C/cm.
Answer: (a) −7.6 °C/cm (cooling); (b) along (−2, −8), at 8.25 °C/cm. No direction gives a faster change than |∇T|
The gradient is everywhere in engineering physics. Heat flows down the temperature gradient (Fourier's law, \(\mathbf{q} = -k\nabla T\)); groundwater flows down the hydraulic head gradient (Darcy's law); the electric field is minus the gradient of potential (\(\mathbf{E} = -\nabla V\), PHYS-131); and fluid is pushed by pressure gradients. In each case, the flow crosses the contours at right angles.
Worked problem
A normal vector from the gradient
Find a vector normal to the isotherm \(x^2 + 2y^2 = 9\) at (1, 2), and the equation of its tangent line.
Show solution
- With \(g = x^2 + 2y^2\), \(\nabla g = (2x, 4y) = (2, 8)\) at (1, 2). This is normal to the level curve.
- Tangent line: \(2(x - 1) + 8(y - 2) = 0\), i.e. \(x + 4y = 9\).
Answer: Normal (2, 8), or (1, 4); tangent line x + 4y = 9. The same trick gives the tangent plane to any level surface F(x, y, z) = k in 3D
Maxima and minima
At a smooth local maximum or minimum, the surface is flat: both partial derivatives are zero. Points where \(\nabla f = \mathbf{0}\) (or where a partial derivative does not exist) are critical points. As in one variable, not every critical point is an extreme; in two variables, a critical point can also be a saddle, rising in one direction and falling in another.
The second derivative test sorts them out. At a critical point, compute
- \(D > 0\) and \(f_{xx} > 0\): local minimum.
- \(D > 0\) and \(f_{xx} < 0\): local maximum.
- \(D < 0\): saddle point.
- \(D = 0\): the test is inconclusive.
Worked problem
Classifying critical points
Find and classify the critical points of \(f(x, y) = x^3 - 3x + y^2\).
Show solution
- \(f_x = 3x^2 - 3 = 0\) gives \(x = \pm 1\); \(f_y = 2y = 0\) gives \(y = 0\). Critical points: (1, 0) and (−1, 0).
- \(f_{xx} = 6x\), \(f_{yy} = 2\), \(f_{xy} = 0\), so \(D = 12x\).
- At (1, 0): \(D = 12 > 0\) and \(f_{xx} = 6 > 0\): local minimum, \(f = -2\).
- At (−1, 0): \(D = -12 < 0\): saddle point, \(f = 2\).
Answer: Local minimum −2 at (1, 0); saddle at (−1, 0)
On a closed, bounded region, a continuous function always has an absolute maximum and minimum. They occur either at critical points inside the region or on its boundary, so check both. This is how you would find, say, the hottest and coldest points of a plate of a given shape.
Optimization with a constraint
Engineering optimization almost always has constraints: minimize material subject to a required volume, maximize strength subject to a weight limit. Sometimes you can substitute the constraint and reduce the number of variables; Lagrange multipliers give a general method. To optimize \(f(x, y, z)\) subject to \(g(x, y, z) = c\), solve
Geometrically, at the optimum the level surface of \(f\) just touches the constraint surface, so their normals (gradients) are parallel.
Worked problem
The cheapest open-top tank
An open-top rectangular tank must hold 32 m³. Find the dimensions that use the least sheet material.
Show solution
- Base \(x \times y\), height \(z\). Minimize \(S = xy + 2xz + 2yz\) subject to \(xyz = 32\).
- Lagrange: \(\nabla S = \lambda\nabla(xyz)\) gives \(y + 2z = \lambda yz\), \(x + 2z = \lambda xz\), \(2x + 2y = \lambda xy\).
- Multiply the first by x and the second by y: \(xy + 2xz = \lambda xyz = xy + 2yz\), so \(x = y\).
- Multiply the second by y and the third by z: \(xy + 2yz = \lambda xyz = 2xz + 2yz\), so \(xy = 2xz\), giving \(y = 2z\).
- With \(x = y = 2z\): \(4z^3 = 32\), so \(z = 2\) and \(x = y = 4\).
- \(S = 16 + 16 + 16 = 48\) m².
Answer: A 4 m × 4 m base, 2 m high, using 48 m² of plate. The optimal open tank is half as tall as it is wide; the same result follows by substituting z = 32/(xy) and setting both partial derivatives to zero
Gradient-based optimization drives much of modern engineering design software: structural optimization, aerodynamic shape design and the training of machine learning models all repeatedly compute a gradient and step downhill. The ideas in this section are the foundation of those methods.
Common mistakes
MistakeDifferentiating the "constant" variable when finding a partial derivative.
InsteadTreat every other variable exactly as a number: ∂(x²y)/∂x = 2xy, not 2xy + x².
MistakeUsing a direction vector that is not a unit vector in D_u f.
InsteadNormalize first: divide by its length.
MistakeThinking the gradient lies along the level curve.
InsteadThe gradient is perpendicular to level curves and points toward higher values.
MistakeCalling every critical point a maximum or minimum.
InsteadUse D = fₓₓf_yy − fₓᵧ²; D < 0 means a saddle.
MistakeForgetting the boundary when finding absolute extremes on a region.
InsteadCheck critical points inside and the function along the boundary.
MistakeAdding uncertainties without weighting by sensitivity.
InsteadUse the total differential; squared or powered quantities contribute in proportion to their exponent.
Summary and key terms
- A partial derivative is the rate of change in one coordinate direction, found by holding the other variables constant.
- Mixed second partials are equal for smooth functions (Clairaut's theorem).
- The tangent plane gives the linear approximation f ≈ f(a, b) + fₓΔx + f_yΔy; the total differential df = fₓdx + f_ydy estimates measurement uncertainty.
- Chain rule: dz/dt = fₓ dx/dt + f_y dy/dt; a tree diagram organizes the terms.
- The directional derivative is D_u f = ∇f · u; the gradient points in the direction of fastest increase, with magnitude equal to that rate, and is perpendicular to level curves.
- Critical points (∇f = 0) are classified with D = fₓₓf_yy − fₓᵧ²: minimum, maximum or saddle.
- Constrained optimization: ∇f = λ∇g at the optimum (Lagrange multipliers), or substitute the constraint.
- Partial derivative
- The derivative with respect to one variable with the others held constant.
- Mixed partial
- A second derivative taken with respect to two different variables.
- Tangent plane
- The plane that best approximates a surface near a point.
- Total differential
- df = fₓdx + f_ydy, the linear estimate of the change in f.
- Chain rule
- The rule for differentiating a function whose inputs depend on another variable.
- Directional derivative
- The rate of change of f in the direction of a unit vector.
- Gradient
- The vector of partial derivatives, pointing in the direction of fastest increase.
- Critical point
- A point where the gradient is zero or undefined.
- Saddle point
- A critical point that is a maximum in one direction and a minimum in another.
- Lagrange multiplier
- The scalar λ in ∇f = λ∇g at a constrained optimum.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Find \(f_x\) and \(f_y\) for \(f(x, y) = e^{xy} + x\ln y\).
Show answer
fₓ = y e^{xy} + ln y; f_y = x e^{xy} + x/y.
For \(f = \sin(x)\cos(2y)\), find all second partial derivatives.
Show answer
fₓₓ = −sin x cos 2y; f_yy = −4 sin x cos 2y; fₓᵧ = f_yx = −2 cos x sin 2y.
Find the tangent plane to \(z = x^2 + y^2\) at (1, 2, 5).
Show answer
zₓ = 2, z_y = 4: z = 5 + 2(x − 1) + 4(y − 2), or z = 2x + 4y − 5.
The resistance of a wire is \(R = \rho L/A\). L is measured to ±0.5% and A to ±1%. Estimate the uncertainty in R (ρ known exactly).
Show answer
dR/R = dL/L + dA/A (magnitudes) = 0.5% + 1% = 1.5%.
A rectangle's sides are 3 m and 4 m, growing at 0.1 and 0.2 m/s. How fast is its diagonal growing?
Show answer
D = √(x² + y²) = 5. dD/dt = (x/D)(0.1) + (y/D)(0.2) = 0.06 + 0.16 = 0.22 m/s.
Find the gradient of \(f = x^2y - y^3\) at (2, 1) and the directional derivative in the direction of (1, 1).
Show answer
∇f = (2xy, x² − 3y²) = (4, 1). u = (1, 1)/√2. D = 5/√2 = 3.54.
In which direction does \(T = 100 - x^2 - 2y^2\) decrease fastest at (2, −1), and at what rate?
Show answer
∇T = (−4, 4); fastest decrease along −∇T = (4, −4), i.e. direction (1, −1)/√2, at rate |∇T| = 5.66 °C/cm.
Find and classify the critical points of \(f = x^2 + xy + y^2 - 6x\).
Show answer
fₓ = 2x + y − 6 = 0, f_y = x + 2y = 0 → x = 4, y = −2. D = 2·2 − 1 = 3 > 0, fₓₓ > 0: minimum, f = −12.
Classify the critical point of \(f = xy\) at the origin.
Show answer
fₓₓ = f_yy = 0, fₓᵧ = 1, D = −1 < 0: saddle.
Find the closed rectangular box of volume 27 m³ with the least surface area.
Show answer
By symmetry (or Lagrange), a cube: 3 × 3 × 3 m, area 54 m².
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.