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.

Main content

Current time:0:00Total duration:8:43

in the last video I introduced a constrained optimization problem where we were trying to maximize this function f of X y equals x squared times y but subject to a constraint that your values of x and y have to satisfy x squared plus y squared equals 1 and the way we were visualizing this was to look at the XY plane where this circle here represents our constraint all of the points that make up this set x squared plus y squared equals 1 and then this curvy line here is one of the contours of F meaning we're setting f of X y equal to some constant and then I was varying around that constant C so for high values of C the contour would look something like this this is where the value of x squared times y is big and then for small values of C the contours would look like this so all the points on this line would be f of XY equals like 0.01 in this case something like that then the way to think about maximizing this function is to try to increase that value of C as much as you can without it falling off the circle and the key observation is that happens when they're tangent so you know you might kind of draw this out on a little sketch and say there's some curve representing your constraint which in this case would be you know kind of where our circle is and then the curve representing the contour would just kiss that curve just barely touch it in some way now that's pretty but in terms of solving the problem we still have some work to do on the main tool we're going to use here is the gradient so let me go ahead and draw a lot more contour lines than there already are 4x squared times y so this is many of the contour lines and I'll draw the gradient field the gradient field of F so I've made a video about the relationship between the gradient and contour lines and the upshot of it is that these gradient vectors every time they pass through a contour line they're perpendicular to it and the basic reason for that is if you walk along the contour line the function isn't changing value so if you want it to change most rapidly you know it kind of makes sense you should walk in the perpendicular direction so that no component of the walk that you're taking is you know useless is along the line where the function doesn't change but again there's a whole video on that that's worth checking out if this feels unfamiliar for our purposes what it means is that when worth considering this point of tangency the gradient of s at that point is going to be some vector perpendicular to both of the curves at that point so that that little vector represents the gradient of F at this point on the plane and we can do something very similar to understand the other curve right now I've just written it as a constraint x squared plus y squared equals 1 but you know to give that function a name let's say that we've defined G of XY to be x squared plus y squared x squared plus y squared in that case this constraint is pretty much just one of the contour lines for the function G and we can take a look at that if we go over here and we look at all of the other contour lines for this function G and it should make sense that they're circles because this function is x squared plus y squared and if we took a look at the gradient of G and we go over and asked about the gradient of G it has that same property that every gradient vector if it passes through a contour line is perpendicular to it so over on our drawing here the gradient vector of G would also be perpendicular to both these curves and you know maybe in this case it's not as long as the gradient of F or maybe it's longer there's no reason that it would be the same length but the important fact is that it's proportional and the way that we're going to write this in formulas is to say that the gradient of F evaluated let's see evaluated at whatever the maximizing value of x and y are so we should give that a name probably maybe you know X sub M Y sub M the specific values of x and y that are going to be at this point that maximizes the function subject to our constraint so that's going to be related to the gradient of G it's not going to be quite equal so I'll leave some room here related to the gradient of G evaluated at that same point XM YM and like I said they're not equal they're proportional so we need to have some kind of proportionality constant in there you almost always use the variable lambda and this guy has a fancy name it's called a Lagrange multiplier l'orange Lagrange's one of those famous French mathematicians I always get him confused with some of the other French mathematicians at the time like Legendre or Laplace there's a whole bunch of things let's see multiplier distracting myself talking here so Lagrange multiplier so there's a number of things in multivariable calculus named after Lagrange and this is one of the big ones this this is a technique that he that he kind of developed or at the very least popularized and the core idea is to just set these gradients equal to each other because that represents when the contour line for one function is tangent to the contour line of another so this this is something that we can actually work with and let's let's start working it out right let's see what this translates to in formulas so I already have G written here so let's go ahead and just evaluate what the gradient of G should be and that's that's the gradient of x squared plus y squared and the way that we take our gradient is it's going to be a vector whose components are all the partial derivatives so the first component is the partial derivative with respect to X so we treat X as a variable Y looks like a constant the derivative is 2x the second component the partial derivative with respect to Y so now we're we're treating Y is the variable X is the constant so the derivative looks like 2y okay so that's the gradient of G then the gradient of F gradient of F it's going to look like gradient of let's see what is X what is F it's x squared times y so x squared times y we do the same thing first component partial derivative with respect to X X looks like a variable so it's derivative is 2 times X and then that Y looks like a constant when we're up here but then partial derivative with respect to Y that Y looks like a variable that x squared just looks like a constant sitting in front of it so that's what we get and now if we kind of work out this Lagrange multiplier expression using these two vectors what we have written what we're going to have written is that this vector 2xy x squared is proportional with a proportionality constant lambda to the gradient vector for G 2 to X to Y and if you want you can think about this as two separate equations I mean right now it's one equation with vectors but really what this is saying is you've got two separate equations two times XY is equal to lambda gotta change colors a lot here lambda times 2 X going to be a stickler for color keep-keep red all of the things associated with G and then the second equation is that x squared is equal to lambda times 2y and this might seem like a problem because we have three unknowns X Y and this new lambda that we introduced kind of shot ourselves in the foot by giving ourselves a new variable to deal with but we only have two equations so in order to solve this we're going to need three equations and the third equation is something that we've known the whole time it's been part of the original problem it's the constraint itself x squared plus y x squared plus y squared excuse me equals one so that that third equation x squared plus y squared is equal to one so these are the three equations they characterize our constrained optimization problem the bottom one just tells you that we have to be on this this unit circle here let me just highlight it we have to be on this unit circle and then these top to tell us what's necessary in order for our contour lines the contour of F and the contour of G to be perfectly tangent with each other so in the next video I'll go ahead and solve this at this point it's pretty much just algebra to deal with but it's worth going through and then the next couple ones we'll talk about a way that you can encapsulate all three of these equations into one expression and also a little bit about the interpretation of this lambda that we introduced because it's not it's not actually just a dummy variable it has a pretty interesting meaning in physical context once you're actually dealing with a constrained optimization problem in practice so I'll see you next video