Lagrange Multipliers
Lagrange Multipliers
Solve lagrange(f, g, x, y) or lagrange(f, g, x, y, z). The unit circle has global maximum 1/2 and global minimum -1/2. The line x+y=10 has minimum 50 or maximum 25, and the other side is unbounded. In three variables, (4, 4, 4) is a local maximum of 64, not a global maximum.
Solve Equation accepts lagrange(x*y,x^2+y^2-1,x,y). The gradients are (y, x) and (2*x, 2*y). The system y = λ*2*x, x = λ*2*y, and x^2+y^2 = 1 has four real solutions. The points (sqrt(2)/2, sqrt(2)/2) and (-sqrt(2)/2, -sqrt(2)/2) give the global maximum 1/2. The points (sqrt(2)/2, -sqrt(2)/2) and (-sqrt(2)/2, sqrt(2)/2) give the global minimum -1/2. Each constraint residual is 0.
lagrange(x^2+y^2,x+y-10,x,y) has global minimum 50 at (5, 5) and no global maximum, because the objective is unbounded above on the line. lagrange(x*y,x+y-10,x,y) has global maximum 25 at (5, 5) and no global minimum. lagrange(x*y*z,x+y+z-12,x,y,z) finds (4, 4, 4) with value 64, a local maximum, and the intercepts (12, 0, 0), (0, 12, 0), and (0, 0, 12) with value 0, which are saddles. The product is unbounded above and below on that plane, so 64 is not a global maximum. The steps list both gradients, the multiplier, and the constraint check.
Equation
lagrange(x*y,x^2+y^2-1,x,y)
When a Lagrange candidate is an optimum
Lagrange multipliers locate stationary candidates of an objective f subject to one equality constraint g = 0. The condition is ∇f = λ∇g together with g = 0. DGS forms those equations from the existing symbolic derivative, solves them with the existing symbolic solver, and keeps exact real solutions. A point is kept only after it satisfies the constraint. A point where the gradient of g is zero is degenerate: the multiplier theorem does not apply there, and that point is not forced through the regular system.
A stationary candidate is not automatically a maximum or a minimum. The second-derivative test on the tangent plane classifies a regular point as a local maximum, a local minimum, a saddle, or inconclusive. A global claim is added only when a separate argument proves it, such as a compact constraint with a complete stationary list, a constant objective, a finite feasible set, or a one-variable reduction of an affine constraint. When the objective is unbounded on the constraint, the result says which side has no global extreme. When that proof is missing, the classification stays inconclusive.
Reading the input
lagrange(x*y,x^2+y^2-1,x,y)— This is a command. The name selects the routine, and the items inside the parentheses are its arguments.
Other versions of this example
These stay on this page so each version keeps the same explanation. Choose Try example to run a version in its Studio workflow, or copy it into the editable field below.
Circle constraint
Global maximum 1/2 and global minimum -1/2 on the unit circle.
lagrange(x*y,x^2+y^2-1,x,y)
Minimum distance
Global minimum 50 at (5, 5). There is no global maximum.
lagrange(x^2+y^2,x+y-10,x,y)
Product optimization
Global maximum 25 at (5, 5). There is no global minimum.
lagrange(x*y,x+y-10,x,y)
Three variables
(4, 4, 4) has value 64 and is a local maximum, not a global maximum. The other stationary candidates are saddles. The objective is unbounded above and below.
lagrange(x*y*z,x+y+z-12,x,y,z)
Try a change
- Change the unit-circle objective from x*y to x^2+y^2 and generate again. The objective equals 1 at every feasible point, so that constant is both the maximum and the minimum.
- For the three-variable product, compare 64 at (4, 4, 4) with the feasible point (24, -6, -6). The product 864 is larger, so 64 is only a local maximum.
Solve Equation shows both gradients, the system ∇f = λ∇g with g = 0, each real stationary candidate, the constraint residual, and the local or global classification. A step is printed only after that calculation. An inconclusive global status is stated rather than called an optimum.