1 00:00:07,036 --> 00:00:07,660 JOEL LEWIS: Hi. 2 00:00:07,660 --> 00:00:09,017 Welcome back to recitation. 3 00:00:09,017 --> 00:00:10,850 In lecture, you've been learning about using 4 00:00:10,850 --> 00:00:12,750 the method of Lagrange multipliers 5 00:00:12,750 --> 00:00:15,950 to optimize functions of several variables given a constraint. 6 00:00:15,950 --> 00:00:19,630 So here's a problem that you can practice this method on. 7 00:00:19,630 --> 00:00:22,700 So I've got a function f of x, y, z equals 8 00:00:22,700 --> 00:00:26,970 x squared plus x plus 2 y squared plus 3 z squared. 9 00:00:26,970 --> 00:00:29,490 And what I'd like you to do is find the maximum and minimum 10 00:00:29,490 --> 00:00:32,850 values that this function takes as the point (x, y, z) 11 00:00:32,850 --> 00:00:36,190 moves around the unit sphere x squared plus y squared plus z 12 00:00:36,190 --> 00:00:37,720 squared equals 1. 13 00:00:37,720 --> 00:00:40,200 So to optimize this function given the constraint 14 00:00:40,200 --> 00:00:42,435 x squared plus y squared plus z squared equals 1. 15 00:00:42,435 --> 00:00:44,570 So why don't you pause the video, take some time 16 00:00:44,570 --> 00:00:47,111 to work that out, come back, and we can work it out together. 17 00:00:55,410 --> 00:00:57,660 Hopefully you had some luck working on this problem. 18 00:00:57,660 --> 00:00:58,910 Let's have a go at it. 19 00:00:58,910 --> 00:01:01,340 So remember that the method of Lagrange 20 00:01:01,340 --> 00:01:03,800 multipliers-- in order to apply it-- what it says 21 00:01:03,800 --> 00:01:07,000 is that when you have a function being optimized 22 00:01:07,000 --> 00:01:10,000 on some constraint condition, what 23 00:01:10,000 --> 00:01:13,070 you do to find the points where the function could be maximum 24 00:01:13,070 --> 00:01:17,500 or minimum is that first you look for points where 25 00:01:17,500 --> 00:01:19,860 the gradient of your objective function 26 00:01:19,860 --> 00:01:23,380 is parallel to the gradient of your constraint function. 27 00:01:23,380 --> 00:01:26,020 So what that means is you take the partial derivatives 28 00:01:26,020 --> 00:01:30,370 f_x, f_y, f_z, and you say f_x has to be equal to lambda times 29 00:01:30,370 --> 00:01:33,120 g_x, f_y has to be equal to lambda times g_y, 30 00:01:33,120 --> 00:01:35,020 and f_z has to be equal to lambda times 31 00:01:35,020 --> 00:01:37,000 g_z, for some lambda. 32 00:01:37,000 --> 00:01:39,000 And then you solve that system together 33 00:01:39,000 --> 00:01:40,720 with the constraint equation. 34 00:01:40,720 --> 00:01:44,260 And so the points that are the solutions 35 00:01:44,260 --> 00:01:46,750 of that system of equations, those points 36 00:01:46,750 --> 00:01:49,280 are your points that you have to check for whether they're 37 00:01:49,280 --> 00:01:50,570 the maximum or the minimum. 38 00:01:50,570 --> 00:01:53,482 And also, sometimes you have some boundary to your region 39 00:01:53,482 --> 00:01:54,940 and you have to check that as well. 40 00:01:54,940 --> 00:01:57,850 So in this case, the sphere doesn't have boundary. 41 00:01:57,850 --> 00:01:58,627 Right? 42 00:01:58,627 --> 00:02:00,710 So we don't have any boundary conditions to check. 43 00:02:00,710 --> 00:02:03,001 So we're going to have a really straightforward problem 44 00:02:03,001 --> 00:02:04,760 to solve where we just have to look 45 00:02:04,760 --> 00:02:05,970 at the partial derivatives. 46 00:02:05,970 --> 00:02:07,920 So let's write down that system of equations 47 00:02:07,920 --> 00:02:09,070 that we have to solve. 48 00:02:09,070 --> 00:02:11,710 So the partial derivative of f with respect to x 49 00:02:11,710 --> 00:02:14,810 is going to be 2x plus 1. 50 00:02:14,810 --> 00:02:19,090 So we have to solve the system 2x plus 1 equals-- 51 00:02:19,090 --> 00:02:23,330 and the partial derivative of our constraint with respect 52 00:02:23,330 --> 00:02:28,660 to x is 2x, so 2x plus 1 has to equal lambda times 2x. 53 00:02:28,660 --> 00:02:31,700 That's what we get from the x-partial derivatives. 54 00:02:31,700 --> 00:02:33,760 How about from the y-partial derivatives? 55 00:02:33,760 --> 00:02:39,550 The y-partial derivative of f is going to be 4y. 56 00:02:39,550 --> 00:02:41,450 So that has to be equal to lambda 57 00:02:41,450 --> 00:02:45,395 and the y-partial derivative of the constraint equation 58 00:02:45,395 --> 00:02:46,720 which is 2y. 59 00:02:49,750 --> 00:02:52,710 And the z-partial derivative of f is 6z. 60 00:02:56,110 --> 00:03:00,280 So 6z has to be equal to lambda times, well, 61 00:03:00,280 --> 00:03:03,001 the z-partial derivative of the constraint function, which 62 00:03:03,001 --> 00:03:03,500 is 2z. 63 00:03:06,150 --> 00:03:11,670 And we have the last equation x squared plus y squared plus z 64 00:03:11,670 --> 00:03:13,780 squared equals 1. 65 00:03:13,780 --> 00:03:17,150 So we get four equations in our variables x, y, and z, 66 00:03:17,150 --> 00:03:19,664 plus this new parameter lambda that we introduced. 67 00:03:19,664 --> 00:03:21,080 And we want to solve these to find 68 00:03:21,080 --> 00:03:24,500 the points x, y, and z at which these equations are all 69 00:03:24,500 --> 00:03:25,240 satisfied. 70 00:03:25,240 --> 00:03:27,120 And then, once we get those points, 71 00:03:27,120 --> 00:03:28,985 we have to test them to see whether they 72 00:03:28,985 --> 00:03:33,000 are the maximum or the minimum or neither. 73 00:03:33,000 --> 00:03:33,850 So OK. 74 00:03:33,850 --> 00:03:35,350 So we have this system of equations. 75 00:03:35,350 --> 00:03:36,933 Now, this is a little bit complicated. 76 00:03:36,933 --> 00:03:39,500 It's not a system of linear equations. 77 00:03:39,500 --> 00:03:41,880 So we need to think about ways that we can solve it. 78 00:03:41,880 --> 00:03:44,000 And one thing that I think we can do here, 79 00:03:44,000 --> 00:03:46,660 is if you look at the second and third equations, 80 00:03:46,660 --> 00:03:48,780 you see that in the second equation, 81 00:03:48,780 --> 00:03:51,310 everything has a factor of y in it. 82 00:03:51,310 --> 00:03:55,980 So either y is equal to 0, or we can divide by it. 83 00:03:55,980 --> 00:04:02,880 So from the second equation, we have 84 00:04:02,880 --> 00:04:06,110 that either y is equal to 0, or we 85 00:04:06,110 --> 00:04:12,590 can divide by y, in which case we get lambda is equal to 2. 86 00:04:12,590 --> 00:04:14,400 Similarly, from the third equation, 87 00:04:14,400 --> 00:04:18,610 we have that either z is equal to 0, or we can divide by z 88 00:04:18,610 --> 00:04:21,000 and we get lambda is equal to 3. 89 00:04:21,000 --> 00:04:25,485 So from the third equation, we have z 90 00:04:25,485 --> 00:04:31,750 equals 0 or lambda equals 3. 91 00:04:31,750 --> 00:04:34,570 So now we have a bunch of possibilities, right? 92 00:04:34,570 --> 00:04:40,110 So either we have y equals z equals 0, or we have y equals 0 93 00:04:40,110 --> 00:04:45,980 and lambda equals 3, or we have lambda equals 2 and z equals 0. 94 00:04:45,980 --> 00:04:48,320 Or, well, the other possibility would be lambda 95 00:04:48,320 --> 00:04:50,800 equals 2 and lambda equals 3, but that can't happen. 96 00:04:50,800 --> 00:04:52,487 So we have three possibilities. 97 00:04:52,487 --> 00:04:54,570 Three different ways that this could be satisfied. 98 00:04:54,570 --> 00:04:56,730 So let's go over here and write down 99 00:04:56,730 --> 00:04:58,750 what those possibilities are. 100 00:04:58,750 --> 00:05:00,820 So case one, or maybe I'll call it case a. 101 00:05:00,820 --> 00:05:06,190 So the case a is when y is equal to z is equal to 0. 102 00:05:06,190 --> 00:05:09,460 So when y is equal to z is equal to 0-- OK, 103 00:05:09,460 --> 00:05:11,360 we need to find x still. 104 00:05:11,360 --> 00:05:13,690 So let's look back at our equations. 105 00:05:13,690 --> 00:05:15,640 And when y is equal to z is equal to 0, 106 00:05:15,640 --> 00:05:18,670 well, we can solve our constraint equation for x. 107 00:05:18,670 --> 00:05:22,169 When y equals z equals 0, we have that x squared equals 1. 108 00:05:22,169 --> 00:05:23,460 So there are two possibilities. 109 00:05:23,460 --> 00:05:27,410 The point (1, 0, 0), and the point minus 1, 0, 0. 110 00:05:27,410 --> 00:05:30,730 So this gives us, in this case, we 111 00:05:30,730 --> 00:05:36,160 have x equals 1 or x equals minus 1. 112 00:05:36,160 --> 00:05:39,600 So that gives us the points (1, 0, 0) 113 00:05:39,600 --> 00:05:42,290 and minus 1, 0, 0 that we're going 114 00:05:42,290 --> 00:05:43,770 to have to check at the end. 115 00:05:43,770 --> 00:05:44,270 All right. 116 00:05:44,270 --> 00:05:49,540 So the second case is we could have y equal to 0 117 00:05:49,540 --> 00:05:52,880 and lambda equal to 3. 118 00:05:52,880 --> 00:05:56,240 So in this case, let's go back to our equations again. 119 00:05:56,240 --> 00:06:02,020 So from lambda equals 3, we have in our first equation 120 00:06:02,020 --> 00:06:05,250 that 2x plus 1 equals 6x. 121 00:06:05,250 --> 00:06:09,180 So 1 equals 4x or x equals 1/4. 122 00:06:09,180 --> 00:06:13,600 So this implies over here that x equals 1/4. 123 00:06:13,600 --> 00:06:16,510 And now, we still need to find z. 124 00:06:16,510 --> 00:06:21,190 So if we go back to our constraint equation here, 125 00:06:21,190 --> 00:06:25,400 we have that x is a quarter and y is 0. 126 00:06:25,400 --> 00:06:29,290 So that means 1/16 plus z squared equals 1. 127 00:06:29,290 --> 00:06:35,170 So z has to be the square root of 15/16, plus or minus. 128 00:06:35,170 --> 00:06:37,549 And z is equal to plus or minus-- 129 00:06:37,549 --> 00:06:39,590 so that we can also write that as the square root 130 00:06:39,590 --> 00:06:41,470 of 15 over 4. 131 00:06:41,470 --> 00:06:43,780 So this also gives us two points to check. 132 00:06:43,780 --> 00:06:50,930 The points are 1/4, 0, the square root of 15 over 4. 133 00:06:50,930 --> 00:06:58,520 And 1/4, 0, minus square root of 15 over 4. 134 00:06:58,520 --> 00:07:01,250 And finally, we have our third case. 135 00:07:01,250 --> 00:07:06,500 So our third case is when lambda is equal to 2 136 00:07:06,500 --> 00:07:09,300 and z is equal to 0. 137 00:07:09,300 --> 00:07:12,810 So again, let's go back over to our equation. 138 00:07:12,810 --> 00:07:15,590 So when lambda equals 2 in the first equation, 139 00:07:15,590 --> 00:07:18,690 we have 2x plus 1 equals 4x. 140 00:07:18,690 --> 00:07:21,930 So 2x equals 1 or x is 1/2. 141 00:07:21,930 --> 00:07:24,940 So this gives us x equals a half. 142 00:07:24,940 --> 00:07:28,530 And now if you take z equals 0 and x equals 1/2, 143 00:07:28,530 --> 00:07:30,810 we can take that down to our constraint equation. 144 00:07:30,810 --> 00:07:33,740 And we get a quarter plus y squared equals 1, 145 00:07:33,740 --> 00:07:36,820 so y is a square root of 3/4. 146 00:07:36,820 --> 00:07:42,120 So y equals plus or minus square root of 3 over 2. 147 00:07:42,120 --> 00:07:43,820 And this gives us two points. 148 00:07:43,820 --> 00:07:50,230 1/2, square root of 3 over 2, 0. 149 00:07:50,230 --> 00:07:56,580 And 1/2, minus square root of 3 over 2, 0. 150 00:07:56,580 --> 00:07:57,980 Those were our three cases. 151 00:07:57,980 --> 00:07:59,160 We've solved each of them. 152 00:07:59,160 --> 00:08:01,740 We've solved each of them all the way down 153 00:08:01,740 --> 00:08:05,260 to finding the points that they lead to. 154 00:08:05,260 --> 00:08:07,010 Now remember, we said already that there's 155 00:08:07,010 --> 00:08:08,400 no boundary to this region. 156 00:08:08,400 --> 00:08:10,670 It's just the sphere. 157 00:08:10,670 --> 00:08:12,754 It has no edges. 158 00:08:12,754 --> 00:08:14,670 So these are the only points we have to check. 159 00:08:14,670 --> 00:08:16,170 We have to check these six points. 160 00:08:16,170 --> 00:08:17,586 What do we have to check them for? 161 00:08:17,586 --> 00:08:19,600 Well, we have to look at the value of f 162 00:08:19,600 --> 00:08:22,560 at each of these six points. 163 00:08:22,560 --> 00:08:25,220 And we want to figure out where f is maximized 164 00:08:25,220 --> 00:08:27,720 and where f is minimized, and these six points are 165 00:08:27,720 --> 00:08:29,600 the only points where that could happen, 166 00:08:29,600 --> 00:08:32,020 where f could be maximized or minimized. 167 00:08:32,020 --> 00:08:34,240 So we just have to evaluate our objective function 168 00:08:34,240 --> 00:08:36,220 f at these six points and find the largest 169 00:08:36,220 --> 00:08:38,430 value and the smallest value. 170 00:08:38,430 --> 00:08:39,340 So let's do that. 171 00:08:39,340 --> 00:08:41,180 So our objective function, remember, it's 172 00:08:41,180 --> 00:08:42,880 all the way back over here. 173 00:08:42,880 --> 00:08:46,010 It's this function x squared plus x plus 2 y 174 00:08:46,010 --> 00:08:49,070 squared plus 3 z squared. 175 00:08:49,070 --> 00:08:49,570 OK. 176 00:08:49,570 --> 00:08:52,850 So let's look at the value of that function at these point. 177 00:08:52,850 --> 00:08:55,370 So x squared plus x plus 2 y squared 178 00:08:55,370 --> 00:08:59,710 plus 3 z squared at the point 1, 0, that's just equal to 2. 179 00:08:59,710 --> 00:09:02,440 So I'm going to write the function values just off 180 00:09:02,440 --> 00:09:06,980 to the side of the points here. 181 00:09:06,980 --> 00:09:08,700 So this gives me the value 2. 182 00:09:08,700 --> 00:09:10,450 And I'm going to circle them. 183 00:09:10,450 --> 00:09:13,730 So the point (1, 0, 0) gives me the value 2. 184 00:09:13,730 --> 00:09:17,420 The point minus 1, 0, 0-- so that's x squared 185 00:09:17,420 --> 00:09:21,500 is 1, plus x is minus 1-- so that's 1 minus 1 186 00:09:21,500 --> 00:09:24,750 is 0-- and then the y and z terms are both 0. 187 00:09:24,750 --> 00:09:29,230 So at the point minus 1, 0, 0, the function value is 0. 188 00:09:29,230 --> 00:09:32,360 I'm going to circle that. 189 00:09:32,360 --> 00:09:32,970 Oh boy. 190 00:09:32,970 --> 00:09:38,075 OK, so at these points-- at the point 1/4, 0, square root 191 00:09:38,075 --> 00:09:43,145 of 15 over 4, and 1/4, 0, minus square root of 15 over 4-- 192 00:09:43,145 --> 00:09:45,520 I'm going to cheat and look at what I wrote down already. 193 00:09:45,520 --> 00:09:48,730 So you could do the arithmetic yourself, 194 00:09:48,730 --> 00:09:51,270 but I think it's not that hard to work out 195 00:09:51,270 --> 00:09:55,230 that in both of these cases, the function value that you get out 196 00:09:55,230 --> 00:09:57,510 is 25 over 8. 197 00:09:57,510 --> 00:10:00,880 I'm not going to do the arithmetic right now. 198 00:10:03,520 --> 00:10:05,830 But you can double-check that for yourself. 199 00:10:05,830 --> 00:10:08,870 And at these last two points-- the points 1/2, 200 00:10:08,870 --> 00:10:12,810 root 3 over 2, 0, and 1/2, minus root 3 over 2, 201 00:10:12,810 --> 00:10:18,120 0-- the function has the same value at both of those points. 202 00:10:18,120 --> 00:10:19,500 That value is 9/4. 203 00:10:23,250 --> 00:10:26,000 Yeah, so 25 over 8 was the value at both of these points, 204 00:10:26,000 --> 00:10:28,740 and 9/4 is the value of both of these points. 205 00:10:28,740 --> 00:10:31,697 So now, to find the maximum value of the function 206 00:10:31,697 --> 00:10:33,280 and the minimum value of the function, 207 00:10:33,280 --> 00:10:34,850 we just look at the values that we got and say, 208 00:10:34,850 --> 00:10:37,225 which of these is biggest and which of these is smallest? 209 00:10:37,225 --> 00:10:42,487 And in our case, it's easy to see that 0 is the minimum. 210 00:10:42,487 --> 00:10:44,320 You know, all the other values are positive, 211 00:10:44,320 --> 00:10:45,600 so 0 is the minimum. 212 00:10:45,600 --> 00:10:56,740 So our minimum value of f is 0 at the point minus 1, 0, 0. 213 00:10:56,740 --> 00:11:01,480 And if you just compare the values 2 and 25/8 and 9/4, 214 00:11:01,480 --> 00:11:03,560 25/8 is the largest. 215 00:11:03,560 --> 00:11:06,680 This is bigger than 3, whereas both of those are less than 3, 216 00:11:06,680 --> 00:11:07,280 for example. 217 00:11:07,280 --> 00:11:08,654 This is one easy way to see that. 218 00:11:08,654 --> 00:11:18,100 So the max of f is 25/8, and that's 219 00:11:18,100 --> 00:11:24,095 achieved at the points 1/4, 0, plus or minus 220 00:11:24,095 --> 00:11:28,680 square root of 15 over 4. 221 00:11:28,680 --> 00:11:29,820 So there you have it. 222 00:11:29,820 --> 00:11:31,860 The method of Lagrange multipliers. 223 00:11:31,860 --> 00:11:37,220 We just followed exactly the strategy that we have. 224 00:11:37,220 --> 00:11:41,420 So you start out and you have an objective function 225 00:11:41,420 --> 00:11:42,770 and a constraint function. 226 00:11:42,770 --> 00:11:43,710 And so what do you do? 227 00:11:43,710 --> 00:11:45,610 You write down their partial derivatives 228 00:11:45,610 --> 00:11:47,780 and you come up with this system of equations. 229 00:11:47,780 --> 00:11:49,946 So this system of equations that you get by setting, 230 00:11:49,946 --> 00:11:54,100 you know, f_x equal to lambda g_x, f_y equal to lambda g_y, 231 00:11:54,100 --> 00:11:57,550 f_z equals lambda g_z, and your constraint equation g 232 00:11:57,550 --> 00:11:59,940 equals some constant. 233 00:11:59,940 --> 00:12:04,100 So then the one part of this procedure that isn't just 234 00:12:04,100 --> 00:12:07,510 a recipe is that you need to solve this system of equations, 235 00:12:07,510 --> 00:12:09,110 but sometimes that can be hard. 236 00:12:09,110 --> 00:12:11,782 So in this case, there were a couple of observations 237 00:12:11,782 --> 00:12:14,240 that we could make from the second and third equations that 238 00:12:14,240 --> 00:12:16,810 made it relatively straightforward to do. 239 00:12:16,810 --> 00:12:18,460 And that gave us some cases. 240 00:12:18,460 --> 00:12:20,970 And then in each of those cases, we 241 00:12:20,970 --> 00:12:23,890 were able to completely solve for the points x, y, and z. 242 00:12:23,890 --> 00:12:26,760 Now we also could solve for the associated values of lambda, 243 00:12:26,760 --> 00:12:29,380 but lambda isn't important to us. 244 00:12:29,380 --> 00:12:31,690 It doesn't affect f. 245 00:12:31,690 --> 00:12:34,330 We can forget about it as soon as we found it, 246 00:12:34,330 --> 00:12:36,320 once we found x, y, and z. 247 00:12:36,320 --> 00:12:37,490 So we were able to solve. 248 00:12:37,490 --> 00:12:39,982 In this case, we got six points of interest. 249 00:12:39,982 --> 00:12:41,440 And then you just look at the value 250 00:12:41,440 --> 00:12:43,470 of your objective function at those points. 251 00:12:43,470 --> 00:12:46,280 So that was what I wrote down in these circles. 252 00:12:46,280 --> 00:12:49,364 So you look at the value of the objective function. 253 00:12:49,364 --> 00:12:51,280 And to find the maximum value of the function, 254 00:12:51,280 --> 00:12:53,300 you just look at which of those is largest. 255 00:12:53,300 --> 00:12:55,895 Now sometimes-- not in this problem, but in other problems, 256 00:12:55,895 --> 00:12:59,200 you'll also have to check-- if the region has a boundary, 257 00:12:59,200 --> 00:13:01,640 you'll also have to check for possible maxima and minima 258 00:13:01,640 --> 00:13:03,180 on the boundary of the region. 259 00:13:03,180 --> 00:13:04,737 But a sphere doesn't have any edges, 260 00:13:04,737 --> 00:13:06,070 so it doesn't have any boundary. 261 00:13:06,070 --> 00:13:08,020 So we don't have to worry about that. 262 00:13:08,020 --> 00:13:10,770 So that's how we apply the method of Lagrange multipliers 263 00:13:10,770 --> 00:13:11,690 to this problem. 264 00:13:11,690 --> 00:13:14,370 And how you can apply it to other problems as well. 265 00:13:14,370 --> 00:13:15,763 I'll end there.