If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

### Course: Multivariable calculus>Unit 3

Lesson 5: Lagrange multipliers and constrained optimization

# Constrained optimization introduction

The Lagrange multiplier technique is how we take advantage of the observation made in the last video, that the solution to a constrained optimization problem occurs when the contour lines of the function being maximized are tangent to the constraint curve. Created by Grant Sanderson.

## Want to join the conversation?

• Hi Grant,
Why are you assuming the maximum value occurs when contour line is tangent to constraint?
What if the contour line which passes through the origin and intersects constraint at two different point happens to be the maximum value for that function?
• What program do you use to model functions? Sometimes I need to model a function and cannot picture what it looks like, and cannot find anything online to help me picture it. So, I'd like to maybe get a program like the one you use or, if possible, maybe even the exact same program.
• It is called 'grapher'. It is standard software that comes with mac osx on Apple computers.
• I don't feel this explains the essence of Lagrange multipliers. You have to say why the gradient of f is a multiple of gradient g. The reason is that when f(x,y) is constrained to the curve/surface g(x,y), we need to find a point (a,b) such that grad(f(a,b)) is perpendicular to this curve/surface g(x,y) which is a candidate for an extrema. To see why extrema of f must have gradients that are perpendicular to the curve/surface g, consider a non-perpedicular grad(f) - it can't possibly be a max or min because it has components pointing in the directions of the surface. Since gradients point in directions of max increase, a max or min should not point in any directions along the curve/surface, because if they do clearly there is something larger/smaller immediately next to it. So grad(f) must be perpendicular, otherwise if it has components along the surface you just follow them until you reach a point that doesn't budge.

Finally, all grad(g) are normal to g since they are level curves to g = 0. So finding the normal gradients of f is simplified since they must point in the same direction of grad(g). That is why they are scalar multiples of each other.

This video elaborates on this idea: https://www.youtube.com/watch?v=WOw7TWueU_A
• what if we want to find the minimum value?
(1 vote)
• Finding the minimum value follows the exact same process as finding the maximum except that after finding the critical points, you chose the point with the lowest value instead of the largest.
• Interesting.
I imagine this this would involve solving that tangency point. That kind of implies though that your constraint has to be a smooth curve? i.e. differentiable? i.e. I can't have a squared constraint right?

I imagine you can represent square waves using a fourier series but I wonder how it would be possible to represent a square as a differentiable function.
• You could take the min/ max on each of 4 straight lines within bounds (i.e., on line segments) as the constraints and compare them to find the min min or max max.
(1 vote)
• why maximum values occurs tangent to the unit circle?

• Hi Grant,
I have one question, What software do you use to plot that amazing graphs?
• Why can't we just solve for x^2 in terms of y, plug it into the equation, and then solve it like a normal single variable calculus problem?
• This only works assuming we know the constant value of f(x,y) = c such that is tangent to the unit circle. In order to make the substitution you suggest, it requires knowing this value of c, so you cannot approach it this way.
• https://www.math3d.org/iuCqFiLU
The maximum of this function along x^2+y^2=5/3 does not occur along a contour line tangent to the circle. How does this mesh with what Grant is saying about constrained optimization?
(1 vote)
• Your circle meets your function's surface at ridges of contant height (so the top of the ridge is a contour line marking the maximum height of the ridge) where the gradient of your surface is 0. Clearly, these are special cases, but in general (it seems to me) - and where ∇f ≠ 0 - the constrained maximum or minimum will be where the contours are tangential to the constraining circle.
(1 vote)
• Hi Grant,
Why would we use Lagrangians instead of pluging in the constraits?
Namely, why max f(x, y) = x^2*y subject to x^2+y^2=1
is different than max f(y) = (1-y^2)*y ?
For both the solution is the same: y=1/root(3)
(1 vote)
• You bring up a good point. However the functions you have just work out nicely, and they don't always do this (try, for example, f(x,y)=xy, 4x^2+9y^2=32, or f(x,y)=x^2y+x+y, xy=4). Also remember that your answer will have two points, from the positive or negative square root from the constraint. Although that root gets squared and the y-value is always positive, you still will have a negative root and a positive root for the x-value.

From what I can tell, Lagrangians were developed because someone noticed that if you were to draw a constraint on a 3D graph and look for maximums or minimums, the gradients would point in the same direction, but the magnitudes would be different by a factor. We call this factor the Lagrange multiplier.

Check out these resources for more help visualizing this idea, which can be super helpful and important.
1) Look up "Understanding Lagrange Multipliers Visually" by Serpentine Integral on YouTube.
2) Look up "Lagrange Multipliers | Geometric Meaning & Full Example" by Dr. Trefor Bazett on YouTube.
3) https://www.geogebra.org/m/gCWD3M4G. This is an interactive program for visualizing gradients and lagranges.
(1 vote)