Enter your values
Minimize a quadratic function
Follow gradient descent from a starting point and compare it with the exact minimizer.
Objective and run settings
A constant learning rate converges for this positive-definite quadratic when 0 < η < 2/λmax(H). The calculator checks this bound before iterating.
What is a gradient descent calculator?
Gradient descent is an iterative optimization method that moves a point in the direction opposite the objective's gradient. For a differentiable function f, each update is xₙ₊₁ = xₙ − η∇f(xₙ), where η is the learning rate. This calculator applies the method to a two-variable positive-definite quadratic, for which the exact minimizer can also be found by solving ∇f = 0.
Important terms
- Objective function
- The function f(x,y) whose value the optimization method attempts to minimize.
- Gradient
- The vector of first partial derivatives, ∇f = (∂f/∂x, ∂f/∂y). It points in the direction of steepest local increase.
- Learning rate
- The positive step size η used to scale each move opposite the gradient.
- Hessian
- The matrix of second partial derivatives. For a quadratic it is constant and describes curvature and the convergence limit.
- Convergence
- Here, the iteration is considered converged when the Euclidean gradient norm is no greater than the entered tolerance.
When this method is useful
- See how an initial point and learning rate affect an optimization path.
- Compare iterative gradient descent with the exact minimum of a quadratic model.
- Study why steep curvature or a large learning rate can slow or destabilize updates.
Formula and variables
- a, b, c
- Quadratic coefficients. They form the Hessian H = [[a,b],[b,c]].
- d, e
- Linear coefficients for x and y.
- k
- Constant offset; it shifts objective values but does not change the minimizer or gradient.
- η
- Learning rate, required here to satisfy 0 < η < 2/λmax(H).
- (x₀,y₀)
- Starting point for the iteration.
- λmax(H)
- Largest Hessian eigenvalue, used for the fixed-step convergence bound.
The gradient is ∇f(x,y) = (ax + by + d, bx + cy + e). The Hessian H = [[a,b],[b,c]] must be positive definite (a > 0 and ac − b² > 0), which gives this quadratic a unique global minimum. For fixed-step gradient descent on a positive-definite quadratic, the update converges when 0 < η < 2/λmax(H). The stopping test uses the Euclidean norm ‖∇f‖₂.
Domain note: This tool handles real-valued, strictly convex quadratic objectives in two variables with a constant learning rate. It is not a general-purpose optimizer for arbitrary functions, constraints, stochastic gradients, or adaptive learning-rate schedules. The convergence bound is a sufficient stability condition for this quadratic model; the requested tolerance may still require more iterations than the selected limit.
How to use this calculator
- 1
Enter the coefficients of f(x,y) = 1/2 ax² + bxy + 1/2 cy² + dx + ey + k, plus the starting coordinates (x₀,y₀).
- 2
Choose a learning rate η, a gradient-norm tolerance, and a maximum number of updates.
- 3
The calculator checks that H = [[a,b],[b,c]] is positive definite and verifies η < 2/λmax(H).
- 4
At each iteration, compute ∇f(xₙ,yₙ) = (axₙ + byₙ + d, bxₙ + cyₙ + e), then subtract η times each gradient component from the current coordinates.
- 5
Stop when ‖∇f(xₙ,yₙ)‖₂ ≤ tolerance or when the iteration limit is reached. The output shows the path, iterate table, final objective value, and exact minimizer for comparison.
Step-by-step examples
Example 1
Problem: Minimize f(x,y) = x² + 2y² − 6x + 8y + 11 from (−2,3), using η = 0.2 and tolerance 0.0001.
Substitution: Here a = 2, b = 0, c = 4, d = −6, and e = 4. Thus ∇f = (2x − 6, 4y + 4), and H = [[2,0],[0,4]] has λmax = 4. The learning-rate limit is 2/4 = 0.5, so η = 0.2 is below the bound. Solving ∇f = 0 gives the exact minimizer (3,−1).
Result: The exact minimum is f(3,−1) = 2. Gradient descent starts at (−2,3) and repeatedly applies (xₙ₊₁,yₙ₊₁) = (xₙ,yₙ) − 0.2(2xₙ−6, 4yₙ+4) until the gradient norm meets the tolerance or the iteration limit is reached.
The iterates approach (3,−1), while the objective approaches 2. The displayed table lets you see how both coordinates and the gradient norm change at each update; finite precision can make the final displayed coordinates differ slightly from the exact solution.
Example 2
Problem: Use f(x,y) = 2x² + xy + 3/2 y² − 5x − 7y + 2, starting at (−3,4).
Substitution: The Hessian is [[4,1],[1,3]] and its determinant is 11 > 0, so it is positive definite. Solving ∇f = (4x+y−5, x+3y−7) = (0,0) gives (x*,y*) = (8/11,23/11).
Result: With a stable learning rate below 2/λmax(H), the iterates approach (8/11,23/11).
The nonzero mixed coefficient b couples the coordinates: an update in x depends on y and an update in y depends on x.
Example 3
Problem: For f(x,y) = 1/2 x² + 6y² − 4x + 24y, compare the curvature in each coordinate.
Substitution: The Hessian is diagonal with eigenvalues 1 and 12. Therefore the fixed learning rate must satisfy 0 < η < 1/6. The exact minimizer is (4,−2).
Result: A learning rate at or above 1/6 fails the calculator's convergence check for this quadratic.
The large difference between eigenvalues creates a narrow valley; the steep direction controls the maximum safe fixed step size.
Rules, edge cases, and related ideas
The gradient controls the update
The gradient points uphill locally, so subtracting a positive multiple of it moves downhill for sufficiently small steps.
Curvature controls the safe step
A large maximum Hessian eigenvalue means steeper curvature and a smaller permitted fixed learning rate.
Tolerance and iteration limit are different
Tolerance defines the stopping accuracy, while the iteration limit caps the amount of computation. Reaching the cap does not imply convergence.
Edge cases and limitations
- A non-positive-definite Hessian is rejected because the objective would not have the unique global minimum this calculator is designed to analyze.
- A learning rate at or above 2/λmax is rejected to avoid unstable fixed-step iterations.
- If the starting point already meets the gradient tolerance, the calculator reports convergence with zero updates.
- An iteration can reach its limit before satisfying the tolerance; that outcome is explicitly marked as not converged.
- If arithmetic becomes non-finite during iteration, the tool stops and asks for smaller inputs or a lower learning rate.
How this differs from a related concept
Gradient descent uses repeated first-order updates and is useful for understanding iterative optimization. For a strictly convex quadratic, solving the linear system ∇f = 0 gives the exact minimizer directly. This calculator shows both: the iterative path is the method being studied, while the exact solution is a reference check.
Understand the result
A converged result means the gradient norm is at or below the chosen tolerance, not that a finite-precision iterate is symbolically identical to the exact minimizer. If the iteration limit is reached first, the last iterate remains a useful approximation but must be identified as unconverged.
Common mistakes
- Using a learning rate that is too large; the iterates can overshoot or diverge even when the objective has a clear minimum.
- Assuming that reaching the maximum number of iterations means the tolerance was met.
- Treating the constant k as if it changed the gradient. It shifts f values but does not affect the minimizer.
- Forgetting the mixed-term contribution bxy in both gradient components.
- Interpreting the trajectory plot as a contour plot. It shows iteration points and the exact minimizer, not objective level curves.
Frequently asked questions
What does this gradient descent calculator optimize?
It minimizes a strictly convex quadratic function of two real variables using a fixed learning rate and gradient descent updates.
Why must the Hessian be positive definite?
Positive definiteness guarantees a unique global minimum for the quadratic, which allows the tool to validate the model and compare the iteration with an exact minimizer.
How is the maximum learning rate calculated?
The calculator finds the largest eigenvalue λmax of the symmetric Hessian and requires 0 < η < 2/λmax.
What does the tolerance measure?
It is the stopping threshold for the Euclidean gradient norm ‖∇f(xₙ,yₙ)‖₂. A smaller tolerance generally requires more updates.
Why can the tool say the iteration limit was reached?
The chosen maximum number of updates may be too small to reach the requested tolerance. The last iterate is shown and clearly marked as not converged.
Does the constant term k change the minimizing coordinates?
No. k shifts every objective value by the same amount and does not appear in the gradient, so it changes the minimum value but not its location.