So hi everyone and welcome to our lecture on extreme a multi-variable functions with constraints. We've seen a bunch of problems before where we have to find minimums or maximums of some function and that there unbounded. There's no restrictions on anything you think of constraints like restrictions, this, if you're trying to do things in the real world rarely ever happens. You often have constraints regarding money like there's a finite budget, you have restrictions or constraints regarding how much material you have to produce something. The hours that your team can work, for whatever reason, so there's always these restrictions that happen in real life. And to see a problem that's applied in a true, unbounded setting is very, very rare, and honestly not realistic. So what we're going to do is, we're going to put some constraints on these things. When we have some multi-variable function, so let's say just do some theory here. If I give you some multivariable function f(x,y) that we want to find a max or min. So this is called our objective function and we want to find maxes or mins and will find extrema. And now we're going to add something new, subject to a constraint which will be given by some function. Some other multivariable function that we're going to set = 0, okay? So this will be actually equation = 0, and the objective function will just be a function itself. And what this does when I have an equation set equal to 0, this is a level curve of a function. Let's give a picture to this and talk about some of the theory before we actually go off and compute some of these things. So we take the x, y, and z plane and imagine that f is some generic function, again, I don't know what f is, so will draw the generic picture. This sort of magic cover that just floats in space, so this is your function f(x,y). And normally would have its maxes and it's mins and it was do its thing. But what I want to do now is I want to say, okay great I have this entire landscape. But I only want to look at along some predetermined path g(x,y) on the x,y plane. Because it's equal to 0, this is relationship between x and y, and so when you graph it, there's no z, so you graph it lives on the xy-plane. So it forms some curve, could be a circle, parabola, who cares? I think it is like a path, some path names by plane and then that path translates up on the surface. And now it's like, what are the max and mins, but only on the projection of this path? Like just on this path of this thing, and that could be different. It could be very different than the true maxes or mins of the function itself, because you're restricting the things only above this path on the xy-plane. So how do we solve this tougher problem? Now we have two functions to worry about, well, a nice way to do this was found by an 18th century mathematician, Lagrange. And the technique that we're going to learn today, this is called Lagrange multipliers. And the basic idea of this method is the replace the function f(x,y) by some helper function of three variables. So we're going to introduce a new variable and replace a two variable function with a three variable function. And this is going to introduce a new Greek letter which is drawn sort of diagonal down, and then to the left. This is called lambda, so this is a Greek letter call lambda, it's just the letter that's used for historical context. It is just some other letter don't get too excited about it. So this lambda though, this is called the Lagrange multiplier and we always multiply it to by the constraint function. So we're going to introduce sort of a method and theorem at the same time, on how to find extrema subject to some constraint. Is very important to apply this method of Lagrange multipliers only when you have a constraint given f(x) or not. And of course the g(x) here is completely arbitrary, they might call it something else, they might not label it at all. But just some other function and what's nice about this theory is yes, it works for one constraint. But you can imagine the real world you have our constraint, and equipment constraint, and resource constraint, money constraint. It generalizes to more than one constraint, which is really nice. Okay, so here is the theorem of Lagrange, it says that if I have a function f(x,y) is subject to a constraint = 0. And it has a relative max or min at a point then there is a value of lambda f(x) is lambda g(x). The partial derivative with respect to x and fy equals lambda and, If you have a variable z, you would add fz equals lambda gz. This is a system of equations, so such that the system of equations is satisfied. So there's a lot of words to get this theorem, but the idea is you're going to create a system of equations if you're using derivatives. We're going to introduce a new variable called lambda, and then we're going to solve this system. The solution of that system is going to be your relative extrema, and we'll keep track of those. We'll plug them in and we'll see what is the max and what is them min. All right, enough theory, let's do some examples. So let's find the max or min, so let's find the max of the function, 36- x squared- y squared. So this is some function, if you think about this, this is like the upside down bowl. But I want not just bowl but I want subject to the constraint. So subject to the constraint plus 7y- 25 is 0. All right, so again no word problem here is sort of arbitrary, just practicing the skills. I have some function 36- x squared- y squared subject to x + 7y- 25 = 0 it's given is our f(x, y) and the second one is or g(x, y) and we have to set up. This is a bunch of steps here, so maybe we're going to set up the system of equations. There's two variables, so we're going to set up two equations. fx = lambda gx, fy = lambda gy. And there's one more here that I like to include that's going to help us solve this equation here is g(x, y) = 0. These are all the equations we have to find all the variables. Let's go ahead and actually solve these things. fx partial with respect to x, -2x = lambda g sub x is just 1, so it's fy minus time. And then the partial derivative of g with respect to y is just 7. So lambda times 7 and then I'm going to rewrite the equation again just to keep it all together. But don't forget, you need this one. So what you end up getting is a system of equation of three variables and three equations. So they match so you can solve this thing. This is where the calculus is sort of done at the moment. Now we have to do some algebra and there's a bunch of ways to solve these things, and some are harder than others. But we could use substitution here and solve. So particular one of the one of the techniques you could do is put everything in terms of lambda. So this says that x equals negative lambda over 2. You could save says that Y = -7 lambda over 2. And then you can substitute those values into the given equation. Over 2, 7y, so that's 7 times -7- 25 is 0. From this one equation with one variable, I can solve for lambda. I can software Lambda and then I'll go back and solve for x and y. So what I end up getting is -49 and then minus another one, so it's like -50 lambda. It's all over 2, so I'll combine the fractions and that'll be equal, move the 25 over this 50 lambda is 2 times 25, which is 50. Once I have lambda, I go back and I solve for x, remember lambda's -1, so x is then minus -1, over 2 better known as a half. And then y is minus -7 over 2, better known as 7 over 2. So I found my x value in my y value, this is at one-half. Now, this just tells you that there's some extremely here. The problem said like find the max of this function. This is the point it doesn't actually maximize the function, you have to go ahead and plug that back in so the function value the maximum that this thing up obtains subject to this constraint. Again, the maximum will contain normally would be just plug in (0, 0) and you get 36. But I have (0, 0) doesn't satisfy the constraint. If you plug in (0, 0) you get 25 = 0. So you have this specific curve, so a specific path on this surface that you're talking about. Let's go ahead and plug that in so you get 36- x squared, so it's minus a half squared minus a fourth, and then minus y squared- 49 over 2. And you can check my arithmetic on this, you get 47 over 2 or equivalently 23.5. So this is the maximum value of this function So let's just stare at this for a second. They're all going to follow the same sort of process. You're going to be given some function, you whether its label or not, call it f. It's going to be subject to some constraint presented as an equation now, maybe it's equal 25, or something else. But you can always move stuff over and set it equal to 0, whether it's legal or not, call it t. You then set up a system of equations using partial derivatives. You introduce this new fancy Greek letters called Lambda. And you plug in by taking partials. Again, I would check like crazy here when you do this, just to make sure your equations are correct. There's no point in solving for a system, if you have some wrong equation. So after you get your equations that again, include the constraint just copy that one over, there no calculus on that one. Then just check your partial derivatives, make sure you're happy with those. Go ahead and solve that, now, that's algebra solving system of equation. It can get tough, be careful. But it's just algebra so just go slow and steady, and watch those minus signs. And sometimes you can solve for Lambda. This is just one way to do it, but there are other ways to. You'll see more examples, as you do more problems. Once you have these variables, you can go back and plug in. Often times, you get more than one solution, so you make a table you sort of collect what your solutions are. You look at the outputs of the function, the largest output on that table is going to be the max response plug them in. But with the theorem says is that these points, the points that satisfy the system of equation. These will be your maxes and mins. Let's do another example. So I want to find all extrema classify, an find all extrema of e to the minus xy. And I want to have this subject to the constraint, x squared plus 4y squared equals 1. Now this is an ellipse. In case you don't recognize what this, you can grab this syndesmosis you get an ellipse. And e to the negative xy and x exponential function here. So find all relative extrema. All right, so the first one is I've already labeled f of x, the second one is not. So if you want to pause the video here, see what you can do. So we're going to set up the system f of x equals Lambda g of x, f of y is Lambda g of y. And then of course, we have the constraint itself x squared plus 4y squared equals 1. Tougher derivative here, give it a chain rule action going on, so just be careful. The partial derivative f with respect to x, would be -y, e to the minus xy. So again, repeat in the move upstairs and take a partial. Equals partial derivative in respect to g is a little easier, so should be Lambda times 2x. Partial derivative with respect to y, becomes minus x, e to the minus xy equals Lambda times 8y. And then we'll keep our equation as well x squared plus 4y squared is 1. Great, okay, so before I showed you that you can solve for Lambda, I want to show you maybe another technique. Another technique here? There's probably more than one way to solve this, but this is a clever one. Sometimes with three variables is nonlinear, you got a lot of stuff going on here. It's really hard to solve for the variables, so would you look for is cancellation, which means like if you subtract things, they cancel. The first equation, -y, e to the minus x squared, looks like the second equation minus x, either the -x squared. But there off by a variable, well, you can fix that. So let's multiply the first equation by x, and you get minus, xy, e to the minus xy equals 2 Lambda, to switch the order x squared. So multiply the first equation by x. And now, what you going to do the second equation to make it match. I'm going to multiply it by y and when you do that, you get minus xy, e to the minus xy is 8 Lambda y squared. So these two equations are the same. And now, what I can do is I can like subtract them from each other, and the third equation no change, just bring it along for the ride. So this is another technique. It's very useful, especially given nonlinear equations. Try to see if you could make the two equations look the same. And so why would I do that? So I guess let's subtract the two. When you subtract the two equations, so we're going to do equation 1 minus equation 2. Something allowed to do with systems. The first 2 terms cancel, and what you get is this new equation, you get 2 Lambda x squared. So minus, minus becomes a plus, the first two terms cancel. So that's like 0 and then you get 2 Lambda x squared minus 8 Lambda y squared, and you have a much simpler equation, in fact. And you still have the x squared + 4y is 1. But you have this new equation that you didn't have before, and it's a little easier, it's equal to 0, it's nice. So what can we do? We can divide everything by 2. Maybe I'm going to switch sides over here. So you divide everything by 2, you get lambda. You're going to factor lambda out as well. So lambda(x squared- 4y squared) = 0. From this product that equals 0, we get that lambda = 0 or x squared- 4y squared = 0. Now let's stare at this for a minute. Let's go down these two rows, right? This is an or statement. One of these two things can be true. So let's go down the first path, what if lambda 0, and we're going to look at the first two equations that we started with and think what would happen. So if lambda = 0, that says we rewrite the first equation, we get -ye to the -xy is 0. Remember the exponential function. This is 1 over e to the xy. Exponential function, think of the graph, it's never zero, never. So the only way that this left side could be 0 would tell us that y has to be 0. And for the same reasons, the second equation tells us that -e to the -xy = 0 as well, so plug in lambda = 0. And again, e to the -xy exponential, never 0, so I get x = 0. So lambda = 0 is saying, okay, if that's the case, x is 0, y is 0. And then remember, though, this point has to satisfy all three equations. So now ask yourself, does 0, 0 satisfy x squared + 4y squared = 1? Third equation becomes 0 = 1. That's a problem, tend to write little arrows that bump into each other. So basically, 0 is not equal to 1. So y = 0, x = 0, that can't happen. So lambda cannot equal 0, which says that x squared- 4y squared has to equal 0. So we're now down to our two last constraints. The first two equations have combined to this beautiful x squared- 4y squared = 0. And our second constraint here, the g, x squared + 4y squared = 1. Gotta solve for x, gotta solve for y. Hopefully you see the 4y squared is negative and positive. That screams to sort of add the equations together. You get 2x squared. The 4y squareds, positive and negative, so they cancel, and 0 plus 1 is, of course, just 1. And so you get x squared is a half. And then you get x squared equals, now remember, you're about to take a square root. So this is the square root + or- of one-half. Friendly reminder that square roots break up over fractions. So the square root of 1 is 1, and you get 1 / the square root of 2. It is okay to leave square roots in the denominator. I know some people are like, we have to rationalize. You could, and this would be root 2 over 2. Either one is perfectly fine. So remember, 2x is over here. So when you have that x squared is a half, you can go back and then solve for y using, well, I guess either equation is perfectly fine. So we have x squared is one-half + 4y squared is 1. So 4y squared, subtract is a half, divide by 4, you have y squared is an eighth. And so y = + or- 1 / root 8 or 2 root 2, however you're going to break that up. So you get your four critical points. This is important to realize. We actually have four critical points here. So let's pick a different color. So 4 relative extrema. We have 1 / square root of 2, so there's four of them, and then 1 / root 8. We have 1 / square root of 2, 1 / square root of 8. -1 / the square root of 2, then positive 1 / the square root of 8. And last but not least, -1 / square root of 2, -1 / the square root of 8. So you have four combinations corresponding to plus and minus of each possible combination. When you plug that into the function, remember, we're still trying to find the outputs of the function. So what is the output of the function? Now you have to go in and plug these in, and you can check this. When you plug in the two positive ones, then you're going to get root 16, which is going to become a fourth. So you get e to the negative one-fourth. And then when they're negative, the negative turns positive, the two negatives Can positive so you get E to the positive one-fourth and then the same thing occurs on the other side. So each time you have one negative, you get a positive one-fourth and if you have two negatives that's like going upstairs and plug it in three negatives you gotta E,. So this tells you that says that on this curve on this ellipse x-squared plus 4y squared is 1 you have relative extreme at these values. And the max and min's correspond to either the negative one-fourth any of the positive one-fourth. So you have two mins' and two maxs' so obviously you look at this and describe the higher number. These two are your max and then you have a nice min. Just one thing to point out in this example here. So we're done with this example. But if you notice compared to the other example, we never solved for lambda. We never went ahead and solve for lambda and we showed that if you check it zero that it doesn't work out. But we didn't actually go ahead and solve for lambda, you don't need it, and sometimes you can you don't have to find it, and this typical in these problems. One thing about the graph of this function, that's interesting when you do Lagrange problems. If you want the picture that correspond to these things is interesting. The constraint g of y of x this was x-squared plus 4y squared is 1. This is an ellipse this will be plug in x equals 0. So what are the y-intercepts? Then you get y-squared is one-fourth or y is one-half so it's a little skinnier. These are like one-half and negative a half and if you plug y equals 0 you get x equals 1 quite drawn to scale. But you get some ellipse that's a little wider than it is taller. And then if you were to do the level curve of the function. So if you did that number f of xy was E to the minus xy. If you start graphing these things at these level curves, you're going to find that they touch the graph tangentially, if you start doing level sets in again level sets all live on the xy plane. So you graph these things set it equal to k. Look at your sliders and they touched this graphs just tangentially. And these are the places, this is why again, go graph this thing and you'll see it. This is why you have four extrema corresponding to the symmetry of the ellipse. So you can see these things that it's true. This isn't a coincidence, it will always be true that if you have a level curve of the function. Then it will touch the graph of the extrema tangentially at the relative max and at the relative min, that's always true. All right, so let's do an example, as part of the example from Economics here. We do like a little word problem if you want. So we have x units of labor and we'll let y be our units of capital. It was taken econ classes seen this before and will save the outputs of your labor and your capital can be described by a function. You know this is the Cobb Douglas function or something similar to this. So if x3 to the 4th and then y to the one-fourth and this is what, this is we're going to model some economy here. Okay, so also suppose that each unit of labor costs $100 and the unit of capital will cost $200. So it will cost $100 as your costs and capital cost you $200 and assume that we have $30,000 available to spend. Okay, so this is we're going to restrict the budget. Okay, so here's the question? How many units of labor and how many units of capital should be utilized? Guys know utility functions to maximize this production. Okay, so we want to find a max here, want to maximize our utility so I'm using again. This is exactly what we've seen that I'm using the language of what you see in economics class. So all right, so our budget constraint is given here. So we want to maximize f of xy. So there above and then subject to the constraint. We have $100 for every x plus $200 for every y and the max I can spend is $30,000. You can certainly move the 30 to the other side to get it to be 0 and define a nice function g of x. So let's set this up. The partial derivative with respect to x and gets a little interesting here, be careful. So this becomes three-fourths times 60, which is 45 subtract 1x to the negative one-fourth and then keep y the same equals lambda times 100. Partial derivative with respect to y, same thing. 1/4 times 60 is 15, so x stays the same to the 3/4, then y to the -3/4 = lambda times partial drill with respect to y, that's 200. I also have my third equation here, which is 100x. Maybe we'll divide by the 100, so I have x+2y. Okay, so there's my system of equations. Make sure you agree with all that. And now let's solve for these variables. From the first equation, you could do a little rearranging and solve for lambda, maybe we will do the first approach again. And when you do that, you get lambda = 45 over 100, better known as 9/20x to the -1/4 and y to the positive 1/4. When you solve for lambda in the other equation, you get lambda = 15 over 200, better known as 3/40, x to the 3/4 and y to the -3/4. And so these are both lambda. So what you could do is, well, I guess you could put these two equal to each other and then you can solve for one in terms of other. Algebra is a little messy here, but you don't practice this on your own and check what you get. But set the two equations equal to each other and simplify and you get 9/20y = 3 / 40x or better known as y = 1/6x. So pause the video and try to work that out and see if you agree with my calculation for y. And then once you have that which is nice, you can go ahead and plug that right into the constraint. Two variables become one in that case, and you get that x = 2 times y or one-third x = 300, you get x = 225. Once you have x = 225, you can go ahead and get y = 225 / 6, which is 37.5. So I'm skipping so a lot of the algebra here just to save some time and space, but it is just all algebra. The calculus is probably the harder part, and then the algebra the longer part, and so this is the idea. So you've achieved your maximum utility by allowing 225 units of labor and then 37.5 units of capital. Once again, we didn't find lambda. It's not necessary, so we're okay. So this is a little application economics. If you've seen little economics, you've seen stuff like this before, but maybe not this kind of problem. Just for the folks interested in econ, this Lagrangian multiplier, what this does an economic setting. You can interpret it as the marginal productivity of money and the way to sort of interpret that is that if you have one additional dollar to spend, then approximately, approximately, the value of lambda. You'll get that many additional units of the product can be produced, so it tells you if you have more money, a dollar more, what is the number of that. And you can solve for lambda, once you have x and y, you can go get lambda. It turns out to be 0.2875, which is some number. So you could think, if I had one more additional dollar to spend in my budget, then I can get 0.2875 more additional units of the output. All right, so these are long. They are a bit of a pain, but you gotta be careful. There's calculus and algebra, but this is honestly as long as they get. So if you can do these, you could probably do anything in this course. All right, great job in this tough unit. See you next time.