# Lagrange Multipliers (Optimizing a Function) • By David A. Smith, Founder & CEO, Direct Knowledge
• David Smith has a B.S. and M.S. in Mathematics and has enjoyed teaching calculus, linear algebra, and number theory at both Tarrant County College and the University of Texas at Arlington. David is the Founder and current CEO of Direct Knowledge.

In many applied problems, the main focus is on optimizing a function subject to constraint; for example, finding extreme values of a function of several variables where the domain is restricted to a level curve (or surface) of another function of several variables. Lagrange multipliers are a general method which can be used to solve such optimization problems.

## Lagrange’s Theorem

The $\lambda$ in Lagrange’s Theorem is called a Lagrange multiplier. Thus, Lagrange’s Theorem gives necessary conditions for the existence of a Lagrange multiplier.

Theorem. (Lagrange) Assume that $f$ and $g$ have continuous first partial derivatives and that $f$ has an extremum at $P_0\left(x_0,y_0\right)$ on the smooth constraint curve $g(x,y)=c.$ If $\nabla g\left(x_0,y_0\right)\neq {0},$ there is a number $\lambda$ such that \begin{equation} \label{lagmult} \nabla f\left(x_0,y_0\right)=\lambda \nabla g\left(x_0,y_0\right). \end{equation}

Proof. Denote the constraint curve $g(x,y)=c$ by $C$ and note that $C$ is smooth. We represent this curve by the vector function $${R}(t)=x(t){i}+y(t){j}$$ for all $t$ in an open interval $I,$ including $t_0$ corresponding to $P_0,$ where $x'(t)$ and $y'(t)$ exist and are continuous. Let $F(t)=f(x(t),y(t))$ for all $t$ in $I,$ and apply the chain rule to obtain \begin{align*} F'(t) & = f_x(x(t),y(t))\frac{d x}{d t}+f_y(x(t),y(t))\frac{d y}{d t} \\ & =\nabla f(x(t),y(t))\cdot {R}'(t). \end{align*} Because $f(x,y)$ has an extremum at $P_0,$ we know that $F(t)$ has an extremum at $t_0.$ Therefore, we have $F’\left(t_0\right)=0$ and $$F’\left(t_0\right)=\nabla f\left(x \left(t_0\right), y\left(t_0\right)\right)\cdot {R}’\left(t_0\right)=0.$$ If $\nabla f\left(x\left(t_0\right), y\left(t_0\right)\right)={0},$ then $\lambda =0,$ and the condition $\nabla f=\lambda \nabla g$ is satisfied trivially. If $$\nabla f\left(x \left(t_0\right),y\left(t_0\right)\right)\neq {0},$$ then $\nabla f\left(x \left(t_0\right), y\left(t_0\right)\right)$ is orthogonal to ${R}’\left(t_0\right).$ Because ${R}’\left(t_0\right)$ is tangent to the constraint curve $C$, it follows that $\nabla f\left(x_0,y_0\right)$ is normal to $C.$ But $\nabla g\left(x \left(t_0 \right), y\left(t_0\right)\right)$ is also normal to $C$ (because $C$ is a level curve of $g$), and we conclude that $\nabla f$ and $\nabla g$ must be parallel at $P_0.$ Thus, there is a scalar $\lambda$ such that \eqref{lagmult} holds.

Example. Find the extreme values of the function $f(x,y)=x^2+y$ constrained to the circle $x^2+y^2=1.$ Extreme values of the function $f(x,y)=x^2+y$ constrained to the unit circle.

Solution. Using Lagrange’s Theorem, we solve the equations $\nabla f=\lambda \nabla g,$ $g(x,y)=1,$ which can be written as $f_x=\lambda g_x,$ $f_y=\lambda g_y$, and $g(x,y)=1$ or written as \begin{align*} 2x=2x \lambda, \qquad 1=2y \lambda, \qquad \text{and} \qquad x^2+y^2=1. \end{align*} From the first equation we have $x=0$ or $\lambda =1.$ If $x=0,$ then by the third equation $y=\pm 1.$ If $\lambda =1,$ then $y=1/2$ and we obtain $x=\left.\pm \sqrt{3} \right/2.$ Therefore, $f$ has possible extreme values at the points $(0,1),$ $(0,-1),$ $\left(\left.\sqrt{3}\right/2,1/2\right),$ and $\left(\left.-\sqrt{3}\right/2,1/2\right).$ Evaluating $f$ at these four points, we find that $f(0,1)=1,$ $f(0,-1)=-1,$ and $f\left(\left.\pm \sqrt{3} \right/2,1/2\right) = 5/4.$ Therefore the maximum value of $f$ constrained to the circle $x^2+y^2=1$ is $5/4$ and the minimum value is $-1.$

## The Method of Lagrange Multipliers

Theorem. (Lagrange Multipliers) Suppose $f$ and $g$ satisfy the hypotheses of Lagrange’s theorem, and that $f$ has an extremum subject to the constraint $g(x,y)=c.$ Then to find the extreme value, proceed as follows:

(1) Simultaneously solve the following three equations for $x,y$ and $\lambda$: $f_x(x,y)=\lambda g_x(x,y),$ $f_y(x,y) = \lambda g_y(x,y),$ and $g(x,y)=c$.

(2) Evaluate $f$ at all points found in step (i). The extremum we seek must be among these values.

Example. Maximize $f(x,y)=x y$ subject to $2x+2y=5.$ Extreme values of the function $f(x,y)=x y$ subject to $2x+2y=5.$

Solution. Let $g(x,y)=2x+2y,$ then we have \begin{align*} f_x=y, \qquad f_y=x, \qquad g_x=2, \qquad \text{and} \qquad g_y=2. \end{align*} We need to solve the system \begin{align*} y=2\lambda, \qquad x=2\lambda, \qquad \text{and} \qquad 2x+2y=5. \end{align*} We find $x=y=\frac{5}{4}.$ Therefore, $f\left(\frac{5}{4},\frac{5}{4}\right)=\frac{25}{16}$ is the constrained maximum.

Example. Minimize $f(x,y,z)=x^2+y^2+z^2$ subject to $x-2y+3z=4.$

Solution. Let $g(x,y,z)=x-2y+3z,$ then we have \begin{align*} f_x=2x, \quad f_y=2y, \quad f_z=2z, \quad g_x=1, \quad g_y=-2, \quad \text{and} \quad g_z=3. \end{align*} We need to solve the system \begin{align*} 2x=\lambda, \qquad 2y=-2\lambda, \qquad 2z=3\lambda, \qquad \text{and} \qquad x-2y+3z=4. \end{align*} We find that $\lambda =\frac{4}{7}$ and then $x=\frac{2}{7},$ $y=-\frac{4}{7},$ and $z=\frac{6}{7}.$ Therefore, \begin{align*} f\left(\frac{2}{7}, -\frac{4}{7},\frac{6}{7}\right)=\frac{8}{7} \end{align*} is the constrained minimum.

Example. A rectangular box with no top is to be constructed from 96 $\text{ft}^2$ of material. What should be the dimensions of the box if it is to enclose maximum volume? Rectangular box enclosing maximum volume constructed from 96 $\text{ft}^2$ of material.

Solution. Let $x,y,$ and $z$ be the length, width, and height of the rectangular box, respectively. We want to maximize the volume: \begin{align*} V=x y z \qquad \text{subject to} \qquad S(x,y,z)=x y+2 x z+2 y z=96 \end{align*} which is obtained from the surface area of the rectangular box (with no lid). We have \begin{align*} V_x=y z, \quad V_y=x z, \quad V_z=x y, \quad S_x=y+2 z, \quad S_y=x+2 z, \quad S_z=2x+2y. \end{align*} Solve the system \begin{align*} y z=\lambda (y+2 z), \quad x z=\lambda (x+2 z), \quad x y=\lambda (2x+2 y), \quad x y+2 x z+2 y z=96. \end{align*} We obtain $x=y=2 z,$ and then find $x=y=4\sqrt{2},$ $z=2\sqrt{2}.$ Therefore the maximum volume is \begin{align*} V\left(4\sqrt{2}, 4\sqrt{2}, 2\sqrt{2}\right)=64\sqrt{2} \text{ft}^3. \end{align*}

Example. A cylindrical can is to hold $4\pi \text{in}.^3$ of orange juice. The cost per square inch of constructing the metal top and bottom is twice the cost per square inch of constructing the cardboard side. What are the dimensions of the least expensive can? A cylindrical can is to hold $4\pi \text{in}.^3$ of orange juice.

Solution. Let $x$ and $y$ be the radius and height of the cylinder, respectively. We want to minimize the cost \begin{align*} f(x,y)=2\left(2\pi x^2\right)+2\pi x y \quad \text{subject to the constraint} \quad g(x,y)=\pi x^2 y=4\pi. \end{align*} We have \begin{align*} f_x=8\pi x+2\pi y, \qquad f_y=2\pi x, \qquad g_x=2\pi x y, \qquad \text{and} \qquad g_y=\pi x^2. \end{align*} Solving the system \begin{align*} 8\pi x+2\pi y=2\lambda \pi x y, \qquad 2\pi x=\lambda \pi x^2, \qquad \pi x^2 y=4\pi. \end{align*} we obtain $y=4x,$ and then find the radius $x=1$ in. and the height $y=4$ in.

## Optimizing a Function Subject to Two Constraints

The method of Lagrange multipliers can also be applied in situations with more than one constraint equation. Suppose we wish to locate an extremum of a function defined by $f(x,y,z)$ subject to constraints $g(x,y,z)=c_1$ and $h(x,y,z)=c_2,$ where $g$ and $h$ are also differentiable and $\nabla g$ and $\nabla h$ are not parallel. By generalizing Lagrange’s theorem, it can be shown that if $\left(x_0, y_0, z_0\right)$ is the desired extremum, then there are numbers $\lambda$ and $\mu$ such that $g\left(x_0,y_0,z_0\right) = c_1, h\left(x_0, y_0, z_0\right) = c_2,$ and \begin{equation} \nabla f\left(x_0, y_0,z_0\right) = \lambda \nabla g \left(x_0, y_0, z_0\right) + \mu \nabla h\left(x_0,y_0,z_0\right). \end{equation} As in the case of one constraint, we proceed by first solving this system of equations simultaneously to find $\lambda , \mu , x_0, y_0, \text{and} z_0$ and then evaluating $f(x,y,z)$ at each solution and comparing to find the assumed extremum.

Example. Find the maximum value of the function $$f(x,y,z)=x+2y+3z$$ on the curve of intersection of the plane $x-y+z=1$ and the cylinder $x^2+y^2=1.$

Solution. We maximize the function$f(x,y,z)=x+2y+3z$ subject to the constraints $g(x,y,z)=x-y+z=1$ and $h(x,y,z)=x^2+y^2=1.$ The Lagrange condition is $\nabla f=\lambda \nabla g+\mu \nabla h,$ so we solve the equations \begin{equation} 1=\lambda +2x \mu, \quad 2=-\lambda +2, \quad y \mu 3=\lambda, \quad x-y+z=1, \quad \text{and} \quad x^2 + y^2=1.\end{equation} Putting $\lambda =3,$ we get $2x \mu =-2,$ so $x=-1/\mu .$ Similarly, we have $y=5/(2\mu ).$ Substitution yields \begin{equation}\frac{1}{\mu ^2}+\frac{25}{4\mu^2} = 1\end{equation} and so $u^2=\frac{29}{4}.$ Then \begin{equation} \mu = \left.\pm \sqrt{29}\right/2, \qquad x=\mp 2\left/\sqrt{29}\right., \qquad \text{and} \qquad y=\pm 5\left/\sqrt{29}\right.\end{equation} and so we have $z=1-x+y$ $=1\pm 7\left/\sqrt{29}.\right.$ The corresponding values of $f$ are \begin{equation} \mp \frac{2}{\sqrt{29}}+2\left(\pm \frac{5}{\sqrt{29}}\right)+3\left(1\pm \frac{7}{\sqrt{29}}\right)=3\pm \sqrt{29}.\end{equation} Therefore the maximum of $f$ on the given curve is $3+\sqrt{29}.$

Example. Find the maximum of $f(x,y,z)=x y z$ subject to $x^2+y^2=3$ and $y=2 z.$

Solution. We need to solve the system $\nabla f=\lambda \nabla g+\mu \nabla h$ where $g(x,y,z)=x^2+y^2$ and $h(x,y,z)=y-2z.$ Therefore we need to solve the system \begin{align*} \left\{ \begin{array}{l} f_x-\lambda g_x-\mu h_x=0 \\ f_y-\lambda g_y-\mu h_y=0 \\ f_z-\lambda g_z-\mu h_z=0 \\ x^2+y^2-3=0 \\ y-2z=0 \end{array} \right. \end{align*} which is written as \begin{align*}\left\{ \begin{array}{l} y z-2\lambda x=0 \\ x z-2\lambda y+\mu =0 \\ x y+2\mu =0 \\ y-2z=0 \\ x^2+y^2-3=0. \end{array} \right. \end{align*} The solutions are $\left(0,0,\pm\sqrt{3}\right)$, and \begin{align*} & \left(1,\sqrt{2},\frac{\sqrt{2}}{2}\right), \quad \left(1,-\sqrt{2},-\frac{\sqrt{2}}{2}\right), \\ & \left(-1,\sqrt{2},\frac{\sqrt{2}}{2}\right), \quad \left(-1,-\sqrt{2},-\frac{\sqrt{2}}{2}\right). \end{align*} The maximum is $f\left(1,\sqrt{2},\frac{\sqrt{2}}{2}\right)=f\left(1,-\sqrt{2},-\frac{\sqrt{2}}{2}\right)=1.$

Example. Find the minimum of $$f(x,y,z)=x^2+y^2+z^2$$ subject to $x+y=4$ and $y+z=6.$

Solution. We want to minimize $x^2+y^2+z^2$ subject to the side conditions $x+y-4=0$ and $y+z-6=0.$ We form \begin{align*} L(x,y,z,\lambda ,\mu )=x^2+y^2+z^2-\lambda (x+y-4)-\mu (y+z-6).\end{align*} The conditions are \begin{align*} \frac{\partial L}{\partial x}=2x-\lambda =0 \end{align*} and \begin{align*} \frac{\partial L}{\partial y}=2y-\lambda -\mu =0 & \qquad \qquad & \frac{\partial L}{\partial z}=2z-\mu =0 \\ \frac{\partial L}{\partial \lambda }=x+y-4=0 & & \frac{\partial L}{\partial \mu }= y+z-6=0. \end{align*} The first and third conditions give $\lambda =2x$ and $\mu =2z,$ so the second condition becomes $2y-2x-2z=0.$ We then have \begin{equation} \left\{ \begin{array}{l} x+ y+z = 0 \\ x+ y = 4 \\ y+z = 6 \end{array} \right. \end{equation} The solution to this system is $P=(2/3,10/3,8/3).$ Therefore the minimum is $f(P)=56/3.$

Example. Use Lagrange multipliers to find the point on the line of intersection of the planes $x-y=2$ and $x-2z=4$ that is closest to the origin.

Solution. We want to minimize $x^2+y^2+z^2$ subject to the side conditions $x-y-2=0$ and $x-2z-4=0.$ We form \begin{equation} L(x,y,z,\lambda ,\mu )=x^2+y^2+z^2-\lambda (x-y-2)-\mu (x-2z-4). \end{equation} The conditions are $\frac{\partial L}{\partial x}=2x-\lambda -\mu =0$ and \begin{equation} \begin{array}{lll} \frac{\partial L}{\partial y}=2y+\lambda =0 & \qquad \qquad & \frac{\partial L}{\partial z}=2z+2\mu =0 \\ \frac{\partial L}{\partial \lambda }=-x+y+2=0 & & \frac{\partial L}{\partial \mu }=-x+2z+4=0. \end{array} \end{equation} The second and third conditions give $\lambda =-2y$ and $\mu =-z,$ so the first condition becomes $2x+2y+z=0.$ We then have $2x+2y+z =0$, $-x+y=-2$, $-x+2z=-4.$ The last two equations may be written as $y=x-2$ and $z=(x-4)/2.$ Substitution of these values into the first equation gives $x=4/3.$ Consequently, $y=-2/3$ and $z=-4/3.$ The desired point is therefore, $(4/3,-2/3,-4/3).$

Example. Find the maximum and minimum values of $$f(x,y,z)=5x-y-6z$$ on the surface $2x^2+4y^2+6z^2=200.$

Solution. We set $g(x,y,z)=2x^2+4y^2+6z^2$ and we use the Lagrange multiplier $\lambda$ and solve the system \begin{align*} \left\{ \begin{array}{l} f_x = \lambda g_x \\ f_y = \lambda g_y \\ f_z = \lambda g_z \\ g = 200 \end{array} \right. \end{align*} which is written as \begin{align*} \left\{ \begin{array}{l} 5 = 4x \lambda \\ -1 = 8y \lambda \\ -6 = 12 z \lambda \\ 2x^2+4y^2+6z^2 = 200 \end{array} \right. \end{align*} to find \begin{align*} P=\left(-10 \sqrt{\frac{2}{3}},\sqrt{\frac{2}{3}},4 \sqrt{\frac{2}{3}} \right) \end{align*} and \begin{align*}
Q=\left(10 \sqrt{\frac{2}{3}},-\sqrt{\frac{2}{3}},-4 \sqrt{\frac{2}{3}}\right) \end{align*} Therefore, $f(P)=-25\sqrt{6}$ is the minimum and $f(Q)=25\sqrt{6}$ is the maximum value.

Example. Maximize $$f(x,y)=\ln \left(x y^2\right)$$ subject to the constraint $2x^2+3y^2=8$ for $x>0.$

Solution. Let $g(x,y)=2x^2+3y^2$ and we will use a Lagrange multiplier, say $\lambda.$ We setup the system of equations \begin{align*} \left\{ \begin{array}{l} \frac{ \partial f}{\partial x} = \lambda \frac{\partial g}{\partial x} \\ \frac{ \partial f}{\partial y} = \lambda \frac{\partial g}{\partial y} \\ g(x) = 8 \end{array} \right. \end{align*} which is written as \begin{align*} \left\{ \begin{array}{l} \frac{y^2}{x y^2} = 4\lambda x \\ \frac{2x y}{x y^2} = 6\lambda y \\ 2x^2+3y^2 = 8 \end{array} \right. \end{align*} Now to solve this we will try to eliminate $\lambda$ from the first two equations. So we solve both of them for $\lambda$ we have, $$\lambda =\frac{1}{4 x^2} \qquad \text{and} \qquad \lambda =\frac{1}{3 x^2 y},$$ (since $x>0$) respectively. Thus, these two expressions must equal yielding $$\frac{1}{4 x^2}=\frac{1}{3 x^2 y}$$ we have $4x^2=3x^2y$ which we write as $x^2(4-3y)=0$ and so $y=4/3.$ So that \begin{equation} x^2=\frac{8-3(4/3)^2}{2}=\frac{4}{3}.\end{equation} However, since $x>0$ we only use $x=\frac{2}{\sqrt{3}}$ with $y=4/3;$ and therefore the maximum value of $f(x,y)=\ln \left(x y^2\right)$ subject to the constraint $g(x,y)=8$ is \begin{equation} f\left(\frac{2}{\sqrt{3}},\pm \frac{4}{3}\right)=\ln \left(\frac{2}{\sqrt{3}}\left(\frac{4}{3}\right)^2\right)=\frac{5}{2}\ln \left(\frac{4}{3}\right).
\end{equation}

## Exercises on Lagrange Multipliers

Exercise. Use Lagrange multipliers to find the point on the line of intersection of the planes $x-y=2$ and $x-2z=4$ that is closest to the origin.

Exercise. Use the method of Lagrange multipliers to maximize or minimize each of the functions.

(1) maximize $f(x,y)=x y$ subject to $2x+2y=5$

(2) minimize $f(x,y)=x y z$ subject to $3x+2y+z=6$

(3) maximize $f(x,y)=e^{x y}$ subject to $x^2+y^2=3$

(4) maximize $f(x,y)=\cos x+\cos y$ subject to $y=x+\frac{\pi }{4}$

(5) minimize $f(x,y)=x^2-x y+2y^2$ subject to $2x+y=22$

(6) minimize $f(x,y)=x^2-y^2$ subject to $x^2+y^2=4$

(7) minimize $f(x,y,z)=2x^2+3y^2+4z^2$ subject to $x+y+z=4$ and $x-2y+5z=3$

(8) minimize $f(x,y,z)=x^2+y^2+z^2$ subject to $x+y=4$ and $y+z=6$

(9) minimize $f(x,y,z)=x y z$ subject to $x^2+y^2=3$ and $y=2z$

(10) maximize $f(x,y,z)=x y+x z$ subject to $2x+3z=5$ and $x y=4$

Exercise. Find the point on the plane $2x-3y+6z=5$ that is closest to the origin.

Exercise. Find the point on the plane $3x-2y+z=5$ that is closet to $(4,-8,5).$

Exercise. A rectangular box has a square base and one top. Find the dimensions for minimum surface area the volume is to be 108 in$^3.$

Exercise. An open rectangular box has ends costing $\$6/\text{ft}^2$, sides costing$\$4/\text{ft}^2$, and a bottom costing $\$10/\text{ft}^2.$Find the dimensions for the minimum cost if the volume of the box is 120 ft$^3.$Exercise. Find the maximum possible volume of a right circular cone inscribed in a sphere of radius$a.$Exercise. The sides of a closed cylindrical container cost twice as much per square food as the ends. Find the ratio of the radius to the altitude of the cylinder for the cheapest such container having fixed volume. Exercise. A pentagon consists of a rectangle surmounted by an isosceles triangle. Find the dimensions of the pentagon having the maximum area if the perimeter is to be$P.$Exercise. Find the point on the curve of intersection of$x^2+z^2=4$and$x-y=8$that is farthest form the origin. Exercise. Find the point on the line of intersection of the planes$x-y=4$and$y+3z=6$that is closet to$(-1,3,2).\$