Explore calculusLesson 28 of 48 · 8 min

Take one partial derivative at a time

Build a gradient with an explicit order of input variables.

Maths refresher: Partial change

A partial derivative varies one coordinate while the other independent inputs stay fixed.

f(x,y)=x2+xy+y2,∇f=(2x+yx+2y)f(x,y)=x^2+xy+y^2,\qquad\nabla f=\begin{pmatrix}2x+y\\x+2y\end{pmatrix}
Worked example

At (1,2)(1,2), the gradient is (4,5)(4,5). Its entries refer to xx and yy respectively.

Maths prerequisite map ↗

A function of several variables can change in several directions. A partial derivative changes one input while holding the others fixed. The gradient collects those partial derivatives in a stated variable order.

See the mathematics
gradientequal axis scale
gradientequal axis scale
∇f(1,2)=(45)\nabla f(1,2)=\binom45
Starter reference. Contours of x² + xy + y². The arrow from (1, 2) follows the gradient (4, 5); its length is scaled for display.

SymPy diff treats other independent symbols as constants when differentiating with respect to one symbol. Parameters are not automatically functions of that symbol; declare functional dependence explicitly if the model requires it.

The quadratic example has inputs x and y with a cross term. Compute each partial derivative, form a column vector and evaluate it at a point. A zero gradient is a candidate for an interior stationary point; it does not by itself prove a minimum, maximum or feasible solution.

When taking the partial derivative of xyxy with respect to xx, does yy also differentiate to one?

Write a prediction (optional)

Exact symbolic investigation

Select Run Python with the code unchanged.

Tools
About Python

Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗

Ctrl+Enter or ⌘+Enter runs Python.

Compare with the worked example

Executed from the published Python during the site build. Your own run appears above. Build environment ↗

Function
x2+xy+y2x^{2} + x y + y^{2}
Gradient, order (x,y)
[2x+yx+2y]\left[\begin{matrix}2 x + y\\x + 2 y\end{matrix}\right]
Gradient at (1,2)
[45]\left[\begin{matrix}4\\5\end{matrix}\right]
Mixed partial
11
Worked text output
Function: x**2 + x*y + y**2
Gradient, order (x,y): Matrix([[2*x + y], [x + 2*y]])
Gradient at (1,2): Matrix([[4], [5]])
Mixed partial: 1

Read the starter result

The first Gradient, order (x,y) component holds y fixed and the second holds x fixed. The term xyxy therefore contributes y to the first component and x to the second.

Edit and compare

Append +3*x*y to the expression line. Select Run Python and compare the first and second entries in Gradient, order (x,y). Which variable is held fixed for each added term?

Return to the editor

Scope. This example assumes independent coordinates and smooth polynomial derivatives; constraints and nonsmooth points require care.

Try a fresh case

A function has gradient zero at a point. What has been established?

Choose an answer
Need a hint?
Hint 1

A flat slope can occur at a maximum or saddle as well as a minimum.

Hint 2

Separate finding candidates from classifying them.

Your notesNotes save in this browser when storage is available.