Steepest descent method

How steepest descent with Armijo backtracking works for a function of two variables. Gradient, automatic differentiation, stopping criteria, an example, and the method's limitations.

This page exists due to the efforts of the following people:

Timur

Timur

Created: 2026-11-27 16:59:18, Last updated: 2026-11-27 19:20:34

This online calculator minimizes a differentiable function of two variables using steepest descent with Armijo backtracking. It shows every iteration, computes partial derivatives automatically, and plots the search trajectory.

One caveat upfront: the result does not prove a local, let alone a global, minimum. A small gradient norm only indicates proximity to a stationary point, which may be a minimum, maximum, or saddle. The formulas, an example, and the limitations are given below the calculator.

PLANETCALC, Steepest descent with Armijo backtracking

Steepest descent with Armijo backtracking

Variables x, y; operators +, -, *, /, ^; functions sin, cos, exp, log, sqrt, abs; constants pi, e. Use explicit multiplication: 2*x.
The x coordinate of the starting point.
The y coordinate of the starting point.
Calculation stops when the Euclidean gradient norm does not exceed this value.
An integer from 1 to 2000. Reaching the limit is not considered convergence.
Status
 
Iterations performed
 
x at the final point
 
y at the final point
 
f(x,y) at the final point
 
Partial derivative ∂f/∂x
 
Partial derivative ∂f/∂y
 
Gradient norm
 
Last accepted step α
 
Digits after the decimal point: 10
The file is very large. Browser slowdown may occur during loading and creation.
Trajectory in the (x,y) plane
The file is very large. Browser slowdown may occur during loading and creation.
Function value by iteration
The file is very large. Browser slowdown may occur during loading and creation.

Gradient and descent direction

Consider unconstrained minimization of a function f(x,y). “Unconstrained” means that no restrictions are imposed on the variables: we search the entire plane rather than a specified region.

The gradient of a function of two variables is the vector of its partial derivatives:

\nabla f(x,y)=\begin{pmatrix}\frac{\partial f}{\partial x}(x,y)\\[4pt]\frac{\partial f}{\partial y}(x,y)\end{pmatrix}.

If we picture the graph as a hilly surface, the gradient points in the direction of the steepest ascent at the current point. We want to go the other way—downhill. The steepest-descent direction is therefore -\nabla f.1

Denote the current point by z^{(k)}=(x_k,y_k) and its gradient by g_k=\nabla f(z^{(k)}). The next iteration is

z^{(k+1)}=z^{(k)}-\alpha_k g_k.

Here \alpha_k>0 is the step length in the chosen direction. Direction and step length are different things: even with the correct downhill direction, we can jump too far past the desired point.

Exact and inexact line search

In the classical method, the step is chosen by exact minimization along the ray:

\alpha_k^{exact}\in\arg\min_{\alpha\geq0}f(z^{(k)}-\alpha g_k).

This is called exact line search. For a quadratic function, this step is often easy to derive analytically. For an arbitrary user-entered function, however, every iteration would require a new one-dimensional optimization problem, with its own minima, domain, and numerical complications.12

The calculator therefore uses a practical alternative: Armijo backtracking. It first tries \alpha=1. If the function does not decrease enough, the step is halved and tried again. The first admissible step is accepted.

The Armijo condition for the direction -g_k is2

f(z^{(k)}-\alpha g_k)\leq f(z^{(k)})-c\alpha\lVert g_k\rVert_2^2.

The calculator uses c=10^{-4}. The norm \lVert g_k\rVert_2 is the Euclidean gradient norm:

\lVert g_k\rVert_2=\sqrt{\left(\frac{\partial f}{\partial x}\right)^2+\left(\frac{\partial f}{\partial y}\right)^2}.

The right-hand side requires not just any decrease, but a sufficient decrease relative to the step length and gradient magnitude. The algorithm parameters are fixed: initial step 1, halving factor 1/2, and at most 50 reductions per iteration. This scheme goes back to Larry Armijo's 1966 paper.3

The two algorithms should not be confused. A step accepted by the Armijo condition usually is not the exact minimizer along the ray. It is simple, reproducible, and clearly demonstrates the logic of practical optimization methods.

Where the partial derivatives come from

Derivative formulas do not need to be entered separately. The calculator parses the expression and computes the function value together with both partial derivatives using differentiation rules.

For example, the familiar product rule is

(uv)'=u'v+uv'.

The chain rule is used for composite functions. If every intermediate quantity is stored as the triple “value, derivative with respect to x, derivative with respect to y”, these rules can be applied sequentially to the whole expression. This is called forward-mode automatic differentiation.4

It is not a finite-difference approximation: there is no additional small perturbation of the variables and no associated truncation error. The usual limitations of double-precision arithmetic still apply.

Supported syntax:

  • variables x, y, constants pi, e;
  • operators +, -, *, /, ^ and parentheses;
  • functions sin, cos, exp, log, sqrt, abs;
  • explicit multiplication: write 2*x, not 2x;
  • natural logarithm log.

Exponentiation is right-associative: x^y^2 means x^(y^2). Unary minus has lower precedence, so -x^2 means -(x^2).

The function field does not execute arbitrary JavaScript. The calculator also checks the domain: for example, log(x) requires positive x, while the derivatives of sqrt(x) and abs(x) do not exist at x=0.

When to stop

The main stopping criterion is checked before each step, including at the starting point:

\lVert\nabla f(x_k,y_k)\rVert_2\leq\varepsilon.

The default is \varepsilon=10^{-6}. This is a numerical check of the first-order necessary condition for stationarity.1

When the criterion is satisfied, the calculator reports that the specified gradient norm has been reached. If the iteration limit is exhausted, the status is different: “Iteration limit reached; convergence has not been established”. The final point in that case must not be presented as a minimum.

Why not stop simply when the function changes very little? A tiny step can produce a tiny change even far from a stationary point. A small gradient norm also depends on the scale of the variables, but at least it tests stationarity rather than merely a short step.

Example

Consider the function already entered in the calculator:

f(x,y)=x^2+4y^2,\qquad (x_0,y_0)=(2,1).

Its gradient is

\nabla f(x,y)=\begin{pmatrix}2x\\8y\end{pmatrix}.

At the starting point, g_0=(4,8) and f_0=8. Try step 1:

(2,1)-1\cdot(4,8)=(-2,-7),\qquad f(-2,-7)=200.

The value increases, so this step is rejected. With \alpha=1/2, we get f(0,-3)=36—also unsuitable. Finally, with \alpha=1/4:

(2,1)-\frac14(4,8)=(1,-1),\qquad f(1,-1)=5.

The Armijo condition holds because

5\leq8-10^{-4}\cdot\frac14\cdot(4^2+8^2)=7{,}998.

The full trajectory is shown below. The step in a row belongs to the transition from that row to the next.

k x y f(x,y) Step α Reductions
0 2 1 8 0.25 2
1 1 -1 5 0.25 2
2 0.5 1 4.25 0.25 2
3 0.25 -1 4.0625 0.25 2
4 0.125 1 4.015625 0.25 2
5 0.0625 -1 4.00390625 0.25 2
6 0.03125 1 4.0009765625 0.125 3
7 0.0234375 0 0.00054931640625 0.5 1
8 0 0 0 — —

Notice the zigzag. The coefficient 4 in front of y^2 stretches the level sets, and the direction of steepest local descent does not lead straight to zero. “Steepest” describes the direction at the current point, not the shortest route for the whole journey.

For comparison, exact line search on the first iteration would minimize

\phi_0(\alpha)=f(2-4\alpha,1-8\alpha)=8-80\alpha+272\alpha^2.

It would give \alpha=5/34\approx0{,}147059, not 1/4. Both steps decrease the function, but they follow different selection rules.

Why a stationary point need not be a minimum

Take the function

f(x,y)=x^2-y^2.

Its gradient is zero at the origin, so the calculator stops at iteration zero. But this is a saddle: the function increases along the x axis and decreases along the y axis. There is no local or global minimum there.

For f(x,y)=x, the gradient is always (1,0). Every step decreases the function value, but no global minimum exists: the function is unbounded below. An iteration limit or numerical error is appropriate here, not a message claiming that a minimum has been found.

Limitations

The calculator is intended for educational and checking calculations on smooth functions of two variables. Keep in mind:

  1. Local behavior. The starting point affects the trajectory and the stationary point reached. Multiple starts and global-minimum search are not performed.
  2. Differentiability. Discontinuities, kinks, and complicated domain boundaries can cause the search to fail. Automatic differentiation checks calculations only at visited points.
  3. No certificate. The Hessian and the type of stationary point are not computed. The gradient criterion does not prove even a local minimum.
  4. Inexact steps. Armijo backtracking is not exact line search and does not guarantee convergence for every arbitrary function.
  5. Scaling. An absolute gradient-norm tolerance should not be transferred uncritically between problems with different variable and function scales.
  6. Numerical limits. Overflow, an excessively small admissible step, and exhaustion of the iteration limit are reported as calculation limitations rather than replaced with a plausible-looking answer.

Serious optimization of badly scaled or large problems generally requires other methods and additional diagnostics. But for seeing the gradient, step, and trajectory in action, this small method is remarkably instructive.


  1. Kasra Khosoussi, MIT 16.485, Unconstrained Optimization and Least Squares: gradient, descent direction, necessary stationarity condition, local and global minima, exact and inexact line search. ↩ ↩ ↩

  2. Cornell University, Computational Optimization Open Textbook, Line search methods: exact line search, the Armijo condition, and backtracking. ↩ ↩

  3. Larry Armijo, Minimization of functions having Lipschitz continuous first partial derivatives, Pacific Journal of Mathematics, 16(1), 1966: modified steepest descent with step reduction. ↩

  4. Paige Bright, Alan Edelman, Steven G. Johnson, MIT 18.S096, Matrix Calculus (for Machine Learning and Beyond): finite differences, forward-mode automatic differentiation, and value–derivative pairs. ↩

URL copied to clipboard
PLANETCALC, Steepest descent method

Comments