Textbooks/Engineering Design and Optimization/Chapter 8Lite (plain text) version
8Gradient methods and convexity
Version 1 · Technically checked (automated checks only) · 3 source lessons · 8 practice items
Introduction
Gradient descent is the workhorse of modern optimisation, from tuning controllers to training networks. This chapter studies it closely: how the learning rate decides between creeping, zig-zagging and exploding, why convex problems have a single answer that descent will find, how Newton's method and momentum go faster, and how constraints such as a motor's current limit are handled with penalties or by building them into the problem.
Explanation
This chapter is built from 3 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.
8.1 Gradient descent and the learning rate
Blindfolded on a hillside, you can only feel the slope under your feet. How big should each step downhill be?
The update
The gradient ∇f points uphill, steepest. Gradient descent steps the other way: x ← x − η∇f(x). η, the learning rate or step size, scales the step. Repeat until the gradient is (nearly) zero or progress stalls.
Too small, too big, just right
Too small: correct but painfully slow. Too big: overshoot, oscillate, diverge. For a quadratic the boundary is exact: η < 2/L. In practice, start small, increase until the loss stops falling smoothly, then back off; or use a line search that picks η each step.
Narrow valleys
When curvature differs a lot between directions (an ill-conditioned problem), the steep direction limits η and the shallow direction then moves slowly: the zig-zag path in the explorer. Rescaling variables (preconditioning), momentum, or second-order methods fix this.
Derivation: When does gradient descent converge on a quadratic?
Take f(x) = ½·a·x² with a > 0. Then f'(x) = a·x and the update is x_{k+1} = x_k − η·a·x_k = (1 − ηa)·x_k.
So x_k = (1 − ηa)^k · x₀: a geometric sequence. It shrinks to 0 if and only if |1 − ηa| < 1, i.e. 0 < η < 2/a.
Fastest: η = 1/a gives 1 − ηa = 0: one step. For 1/a < η < 2/a it overshoots and oscillates but still converges.
In two dimensions, f = ½(a₁x² + a₂y²) gives two independent factors (1 − ηa₁) and (1 − ηa₂). Stability needs η < 2/max(aᵢ).
With η limited by the steep direction, the shallow direction shrinks by (1 − a_min/a_max) per step at best. The condition number κ = a_max/a_min sets the pace: κ = 100 means about 100 steps per factor e.
For a general smooth f, L (the largest curvature, the Lipschitz constant of the gradient) plays the role of a_max: η < 2/L.
Common mix-ups
- A bigger learning rate always gets there faster.
✓ Beyond 2/L it diverges, and between 1/L and 2/L it oscillates. - Gradient descent finds the global minimum.
✓ On convex functions any minimum is global; on non-convex ones it finds a local minimum near the start (next lesson).
Open the full lesson: Gradient descent and the learning rate →
8.2 Convexity and local minima
Two engineers run the same optimiser on the same design problem and get different answers. Who is wrong?
Convex functions
f is convex if the straight line between any two points on its graph lies on or above the graph: f(θx + (1 − θ)y) ≤ θf(x) + (1 − θ)f(y). For twice-differentiable f this means f'' ≥ 0 (in 1-D) or a positive semi-definite Hessian. x², |x|, eˣ and ½xᵀAx with A positive semi-definite are convex.
Why convexity is precious
For a convex function on a convex set, every local minimum is a global minimum, and gradient methods with a sensible step converge to it from any start. You can also certify optimality: a zero gradient proves you are done.
Living with non-convexity
Non-convex functions can have many local minima, saddle points and flat regions. Practical responses: multiple random starts (report the spread of results), good initial guesses from physics, convex relaxations that give bounds, and global methods (simulated annealing, genetic algorithms) for small problems. Never present one run of a non-convex optimiser as 'the optimum'.
Common mix-ups
- If an optimiser converges, it found the best answer.
✓ It found a stationary point. Only convexity (or a global method with proof) makes that the best. - Non-convex problems cannot be optimised.
✓ They are optimised every day; you just report local results honestly and test robustness.
8.3 Newton's method, momentum and constraints
Gradient descent takes 200 steps down a narrow valley. Newton's method takes one. What is it using that gradient descent ignores?
Second-order methods
Newton's method uses curvature to scale the step in every direction, so ill-conditioning disappears: the narrow valley looks round to it. Quasi-Newton methods (BFGS, L-BFGS) build an approximation of H⁻¹ from gradients, keeping most of the benefit at a fraction of the cost, and are the default for medium-sized smooth problems.
Momentum
Momentum keeps a running velocity: v ← βv − η∇f, x ← x + v. Along a consistent shallow direction the steps add up; across a steep gully they cancel. It is cheap, first-order, and widely used in training neural networks.
Constraints by penalty
To minimise f subject to g(x) ≤ 0, minimise f(x) + μ·max(0, g(x))². Small μ: the constraint is violated a little. Large μ: closer to feasible, but the problem becomes ill-conditioned and slow. Increase μ gradually, or use exact methods (Lagrange multipliers, projection, interior-point solvers) when feasibility is non-negotiable, such as a safety limit.
Derivation: Newton's step from a quadratic model
Near x_k, approximate f by its second-order Taylor expansion: f(x_k + d) ≈ f(x_k) + f'(x_k)·d + ½f''(x_k)·d².
Minimise the model over d: derivative f'(x_k) + f''(x_k)·d = 0, so d = −f'(x_k)/f''(x_k).
Newton update: x_{k+1} = x_k − f'(x_k)/f''(x_k). In n dimensions: x ← x − H⁻¹∇f, with H the Hessian.
It is Newton–Raphson root-finding applied to f' = 0, which you met for solving equations.
Cost: forming and solving with H is O(n²) memory and O(n³) time per step, versus O(n) for a gradient step. Trade: few expensive steps versus many cheap ones.
Caution: if f'' ≤ 0 the step can go uphill; practical methods add a line search or modify H.
Common mix-ups
- Second-order methods are always better.
✓ They take fewer steps, but each costs far more; for huge problems cheap first-order steps win. - A penalty enforces the constraint exactly.
✓ Only in the limit μ → ∞; at finite μ the solution sits slightly outside.
Open the full lesson: Newton's method, momentum and constraints →
Worked examples
Gradient descent and the learning rate: example 1
f(x) = 2(x − 3)², x₀ = 7, η = 0.1. Find x₁ and x₂.
Solution
f'(x) = 4(x − 3). x₁ = 7 − 0.1×16 = 5.4. x₂ = 5.4 − 0.1×9.6 = 4.44. Each step multiplies the distance to 3 by 1 − 0.4 = 0.6: 4 → 2.4 → 1.44 ✓.
Convexity and local minima: example 1
Is f(x) = x⁴ − 2x² convex?
Solution
f''(x) = 12x² − 4, negative for |x| < 0.577. Not convex. It has minima at x = ±1 and a local maximum at x = 0, just like the double well.
Newton's method, momentum and constraints: example 1
Newton's method on f(x) = x⁴ from x₀ = 1. Find x₁ and x₂.
Solution
f' = 4x³, f'' = 12x². Step: x − 4x³/12x² = x − x/3 = (2/3)x. x₁ = 0.667, x₂ = 0.444. Only linear here, because f'' = 0 at the minimum: Newton's quadratic speed needs f'' > 0 there.
Interactive figures
Interactive figure (online). Description: The explorer draws elliptical contours and the path of each gradient step. On f = ½(x² + 4y²) with η = 0.3, the y-coordinate shrinks by |1 − 1.2| = 0.2 per step and x by 0.7; at η = 0.6 the y-factor is |1 − 2.4| = 1.4 and the path diverges.
Laboratory
Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.
Equation Lab exploration
Equation Lab: Optimisation
Find the largest learning rate that converges on a narrow valley, then rescale the variables and find it again.
Open Equation Lab: Optimisation →Simulation OS experiment
Simulation OS: Robot joint under PID control
Tune the joint's gains by repeated small changes in the direction that reduces settling time, and record each step like a gradient method.
Open Simulation OS: Robot joint under PID control →
Guided practice
Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.
- f(x, y) = ½(3x² + 12y²). What is the largest learning rate for which gradient descent converges? (Strict upper bound.)
- Gradient descent zig-zags slowly down a long, narrow valley. The most direct cure is…
- A larger learning rate
- Rescaling the variables so the curvature is similar in every direction
- More random starting points
- Stopping earlier
- For f(x) = ½·5x², which learning rate reaches the minimum in exactly one step from any start?
- Which function is convex on all real x?
- sin x
- x³
- eˣ + x²
- x⁴ − x²
- Your optimiser returns a point with zero gradient on a convex objective. What can you conclude?
- It may be a local maximum
- It is a global minimum
- Nothing without more starts
- It is a saddle point
- You tune a robot arm design with a non-convex objective. What is the honest report?
- 'We found the optimal design.'
- 'Best of 50 random starts; 38 reached within 1% of this value; results from the other 12 are shown.'
- 'Gradient descent converged, so it is optimal.'
- Report only the best run
- For a problem with a million variables, why is plain Newton's method rarely used?
- It converges too slowly
- Storing and solving with a million-by-million Hessian is far too expensive
- It only works in 1-D
- It cannot handle convex problems
- A motor current must never exceed its rating. Which constraint method suits that best?
- A small penalty
- An exact constraint method (projection, interior-point or clamping) that guarantees feasibility
- Ignore it and check afterwards
- A random search
Engineering applications
Controller auto-tuning
Auto-tuners adjust controller gains to reduce a cost such as overshoot plus settling time. The cost surface is rarely convex, so good tuners start from several points and report the spread.
Trajectory optimisation
Robot arms plan smooth paths by minimising effort subject to joint limits. Limits that must never be broken are built in as hard constraints, not left to a penalty that might be outweighed.
Watch
Optional verified videos. Nothing loads from YouTube until you press play.
- Gradient descent, how neural networks learn | Deep Learning Chapter 2 (3Blue1Brown)
- Newton’s fractal (which Newton knew nothing about) (3Blue1Brown)
Chapter summary
- Gradient descent steps x ← x − η∇f; on a quadratic it is stable only below η = 2/λmax.
- Narrow valleys (poor conditioning) cause zig-zagging; rescaling variables helps.
- Convex functions have no local minima apart from the global one.
- Newton's method uses curvature for fast convergence but is costly in many variables; momentum is a cheap middle way.
- Hard limits belong in the constraints; penalties are for soft preferences.
Glossary
- Derivative (rate of change)
- The derivative of a quantity is its instantaneous rate of change: the gradient of its graph at a point.
- Efficiency
- Efficiency is the fraction of input energy or power that comes out as useful output. The rest becomes heat, sound or other losses.
- PID controller
- A PID controller adds proportional, integral and derivative actions: present error, accumulated past error and predicted future error.
Definitions from the Field Guide.
Project: Tune a design by descent
Choose a design with two continuous variables and a cost you can compute, such as a stand's mass with a tipping penalty. Implement gradient descent, try three learning rates and several starting points, and report the best design, whether the problem appears convex, and how sure you are.
Deliverables
- The cost function and variables
- Convergence plots for each learning rate
- The best design with a convexity and uncertainty statement
Keep your work in your Engineering Journal; it stays private unless you choose to share it.
References
- Stephen Boyd and Lieven Vandenberghe (2004). Convex Optimization. Cambridge University Press.
- Jorge Nocedal and Stephen J. Wright (2006). Numerical Optimization, 2nd edition. Springer.
Publication record
- Version
- 1
- Status
- Technically checked (automated checks only)
- Technical review
- Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
- Written by
- Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
- Licence
- All rights reserved by the founders unless a licence is approved.
- Corrections
- None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.