Skip to main content
Mathematics LibreTexts

10.8: Constrained Optimization - Lagrange Multipliers

  • Page ID
    108019
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Motivating Questions
    • What geometric condition enables us to optimize a function \(f=f(x,y)\) subject to a constraint given by \(g(x,y) = k\text{,}\) where \(k\) is a constant?
    • How can we exploit this geometric condition to find the extreme values of a function subject to a constraint?

    We previously considered how to find the extreme values of functions on both unrestricted domains and on closed, bounded domains. Other types of optimization problems involve maximizing or minimizing a quantity subject to an external constraint. In these cases the extreme values frequently won't occur at the points where the gradient is zero, but rather at other points that satisfy an important geometric condition. These problems are often called constrained optimization problems and can be solved with the method of Lagrange Multipliers, which we study in this section.

    Preview Activity \(\PageIndex{1}\)

    According to U.S. postal regulations, the girth plus the length of a parcel sent by mail may not exceed 108 inches, where by “girth” we mean the perimeter of the smallest end. Our goal is to find the largest possible volume of a rectangular parcel with a square end that can be sent by mail. (We solved this applied optimization problem in single variable Active Calculus, so it may look familiar. We take a different approach in this section, and this approach allows us to view most applied optimization problems from single variable calculus as constrained optimization problems, as well as provide us tools to solve a greater variety of optimization problems.) If we let \(x\) be the length of the side of one square end of the package and \(y\) the length of the package, then we want to maximize the volume \(f(x,y) = x^2y\) of the box subject to the constraint that the girth (\(4x\)) plus the length (\(y\)) is as large as possible, or \(4x+y = 108\text{.}\) The equation \(4x + y = 108\) is thus an external constraint on the variables.

    1. The constraint equation involves the function \(g\) that is given by

      \[ g(x,y) = 4x+y. \nonumber \]

      Explain why the constraint is a contour of \(g\text{,}\) and is therefore a two-dimensional curve.

    fig_10_8_postal.svg

    1. Figure \(\PageIndex{1}\). Contours of \(f\) and the constraint equation \(g(x,y) = 108\text{.}\)
    2. Figure \(\PageIndex{1}\) shows the graph of the constraint equation \(g(x,y) = 108\) along with a few contours of the volume function \(f\text{.}\) Since our goal is to find the maximum value of \(f\) subject to the constraint \(g(x,y) = 108\text{,}\) we want to find the point on our constraint curve that intersects the contours of \(f\) at which \(f\) has its largest value.
      1. Points \(A\) and \(B\) in Figure \(\PageIndex{1}\) lie on a contour of \(f\) and on the constraint equation \(g(x,y) = 108\text{.}\) Explain why neither \(A\) nor \(B\) provides a maximum value of \(f\) that satisfies the constraint.
      2. Points \(C\) and \(D\) in Figure \(\PageIndex{1}\) lie on a contour of \(f\) and on the constraint equation \(g(x,y) = 108\text{.}\) Explain why neither \(C\) nor \(D\) provides a maximum value of \(f\) that satisfies the constraint.
      3. Based on your responses to parts i. and ii., draw the contour of \(f\) on which you believe \(f\) will achieve a maximum value subject to the constraint \(g(x,y) = 108\text{.}\) Explain why you drew the contour you did.
    3. Recall that \(g(x,y) = 108\) is a contour of the function \(g\text{,}\) and that the gradient of a function is always orthogonal to its contours. With this in mind, how should \(\nabla f\) and \(\nabla g\) be related at the optimal point? Explain.

    Constrained Optimization and Lagrange Multipliers

    In Preview Activity \(\PageIndex{1}\), we considered an optimization problem where there is an external constraint on the variables, namely that the girth plus the length of the package cannot exceed 108 inches. We saw that we can create a function \(g\) from the constraint, specifically \(g(x,y) = 4x+y\text{.}\) The constraint equation is then just a contour of \(g\text{,}\) \(g(x, y) = c\text{,}\) where \(c\) is a constant (in our case 108). Figure \(\PageIndex{2}\) illustrates that the volume function \(f\) is maximized, subject to the constraint \(g(x, y) = c\text{,}\) when the graph of \(g(x, y) = c\) is tangent to a contour of \(f\text{.}\) Moreover, the value of \(f\) on this contour is the sought maximum value.

    Figure \(\PageIndex{2}\). Contours of \(f\) and the constraint contour.

    To find this point where the graph of the constraint is tangent to a contour of \(f\text{,}\) recall that \(\nabla f\) is perpendicular to the contours of \(f\) and \(\nabla g\) is perpendicular to the contour of \(g\text{.}\) At such a point, the vectors \(\nabla g\) and \(\nabla f\) are parallel, and thus we need to determine the points where this occurs. Recall that two vectors are parallel if one is a nonzero scalar multiple of the other, so we therefore look for values of a parameter \(\lambda\) that make

    \[ \nabla f = \lambda \nabla g.\label{eq_10_8_Lagrange_ex1}\]

    The constant \(\lambda\) is called a Lagrange multiplier.

    To find the values of \(\lambda\) that satisfy Equation \ref{eq_10_8_Lagrange_ex1} for the volume function in Preview Activity \(\PageIndex{1}\), we calculate both \(\nabla f\) and \(\nabla g\text{.}\) Observe that

    \[ \nabla f = 2xy \mathbf{i} + x^2 \mathbf{j} \ \ \ \ \text{ and } \ \ \ \ \nabla g = 4\mathbf{i} + \mathbf{j}, \nonumber \]

    and thus we need a value of \(\lambda\) so that

    \[ 2xy \mathbf{i} + x^2 \mathbf{j} = \lambda(4\mathbf{i} + \mathbf{j}). \nonumber \]

    Equating components in the most recent equation and incorporating the original constraint, we have three equations

    \begin{align} 2xy & = \lambda (4) \label{eq_10_8_lag_ex1}\\[4pt] x^2 & = \lambda (1) \label{eq_10_8_lag_ex2}\\[4pt] 4x+y & = 108 \label{eq_10_8_lag_ex3} \end{align}

    in the three unknowns \(x\text{,}\) \(y\text{,}\) and \(\lambda\text{.}\) First, note that if \(\lambda = 0\text{,}\) then Equation \ref{eq_10_8_lag_ex2} shows that \(x=0\text{.}\) From this, Equation \ref{eq_10_8_lag_ex3} tells us that \(y = 108\text{.}\) So the point \((0,108)\) is a point we need to consider. Next, provided that \(\lambda \neq 0\) (from which it follows that \(x \neq 0\) by Equation \ref{eq_10_8_lag_ex2}, we may divide both sides of Equation \ref{eq_10_8_lag_ex1} by the corresponding sides of Equation \ref{eq_10_8_lag_ex2} to eliminate \(\lambda\text{,}\) and thus find that

    \begin{align*} \frac{2y}{x} & = 4, \ \mbox{so}\\[4pt] y & = 2x. \end{align*}

    Substituting into Equation \ref{eq_10_8_lag_ex3} gives us

    \[ 4x+2x = 108 \nonumber \]

    or

    \[ x = 18. \nonumber \]

    Thus we have \(y = 2x = 36\) and \(\lambda = x^2 = 324\) as another point to consider. So the points at which the gradients of \(f\) and \(g\) are parallel, and thus at which \(f\) may have a maximum or minimum subject to the constraint, are \((0,108)\) and \((18,36)\text{.}\) By evaluating the function \(f\) at these points, we see that we maximize the volume when the length of the square end of the box is 18 inches and the length is 36 inches, for a maximum volume of \(f(18,36) = 11664\) cubic inches. Since \(f(0,108) = 0\text{,}\) we obtain a minimum value at this point.

    We summarize the process of Lagrange multipliers as follows.

    The method of Lagrange multipliers

    The general technique for optimizing a function \(f = f(x,y)\) subject to a constraint \(g(x,y)=c\) is to solve the system \(\nabla f = \lambda \nabla g\) and \(g(x,y)=c\) for \(x\text{,}\) \(y\text{,}\) and \(\lambda\text{.}\) We then evaluate the function \(f\) at each point \((x,y)\) that results from a solution to the system in order to find the optimum values of \(f\) subject to the constraint.

    Activity \(\PageIndex{2}\)

    A cylindrical soda can holds about 355 cc of liquid. In this activity, we want to find the dimensions of such a can that will minimize the surface area. For the sake of simplicity, assume the can is a perfect cylinder.

    1. What are the variables in this problem? Based on the context, what restriction(s), if any, are there on these variables?
    2. What quantity do we want to optimize in this problem? What equation describes the constraint? (You need to decide which of these functions plays the role of \(f\) and which plays the role of \(g\) in our discussion of Lagrange multipliers.)
    3. Find \(\lambda\) and the values of your variables that satisfy Equation \ref{eq_10_8_Lagrange_ex1} in the context of this problem.
    4. Determine the dimensions of the pop can that give the desired solution to this constrained optimization problem.

    The method of Lagrange multipliers also works for functions of more than two variables.

    Activity \(\PageIndex{3}\)

    Use the method of Lagrange multipliers to find the dimensions of the least expensive packing crate with a volume of 240 cubic feet when the material for the top costs $2 per square foot, the bottom is $3 per square foot and the sides are $1.50 per square foot.

    The method of Lagrange multipliers also works for functions of three variables. That is, if we have a function \(f = f(x,y,z)\) that we want to optimize subject to a constraint \(g(x,y,z) = k\text{,}\) the optimal point \((x,y,z)\) lies on the level surface \(S\) defined by the constraint \(g(x,y,z) = k\text{.}\) As we did in Preview Activity \(\PageIndex{1}\), we can argue that the optimal value occurs at the level surface \(f(x,y,z) = c\) that is tangent to \(S\text{.}\) Thus, the gradients of \(f\) and \(g\) are parallel at this optimal point. So, just as in the two variable case, we can optimize \(f = f(x,y,z)\) subject to the constraint \(g(x,y,z) = k\) by finding all points \((x,y,z)\) that satisfy \(\nabla f = \lambda \nabla g\) and \(g(x,y,z) = k\text{.}\)

    Summary

    • The extrema of a function \(f=f(x,y)\) subject to a constraint \(g(x,y) = c\) occur at points for which the contour of \(f\) is tangent to the curve that represents the constraint equation. This occurs when
      \[ \nabla f = \lambda \nabla g. \nonumber \]
    • We use the condition \(\nabla f = \lambda \nabla g\) to generate a system of equations, together with the constraint \(g(x,y) = c\text{,}\) that may be solved for \(x\text{,}\) \(y\text{,}\) and \(\lambda\text{.}\) Once we have all the solutions, we evaluate \(f\) at each of the \((x,y)\) points to determine the extrema.

    This page titled 10.8: Constrained Optimization - Lagrange Multipliers is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Matthew Boelkins, David Austin & Steven Schlicker (ScholarWorks @Grand Valley State University) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.