Lagrange Multiplier Calculator

Free Lagrange multiplier calculator. Maximise or minimise f subject to a constraint g = c, in two or three variables. Get every critical point, the multiplier λ, and which point is the maximum and which the minimum.

Optimise a function subject to a constraint. Enter the objective f, the constraint g and its value c, and the calculator solves ∇f = λ∇g together with g = c, listing every critical point, its multiplier, and whether it is a maximum or a minimum.

The quantity to maximise or minimise

Left-hand side of g = c

Right-hand side

Try an example

How to use Lagrange multipliers

  1. 1

    Identify f and g

    f is what you are optimising; g = c is the restriction. Write both in the same variables.

  2. 2

    Set the gradients parallel

    Write ∂f/∂x = λ∂g/∂x and the same for every other variable.

  3. 3

    Add the constraint

    Include g = c so the number of equations matches the number of unknowns, counting λ.

  4. 4

    Solve and compare

    Solve the system for every solution, then evaluate f at each point — the largest is the maximum and the smallest the minimum.

The geometry behind the method

Picture the level curves of f drawn on top of the constraint curve g = c. Walking along the constraint, you cross level curve after level curve, and f keeps changing. The value of f can only stop changing where the constraint curve touches a level curve instead of crossing it — that is, where the two are tangent.

Tangency of the curves means their normals point the same way. The normal to a level curve of f is ∇f, and the normal to the constraint is ∇g, so tangency is exactly the statement ∇f = λ∇g. The multiplier λ is just how much longer one gradient is than the other.

This also explains why the method finds minima as well as maxima, and occasionally points that are neither: tangency is a necessary condition for an extremum, not a sufficient one. Always compare the f values at the end.

Worked problems

Where the method is used

Economics Maximise utility subject to a budget; λ is the marginal utility of income.
Physics Derive equilibrium shapes and constrained motion; λ becomes the constraint force.
Machine learning Support vector machines and regularised regression are constrained optimisations solved this way.
Statistics Maximum entropy distributions come from maximising entropy subject to moment constraints.
Engineering Minimise weight or cost subject to a strength or volume requirement.
Geometry Find the closest point on a surface to a given point, or the largest box inside an ellipsoid.

Frequently asked questions

What is a Lagrange multiplier?

It is the scalar λ in the condition ∇f = λ∇g. At a constrained optimum, the gradient of the objective must be parallel to the gradient of the constraint — otherwise you could still move along the constraint surface and improve f. The multiplier is the ratio between those two gradients.

How does the method of Lagrange multipliers work?

To optimise f subject to g = c, solve the system ∇f = λ∇g together with g = c. In two variables that is three equations (∂f/∂x = λ∂g/∂x, ∂f/∂y = λ∂g/∂y, and g = c) in three unknowns x, y and λ. Every solution is a candidate; compare their f values to see which is the maximum and which the minimum.

What does the multiplier λ actually mean?

It is the sensitivity of the optimal value to the constraint. Raising c by one unit changes the optimum of f by approximately λ. Economists call this the shadow price — the most you would pay for one more unit of a scarce resource.

Why does ∇f have to be parallel to ∇g?

∇f points in the direction where f increases fastest. If any part of that direction lay along the constraint surface, you could slide that way and increase f while staying feasible, so you would not be at an optimum. That only fails to be possible when ∇f is entirely perpendicular to the surface — that is, parallel to ∇g.

Does the method always give the global maximum?

Not necessarily. It finds stationary points of the constrained problem. If the constraint set is closed and bounded, the largest and smallest values among the candidates are the global extremes. On an unbounded set — a hyperbola or a plane, say — f may have no global maximum at all, and the points found are local.

What if there are two constraints?

You need one multiplier per constraint: ∇f = λ∇g + μ∇h, together with both constraint equations. This calculator handles a single constraint in two or three variables, which covers the standard coursework cases.

About this Calculator

Free Lagrange multiplier calculator. Maximise or minimise f subject to a constraint g = c, in two or three variables. Get every critical point, the multiplier λ, and which point is the maximum and which the minimum.

Related Searches

lagrange multiplier calculatorlagrange multiplierlagrange multipliersconstrained optimization calculatormaximize subject to constraintlagrange multiplier methodlambda multiplier