yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Finishing the intro lagrange multiplier example


5m read
·Nov 11, 2024

So, in the last two videos, we were talking about this constrained optimization problem where we want to maximize a certain function on a certain set: the set of all points ( x, y ) where ( x^2 + y^2 = 1 ).

We ended up working out, through some nice geometrical reasoning, that we need to solve this system of equations. So, there's nothing left to do but to just solve the system of equations.

We'll start with this first one at the top and see what we can simplify. We notice there's an ( x ) term in each one, so we'll go ahead and cancel those out, which is basically a way of saying we're assuming that ( x ) is not zero. We can kind of return to that to see if ( x = 0 ) could be a solution. So maybe we'll kind of write that down: we're assuming ( x \neq 0 ) in order to cancel out.

From this, we can simplify to get ( 2y = \lambda \cdot 2 ). The ( 2 )s can cancel out—no worries about ( 2 ) equaling ( 0 ). We know that ( y = \lambda ), so that's a nice simplified form for this equation.

For the next equation, we can use what we just found—that ( y = \lambda )—to replace the ( \lambda ) that we see. Instead, if I replace this with ( y ), what I'm going to get is that ( x^2 = y \cdot 2 \cdot y ), so that's ( 2y^2 ). I’ll leave it in that form because I see that in the next equation I see an ( x^2 ) and I see ( y^2 ). So it might be nice to be able to plug this guy right into it.

In that next equation, ( x^2 ), I'm going to go ahead and replace that with ( y^2 ), so that's ( 2y^2 + y^2 = 1 ). Then, from there, it simplifies to ( 3y^2 = 1 ), which in turn means ( y^2 = \frac{1}{3} ). So, ( y = \pm \sqrt{\frac{1}{3}} ). Great! This gives us ( y ), and I’ll go ahead and put a box around that—we have found what ( y ) must be.

Now, if ( y^2 = \frac{1}{3} ), then when we look up here and we say ( 2y^2 ), that's going to be the same thing as ( 2 \cdot \frac{1}{3} ). So, if ( x^2 = \frac{2}{3} ), what that implies is that ( x = \pm \sqrt{\frac{2}{3}} ). And there we go, that's another one of the solutions.

I could write down what ( \lambda ) is, right? I mean, in this case, it's easy because ( y = \lambda ). But all we really want in their final form are ( x ) and ( y ) since that's going to give us the answer to the original constraint problem.

So, this gives us what we want. We just have that pesky little possibility that ( x = 0 ) to address. For that, we can take a look and say if ( x = 0 ), let’s go through the possibility that maybe that’s one of the constrained solutions.

Well, in this equation, that would make sense since ( 2 \cdot 0 ) would equal ( 0 ). In this equation, that would mean that we’re setting ( 0 = \lambda \cdot 2y ). Well, since ( \lambda = y ), that would mean that for this side to equal zero, ( y ) would have to equal ( 0 ).

So, evidently, you know, if it was the case that ( x = 0 ), that would have to imply from the second equation that ( y = 0 ). However, if ( x ) and ( y ) both equal ( 0 ), this constraint can't be satisfied. So none of this is possible. We never even had to worry about this to start with, but it's something you do need to check just every time you're dividing by a variable; you're basically assuming that it's not equal to zero.

This right here gives us four possible solutions, four possible values for ( x ) and ( y ) that satisfy this constraint and which potentially maximize this. And remember, when I say potentially maximize, the whole idea of this Lagrange multiplier is that we're looking for where there's a point of tangency between the contour lines.

Just to make it explicit, the four points that we're dealing with here: I’ll write them all here.

So ( x ) could be ( \sqrt{\frac{2}{3}} ), and ( y ) could be the positive ( \sqrt{\frac{1}{3}} ). Then we can basically just toggle. You know, maybe ( x ) is the negative ( \sqrt{\frac{2}{3}} ) and ( y ) is still the positive ( \sqrt{\frac{1}{3}} ). Or maybe ( x ) is the positive ( \sqrt{\frac{2}{3}} ) and ( y ) is the negative ( \sqrt{\frac{1}{3}} ).

Kind of monotonous, but just getting all of the different possibilities on the table here: ( x = -\sqrt{\frac{2}{3}} ) and then ( y = \sqrt{\frac{1}{3}} ) or ( y = -\sqrt{\frac{1}{3}} ). So these are the four points where the contour lines are tangent.

To find which one of these maximizes our function here, let's go ahead and write down our function again. It gets easy to forget. The whole thing we’re doing is maximizing ( f(x, y) = x^2 \cdot y ). So let me just put that down again: we're looking at ( f(x, y) = x^2 \cdot y ).

We could just plug these values in and see which one of them is actually greatest. The first thing to observe is ( x^2 ) is always going to be positive. So if I plug in a negative value for ( y )—if I plug in either this guy here or this guy here where the value for ( y ) is negative—the entire function would be negative.

So I’m just going to say that neither of these can be the maximum because it'll be some positive number, some ( x^2 ) times a negative, whereas I know that these guys are going to produce a positive number. Specifically, if we plug in ( f ) of, let’s say, this top one: ( \sqrt{\frac{2}{3}} ), ( \sqrt{\frac{1}{3}} ). Well, ( x^2 ) is going to be ( \frac{2}{3} ), and then ( y ) is ( \sqrt{\frac{1}{3}} ).

In fact, that's going to be the same as what we get plugging in this other value. So either one of these maximizes the function. It's got two different maximizing points, and each one of them has a maximum value of ( \frac{2}{3} \cdot \sqrt{\frac{1}{3}} ), and that's the final answer.

But I do want to emphasize that the takeaway here is not the specific algebra that you work out going towards the end, but it's the whole idea of this Lagrange multiplier technique. To find the gradient of one function, find the gradient of the constraining function, and then set them proportional to each other. That’s the key takeaway.

Then the rest of it is just, you know, making sure that we check our work and go through the minute details, which is important—it has its place. Coming up, I’ll go through a few more examples.

More Articles

View All
Gini Coefficient and Lorenz Curve
In this video, we’re going to discuss income inequality, which is something that is often debated. Thinking about comparing countries, thinking about whether it’s an issue or not, and how to address it. To appreciate what income inequality is, let’s imagi…
Some Surprising Things
Hey, Vsauce. Michael here. What’s normal? Are you normal? Well, today let’s bathe our brains with those questions and scrub down with things that are surprising and counterintuitive. What does it mean to be normal in the first place? Well, maybe it just …
Why We're Jerks Online
Hello everyone! October 2019 is over, which means that it’s time for the next Q&A. As most of you know, there’s a Patreon edition and a public edition. In this public edition, I’ll talk about the effect of the internet in regards to the shadow, which …
YC Partner AMA at the Female Founders Conference
Hello everyone, my name is Sharon Pope. I’m the head of marketing programs at Y Combinator, and it is my pleasure to welcome back to the stage YC’s partners coming up: Catman, y’all, Ik, Kirstie, Nephew, Adora, Polly, Jessica, and Carolyn. I’m gonna stand…
The Isolation of Addiction | Breakthrough
The similarities with all kinds of addiction is you get that first good feeling from using something, and your brain just remembers the good part. Whether there’s a negative—I, oh, I didn’t have any money after that, I didn’t, I mis-rent or whatever—your …
Have you LOST Your Self-Confidence? 6 POWERFUL TIPS | STOICISM
[Music] Believing in yourself is more than just a feeling; it’s a special skill, a deep way of thinking about life. One clear fact about learning about yourself is this: how much you achieve depends a lot on how confident you are in yourself. Not believin…