Free lesson · Partial derivatives
Gradients, directional derivatives and Jacobians
Open interactive lessonPractice calculationsExplore labs
Start with the idea
- Find the slope for each input. Multiply each slope by that input’s small change, then add the contributions to estimate the output change.
Symbols, units & horizon
- ∇f: gradient of a scalar function
- T: transpose
- u: direction vector of unit Euclidean length for a per-unit-distance derivative
- Dᵤf: directional derivative
- Fᵢ: output component i
- xⱼ: input component j
- J: Jacobian matrix
- Δx,ΔF: small finite input and output changes
- || ||: vector length
When and why to use this
Use gradients for scenario directions and optimisation; use Jacobians to connect stages of a multivariable model and audit input/output dimensions.
Start here · the same idea in everyday words
| Technical term | Everyday meaning | Concrete example |
|---|---|---|
| Gradient | A list of slopes, one for each input. | For two inputs, list the x slope and the y slope in that order. |
| Directional derivative | The slope when moving in one specified direction. | Moving only east is different from moving northeast. |
| Jacobian | A table showing how each output changes with each input. | Two outputs and three inputs give a table with two rows and three columns. |
Unpack a technical sentence
Technical wording: The gradient maps an input perturbation to a first-order output change.
Read it as: Find the slope for each input. Multiply each slope by that input’s small change, then add the contributions to estimate the output change.
A slower worked example · one step at a time
- Use a dimensionless output f=x squared plus 3y at x=2 and y=1. The current output is 4+3=7.
- Holding y fixed, the x slope is 2 times x, or 4. Holding x fixed, the y slope is 3. The gradient is the list [4,3].
- Increase x by .01 and decrease y by .02. The x contribution is 4 times .01=.04. The y contribution is 3 times −.02=−.06.
- Add the contributions: .04−.06=−.02. The predicted new output is 6.98.
- Calculate directly: 2.01 squared plus 3 times .98 equals 6.9801. The difference .0001 is the quadratic x term omitted by the straight-line approximation.
Self-assessed: Why do we add the two input contributions rather than multiply them?
They are separate ways the same output changes. Multiply along a chain of dependent calculations; add the contributions from separate changing inputs.
- For a unit direction u, the directional derivative measures output change per unit distance in the chosen coordinate scale.
- Rescaling an input changes what a unit step means.
- This matters when combining prices, rates and volatility coordinates.
- If a model maps an input vector x to an output vector F, its Jacobian entry Jᵢⱼ is the partial derivative of output i with respect to input j.
- Multiplying J by a small input change gives a first-order output-change vector.
- The rows and columns must match the documented ordering.
Gradients, directional derivatives and Jacobians
- For f=x²+2y², the gradient is (2x,4y). At (1,1) it is (2,4).
- Use direction u=(3/5,4/5), whose squared length is 9/25+16/25=1. The directional derivative is 2×3/5+4×4/5=4.4.
- For F=(x+y,xy), differentiate each output to get Jacobian rows (1,1) and (y,x). At (2,3), a change (.1,−.2) gives first-order output change (−.1,−.1).
For F=(x+y,xy), actual change from (2,3) to (2.1,2.8) is (−.1,−.12). The −.02 difference in the second component is the product of the two input changes, omitted at first order.
Architecture pseudocode
def directional_quadratic(x,y,direction):
ux,uy=direction
if abs(ux*ux+uy*uy-1)>1e-9: raise ValueError("Unit direction required")
return 2*x*ux+4*y*uy
def example_jacobian(x,y):
return [[1,1],[y,x]]
def linear_output_change(jacobian,change):
if any(len(row)!=len(change) for row in jacobian): raise ValueError("Dimensions must match")
return [sum(a*b for a,b in zip(row,change)) for row in jacobian]
print(directional_quadratic(1,1,(.6,.8)),linear_output_change(example_jacobian(2,3),[.1,-.2]))
# Replay the slower, synthetic example above. Units are stated in its steps.
def plain_language_example():
from math import exp, e # Standard library; no extra dependency.
return {
"start": 2**2+3*1,
"change": 4*.01+3*(-.02),
"prediction": 7+4*.01+3*(-.02),
"actual": 2.01**2+3*.98,
}
print(plain_language_example())An analogy to remember
A gradient is a slope map telling you how a hill rises in each coordinate direction. A Jacobian is a table of such responses when you are tracking several outputs at once.
How this becomes a building block
A Jacobian can map market-quote changes into instrument-price changes or map parameter changes into calibration errors. Reverse-mode automatic differentiation efficiently propagates a scalar output’s sensitivities backward through a computational graph; it differentiates the implemented operations, not an independently validated economic truth.
Python implementation
Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.
def directional_quadratic(x,y,direction):
ux,uy=direction
if abs(ux*ux+uy*uy-1)>1e-9: raise ValueError("Unit direction required")
return 2*x*ux+4*y*uy
def example_jacobian(x,y):
return [[1,1],[y,x]]
def linear_output_change(jacobian,change):
if any(len(row)!=len(change) for row in jacobian): raise ValueError("Dimensions must match")
return [sum(a*b for a,b in zip(row,change)) for row in jacobian]
print(directional_quadratic(1,1,(.6,.8)),linear_output_change(example_jacobian(2,3),[.1,-.2]))
# Replay the slower, synthetic example above. Units are stated in its steps.
def plain_language_example():
from math import exp, e # Standard library; no extra dependency.
return {
"start": 2**2+3*1,
"change": 4*.01+3*(-.02),
"prediction": 7+4*.01+3*(-.02),
"actual": 2.01**2+3*.98,
}
print(plain_language_example())Continue learning
Multivariable Calculus & Partial Derivatives — all lessons- Start with two inputs: change only one
- Partial derivatives: holding the other inputs fixed
- Gradients, directional derivatives and Jacobians
- Hessians, mixed derivatives and second-order scenarios
- Constrained optimisation and multiple integrals
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations