Example data table
These sample inputs reproduce a classic constrained optimum.
| Mode | Objective f(x,y) | Constraint g(x,y)=0 | Expected best point |
|---|---|---|---|
| Minimize | x^2 + y^2 | x + y - 1 | x=0.5, y=0.5 |
| Maximize | x*y | x + y - 10 | x=5, y=5 |
| Minimize | (x-2)^2 + (y+1)^2 | x^2 + y^2 - 4 | Closest point on circle |
Formula used
The method builds a Lagrangian L(x,y,λ)=f(x,y)−λ·g(x,y) and solves the system: ∂L/∂x=0, ∂L/∂y=0, and g(x,y)=0. Derivatives are approximated by central differences, then Newton’s method refines (x,y,λ).
- KKT stationarity: ∇f(x,y)=λ∇g(x,y)
- Feasibility: g(x,y)=0
- Residual: ||[∂L/∂x, ∂L/∂y, g]||
How to use this calculator
- Choose maximize or minimize.
- Enter f(x,y) and your constraint g(x,y)=0.
- Set an initial guess, then enable multi-start if needed.
- Press Solve to see results above this form.
- Download CSV or PDF from the result panel.
FAQs
1) What problems does this solver handle?
It solves two-variable optimization with one equality constraint. You can model many textbook Lagrange multiplier tasks using x and y expressions safely.
2) Why do I get no convergence sometimes?
Newton steps can fail near flat gradients or singular Jacobians. Try a different initial guess, increase the multi-start range, or relax tolerance slightly.
3) Does it guarantee a global optimum?
No. It finds stationary points that satisfy KKT conditions. Use multiple starts and compare objective values to increase confidence in the best solution.
4) What functions can I type?
Use + − * / ^, parentheses, x, y, and common functions like sin, cos, tan, sqrt, log, exp, abs. Unsupported tokens are blocked for safety.
5) How should I write the constraint?
Write it as a single expression equal to zero. Example: for x+y=10, enter x+y-10. For x²+y²=1, enter x^2+y^2-1.
6) What does the residual value mean?
Residual measures how closely the solution satisfies stationarity and feasibility. Smaller residual usually means a more accurate stationary point for your constraint.
7) How do I interpret multiple solutions?
Some problems have several stationary points. Sort by objective value for your mode, then validate with second-derivative reasoning or plotting if needed.