Lagrange Multiplier Calculator

Enter an objective and up to two constraints written as equations. The tool builds ∇f = λ∇g, solves the system from many starting points, lists every critical point with exact values where it can and ranks them.

Berjalan dalam pelayar anda. Fail anda tidak pernah meninggalkan peranti. Lihat cara menyemaknya

…

Cara melakukannya

  1. 1
    Enter the objective

    Type the function f you want to maximise or minimise.

  2. 2
    Add the constraint

    Write it as an equation; add a second one if needed.

  3. 3
    Set the search box

    Choose a box size that contains the points you expect.

  4. 4
    Read the points

    See every critical point, its multipliers and the value of f.

  5. 5
    Check the type

    Read the restricted Hessian or bordered Hessian verdict for each point.

  6. 6
    See the picture

    Use the contour map, then copy, download or print the working.

Tentang alat ini

Many optimisation problems come with a condition attached. Make a box with the largest volume for a fixed amount of card, find the point of an ellipse nearest the origin, or spend a budget to get the most output from labour and capital. The method of Lagrange multipliers turns such a problem into a system of equations: at a constrained extremum the gradient of the objective f is parallel to the gradient of the constraint g, so ∇f = λ∇g for some number λ, and the constraint itself must hold. With two constraints a second multiplier μ joins in. This calculator writes out the Lagrangian L = f − λg − μh, differentiates it symbolically and shows every equation, including the constraints. Solving those equations by hand is the step that usually goes wrong, because the system is nonlinear and it is easy to divide by zero and lose a solution. The tool solves it with Newton's method started from hundreds of seeded points in a search box you control, removes duplicates and recognises coordinates that match fractions, square roots or multiples of π to ten digits, so (√5/5, 2√5/5) appears as you would write it in an exam. Every point is substituted back into f, the largest and smallest values are highlighted, and each point gets a second-order check: the Hessian of the Lagrangian is restricted to the tangent space of the constraints and its eigenvalues decide between a local maximum, a local minimum and a saddle along the constraint. For two variables and one constraint the classic bordered Hessian determinant is shown as well. For two variables a contour map draws level curves of f, the constraint curve and the gradients at each point, which makes the tangency condition visible.

Reading the answer

The answer panel counts the critical points, quotes the largest and smallest values of f and lists each point with its multipliers in a table. Rows for the maximum and minimum are tinted. The working panel follows the order a lecturer would use: the Lagrangian, the gradients, the equations, the solutions, the values of f and the second-order check. On the contour map the red curve is the constraint, blue level curves pass through critical points and the green and red arrows are ∇f and ∇g; at every critical point they line up. For three variables the points are shown in a rotatable 3D view.

Worked example

Find the extremes of f = x + 2y on the unit circle x² + y² = 1. The Lagrangian is x + 2y − λ(x² + y² − 1). The equations are 1 = 2λx, 2 = 2λy and x² + y² = 1. The tool finds two solutions. At (√5/5, 2√5/5) with λ = √5/2 the value is f = √5 ≈ 2.236, the maximum. At (−√5/5, −2√5/5) with λ = −√5/2 the value is −√5, the minimum. At the minimum the bordered Hessian determinant is −4√5, negative, which confirms a local minimum, and the restricted Hessian eigenvalue there is √5. The ellipse example x² + xy + y² = 3 gives a largest value 6 of x² + y² at (√3, −√3) and (−√3, √3) and a smallest value 2 at (1, 1) and (−1, −1).

Limits

The largest and smallest values among the critical points are the true maximum and minimum only when the constraint set is closed and bounded; on a line or a plane the function may grow without limit. Points where the constraint gradients vanish or are parallel are not covered by the multiplier rule and must be checked separately. Newton's method may not find a solution outside the search box, so widen it if you expect large coordinates.

Contoh berselesaian

f = x + 2y on x² + y² = 1: maximum √5 at (√5/5, 2√5/5) with λ = √5/2, minimum −√5 at (−√5/5, −2√5/5).

Ringkasnya

Soalan lazim

How do I type a constraint?

As an equation such as x^2 + y^2 = 1 or 2*x + 2*y + z = 12. An expression without an equals sign is read as expression = 0.

When do I need a second constraint?

When the point must satisfy two conditions at once, such as lying on a plane and on a cylinder. The tool then adds a second multiplier μ and solves for both.

What does the value of λ mean?

λ is the rate at which the optimal value of f changes when the constant in the constraint increases by one. In economics it is the shadow price of the budget.

Why does the tool say "saddle on the constraint"?

Moving along the constraint in one direction increases f and in another decreases it, so the point is neither a maximum nor a minimum even though ∇f is parallel to ∇g.

Are the exact values guaranteed?

They are recognised from a converged numeric solution and accepted only when substituting them back leaves a residual below one billionth. Values that do not match a simple form are shown as decimals.

Can I use more than three variables?

Yes, up to four variables with one or two constraints. The contour map appears only for two variables and the 3D view for three.

Percuma sepenuhnyaTiada bayaran, tiada pendaftaran
Fail kekal peribadiSemuanya berjalan dalam pelayar anda
Mudah dalam bahasa andaTersedia dalam banyak bahasa