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
Avoid These Tempting Startup Ideas
That’s the tar pit talking. It’s like, “Oh, this looks like a nice pool water. No one’s here drinking at it. I’m gonna go get a drink of water from this pool, right? Like no danger quicksand.” This is Michael Seibel with Dalton Caldwell, and today we’re …
Khan Academy Ed Talks featuring Dr. Jharrett Bryantt - Thursday, Dec. 10
So I’m excited to introduce our guest, Dr. Jharett Bryantt. Jharett, are you there? I’m sorry for the technical difficulties. My internet connection has been spotty, (chuckles) Let’s just call it that. Jharett- - Good to see you too, Sal, how are you? …
Later stages of the Civil War part 2
All right, so we’ve been talking about the later stages of the Civil War. In the last video, we just did a brief overview of the end of 1863, after the North has won the Battle of Gettysburg and Lee has been turned around and sent back down to Richmond, w…
Nail Polish | Ingredients With George Zaidan (Episode 4)
What’s in here? What does it do? And can I make it from scratch? It’s the stuff inside your sun. Ingredients way back in the day, nail polish was actually pretty simple. The Egyptians used henna and the Chinese used a mixture of egg white, beeswax, gelat…
Tiny Fish Use Bacteria to Glow in the Dark | National Geographic
(Calming music) - I was in the Solomon Islands on a National Geographic expedition. We were working in a shallow reef, and we had a big blue light that we were filming fluorescent corals. One of the safety divers, Brendan Phillips, came up to me and just …
When Family Secrets (And Soap Operas) Fuel Creativity | Podcast | Overheard at National Geographic
I think when I think about my childhood, it feels split. There’s my childhood in Moscow and my childhood in Armenia, which came at the time of the collapse of the Soviet Union. So my first memory is of us standing in breadlines. My second memory is of us …