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
Miami Is Sinking | Explorer
How do we know climate change has happened? Well, the first thing is with the glaciers. Glaciers are receding; the world’s getting warmer. People have written computer models of the atmosphere. You imagine boxes of air, boxes of water, and you make them …
15 Crucial Decisions Everyone Needs To Make
The Alex lady you all know and love is still around. We have a lot of work to be done, so we got a new team member. Me think of me as the Alex lady’s helper. Okay, back to the video: 15 crucial decisions everyone needs to make. Life is a roller coaster o…
Course Mastery Sal (intro only)
Hi teachers, this is Sal Khan here from Khan Academy, and welcome to Course Mastery. So, back in 1984, famous education researcher Benjamin Bloom published the famous Two Sigma study, where he showed that a student who works in a mastery learning framewo…
Bill Ackman on Starting His Own Hedge Fund at 26 and Activist Investing
To put this in context, you were mid-20s and I had just gotten—I just started as a rookie professor two years before. So, Bill, at the time, was trying to set up an interesting business, which ultimately became Gotham Partners. So, for those of you who ar…
The age of empire | Rise to world power (1890-1945) | US History | Khan Academy
So I have a map here of United States possessions in the Pacific and in the Caribbean today, and they’re kind of all over the place. I mean, some of them are pretty tiny. There’s Guam, which is just barely a little speck on the map, and American Samoa. An…
Bare/bear, allowed/aloud, advice/advise, break/brake | Frequently confused words | Usage | Grammar
Hello Grim Marians, hello a man, hello uh! Today, we’re going to be talking about four sets of frequently confused words, and the one that I want to begin with is “advice” and “advise.” How do we keep these two words straight? Well, first of all, “advice…