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
The 8 BEST INVESTMENTS to make RIGHT NOW
One supplies its Graham here. So I checked my analytics the other day, and as it turns out, nearly 60% of you watching are in your 20s, or you just lied to Google about your age when they asked you how old you were so you can get around the age-restricted…
Integration with partial fractions | AP Calculus BC | Khan Academy
[Instructor] We are asked to find the value of this indefinite integral. And some of you, in attempting this, might try to say, all right, is the numerator here the derivative or a constant multiple of the derivative of the denominator? In which case, u-s…
Unit 731: Japan’s Hidden Experiment
Four to six weeks. It’s a duration of time that you and I probably take for granted. What can really happen in that time? Nothing, right? Maybe that’s a big project at work, or maybe how long you’d spend learning integrals in calculus. In a different per…
"I Got Rich When I Understood This" | Jeff Bezos
I was working at a financial firm in New York City with a bunch of very smart people, and I had a brilliant boss I much admired. I went to my boss and told him I was going to start a company selling books on the internet. He took me on a long walk in Cent…
Financial Tips for Millennials: Part 2
The second thing is how do I save? Well, what should I put my saving in? When thinking about what you should put your saving in, realize that the least risk investment, the one you think is the least risk investment, which is cash, is the worst investmen…
How Much Equity to Give Your Cofounder - Michael Seibel
How much equity to give your co-founders? This is a problem and a question that a lot of people have written about, and you can see a lot of varied advice online. My perspective is that most founders are missing a couple key points when divvying up their …