1 00:00:00,000 --> 00:00:07,026 2 00:00:07,026 --> 00:00:07,650 JOEL LEWIS: Hi. 3 00:00:07,650 --> 00:00:09,180 Welcome back to recitation. 4 00:00:09,180 --> 00:00:11,950 In lecture, you've learned about gradients and about 5 00:00:11,950 --> 00:00:13,170 directional derivatives. 6 00:00:13,170 --> 00:00:16,500 So I have a problem here to test your understanding 7 00:00:16,500 --> 00:00:20,820 of those objects and give you some practice computing them. 8 00:00:20,820 --> 00:00:23,869 So I have three functions here. 9 00:00:23,869 --> 00:00:25,410 And for each function, I've given you 10 00:00:25,410 --> 00:00:27,260 a point and a direction. 11 00:00:27,260 --> 00:00:30,020 So what I'd like you to do is compute 12 00:00:30,020 --> 00:00:32,310 the gradients of the functions, then 13 00:00:32,310 --> 00:00:34,900 evaluate their gradients at the point given, 14 00:00:34,900 --> 00:00:38,830 and then compute the directional derivative of the function 15 00:00:38,830 --> 00:00:42,250 at the point in the direction of the vector given. 16 00:00:42,250 --> 00:00:44,070 So here, for example, in part a, I've 17 00:00:44,070 --> 00:00:48,270 given you the function f of x, y equal to x squared y plus x 18 00:00:48,270 --> 00:00:52,740 y squared, at the point x equal minus 1, y equal 2, 19 00:00:52,740 --> 00:00:56,400 and in the direction of the vector [3, 4]. 20 00:00:56,400 --> 00:00:59,729 And then we've got two more examples here. g of x, y, z 21 00:00:59,729 --> 00:01:02,020 is equal to the square root of x squared plus y squared 22 00:01:02,020 --> 00:01:05,400 plus z squared, P is the point 2, 6, minus 3, 23 00:01:05,400 --> 00:01:07,480 and v is the direction [1, 1, 1]. 24 00:01:07,480 --> 00:01:10,870 And our third example, h is a function of four variables, w, 25 00:01:10,870 --> 00:01:12,220 x, y, and z. 26 00:01:12,220 --> 00:01:19,130 It's given by w*x plus w*y plus w*z plus x*y plus x*z plus y*z, 27 00:01:19,130 --> 00:01:23,180 at the point 2, 0, minus 1, minus 1, in the direction 1, 28 00:01:23,180 --> 00:01:26,030 minus 1, 1, minus 1. 29 00:01:26,030 --> 00:01:28,390 So why don't you pause the video, take some time 30 00:01:28,390 --> 00:01:30,374 to work out these three problems, come back, 31 00:01:30,374 --> 00:01:31,790 and we can work them out together. 32 00:01:31,790 --> 00:01:40,350 33 00:01:40,350 --> 00:01:42,760 I hope you had some luck working out these problems. 34 00:01:42,760 --> 00:01:46,560 Let's get started on the first one. 35 00:01:46,560 --> 00:01:52,260 So on the first one, our function f of x, y 36 00:01:52,260 --> 00:01:57,330 is equal to x squared y plus x y squared. 37 00:01:57,330 --> 00:01:59,120 So to compute the gradient, I just 38 00:01:59,120 --> 00:02:01,540 have to compute the first partials of our function, 39 00:02:01,540 --> 00:02:03,570 and then put them into a single vector. 40 00:02:03,570 --> 00:02:04,910 So that's what the gradient is. 41 00:02:04,910 --> 00:02:09,790 So we have that the gradient of f at (x, 42 00:02:09,790 --> 00:02:12,760 y) is equal to-- it's the vector, 43 00:02:12,760 --> 00:02:16,650 and its first component is the first partial of f with respect 44 00:02:16,650 --> 00:02:23,270 to x, so that's going to be 2x*y plus y squared. 45 00:02:23,270 --> 00:02:26,580 And its second component is the partial of f with respect to y, 46 00:02:26,580 --> 00:02:31,920 so that's going to be x squared plus 2x*y. 47 00:02:31,920 --> 00:02:34,400 So this is the gradient of our function f. 48 00:02:34,400 --> 00:02:36,780 Now, the question asked you to compute this gradient 49 00:02:36,780 --> 00:02:40,620 at the particular point minus 1, 2. 50 00:02:40,620 --> 00:02:44,520 So we have gradient of f at the point minus 1, 51 00:02:44,520 --> 00:02:48,390 2 is equal to-- well, we just put in x equal minus 1, 52 00:02:48,390 --> 00:02:50,310 y equal 2 into this formula. 53 00:02:50,310 --> 00:02:54,060 So at x equal minus 1, y equals 2, this is 2 times 54 00:02:54,060 --> 00:02:56,480 minus 1 times 2 plus 2 squared. 55 00:02:56,480 --> 00:02:59,260 So that's minus 4 plus 4, so that's just 0. 56 00:02:59,260 --> 00:03:04,750 And the second term is minus 1 squared plus 2 times 57 00:03:04,750 --> 00:03:06,180 minus 1 times 2. 58 00:03:06,180 --> 00:03:11,730 So that's 1 plus 4-- nope-- 1 plus negative 4, 59 00:03:11,730 --> 00:03:14,390 so that's negative 3. 60 00:03:14,390 --> 00:03:14,890 All right. 61 00:03:14,890 --> 00:03:17,650 So this is the gradient of our function f. 62 00:03:17,650 --> 00:03:20,820 This is the gradient at the point minus 1, 2. 63 00:03:20,820 --> 00:03:23,950 Now we are asked for the directional derivative. 64 00:03:23,950 --> 00:03:26,350 So we were asked for the directional derivative 65 00:03:26,350 --> 00:03:29,745 of f in a direction. 66 00:03:29,745 --> 00:03:34,400 So we're given-- I didn't give you-- so I gave you a vector v. 67 00:03:34,400 --> 00:03:37,620 But when we take directional derivatives, what we want 68 00:03:37,620 --> 00:03:39,450 is a unit vector. 69 00:03:39,450 --> 00:03:40,020 Right? 70 00:03:40,020 --> 00:03:43,790 So the vector v that I gave you-- was right over here-- 71 00:03:43,790 --> 00:03:46,820 it was this vector, [3, 4]. 72 00:03:46,820 --> 00:03:51,050 And so we need to find the unit vector u in the direction of v 73 00:03:51,050 --> 00:03:53,750 in order to apply our usual formula. 74 00:03:53,750 --> 00:04:00,040 So u is just v divided by the length of 75 00:04:00,040 --> 00:04:04,020 v. So in this case, the vector [3, 4], 76 00:04:04,020 --> 00:04:06,450 by the Pythagorean theorem, it has length 5. 77 00:04:06,450 --> 00:04:14,110 So this is equal to the vector 3/5 comma 4/5. 78 00:04:14,110 --> 00:04:16,440 And so our directional derivative 79 00:04:16,440 --> 00:04:19,790 in the direction of v-- which is this vector 80 00:04:19,790 --> 00:04:23,280 u-- it's just equal to the gradient at that point 81 00:04:23,280 --> 00:04:25,690 dotted with the direction vector. 82 00:04:25,690 --> 00:04:32,990 So this is equal to gradient of f at that point dot u. 83 00:04:32,990 --> 00:04:36,790 Which in our case is equal to-- well, 84 00:04:36,790 --> 00:04:39,880 since we're interested at the point P-- it's equal to 0, 85 00:04:39,880 --> 00:04:47,650 minus 3, dot our vector u, which is [3/5, 4/5]. 86 00:04:47,650 --> 00:04:51,680 And that dot product is negative 12/5. 87 00:04:51,680 --> 00:04:54,520 So in this direction, the function 88 00:04:54,520 --> 00:04:58,370 is decreasing at about this rate at the given point. 89 00:04:58,370 --> 00:04:58,870 All right. 90 00:04:58,870 --> 00:05:00,050 That's part a. 91 00:05:00,050 --> 00:05:02,340 Let's go on to part b. 92 00:05:02,340 --> 00:05:05,380 So, you know, you've probably noticed that these questions 93 00:05:05,380 --> 00:05:06,410 are all fairly similar. 94 00:05:06,410 --> 00:05:11,020 The only real complication is that I've been increasing 95 00:05:11,020 --> 00:05:12,072 the number of variables. 96 00:05:12,072 --> 00:05:13,530 But of course, you know how to take 97 00:05:13,530 --> 00:05:16,010 a gradient for a function of three variables as well. 98 00:05:16,010 --> 00:05:21,980 So in this case, our function g of x, y, z 99 00:05:21,980 --> 00:05:25,660 is given by the square root of x squared 100 00:05:25,660 --> 00:05:29,330 plus y squared plus z squared. 101 00:05:29,330 --> 00:05:31,760 So, if you like, this is the function 102 00:05:31,760 --> 00:05:36,890 that measures the distance of a point from the origin. 103 00:05:36,890 --> 00:05:42,146 And so we're asked first for the gradient, so the gradient of g. 104 00:05:42,146 --> 00:05:45,499 105 00:05:45,499 --> 00:05:46,040 What do I do? 106 00:05:46,040 --> 00:05:50,020 Well, again, I just take these partial derivatives. 107 00:05:50,020 --> 00:05:52,902 This is going to be a tiny bit messy, I'm afraid. 108 00:05:52,902 --> 00:05:54,360 Because I take a partial derivative 109 00:05:54,360 --> 00:05:56,140 of this expression with respect to x, 110 00:05:56,140 --> 00:05:57,980 I've got to apply the chain rule, right? 111 00:05:57,980 --> 00:06:01,551 Because this is a composition of functions here. 112 00:06:01,551 --> 00:06:02,050 So OK. 113 00:06:02,050 --> 00:06:03,580 So, what do I get? 114 00:06:03,580 --> 00:06:08,161 I get the derivative of the inside times the derivative 115 00:06:08,161 --> 00:06:08,660 of the out. 116 00:06:08,660 --> 00:06:10,368 So the outside function is a square root, 117 00:06:10,368 --> 00:06:12,470 so that's to the one halfth power. 118 00:06:12,470 --> 00:06:18,665 So I get 1/2 times the thing inside to the minus one halfth 119 00:06:18,665 --> 00:06:19,165 power. 120 00:06:19,165 --> 00:06:21,360 So it's over 2 times the square root 121 00:06:21,360 --> 00:06:26,160 of x squared plus y squared plus z squared. 122 00:06:26,160 --> 00:06:29,845 And then I need to multiply by the derivative of the inside, 123 00:06:29,845 --> 00:06:32,150 which is times 2x. 124 00:06:32,150 --> 00:06:32,650 OK. 125 00:06:32,650 --> 00:06:34,360 So, and then the 2's cancel, and that's 126 00:06:34,360 --> 00:06:37,880 x over square root of x squared plus y squared plus z squared. 127 00:06:37,880 --> 00:06:40,410 And similarly, this is a nice symmetric function, 128 00:06:40,410 --> 00:06:43,200 and, you know, if I changed x and y, it's the same. 129 00:06:43,200 --> 00:06:45,770 So the other partial derivatives look very similar. 130 00:06:45,770 --> 00:06:49,970 So they're going to be y over the square root of x squared 131 00:06:49,970 --> 00:06:53,730 plus y squared plus z squared. 132 00:06:53,730 --> 00:07:00,530 And z over the square root of x squared plus y squared plus z 133 00:07:00,530 --> 00:07:01,810 squared. 134 00:07:01,810 --> 00:07:02,310 Sorry. 135 00:07:02,310 --> 00:07:05,090 That's a little bit of a long formula there. 136 00:07:05,090 --> 00:07:06,450 But there we have it. 137 00:07:06,450 --> 00:07:09,230 That's the derivative-- or, sorry, not the derivative. 138 00:07:09,230 --> 00:07:10,190 That's the gradient. 139 00:07:10,190 --> 00:07:13,100 The vector of partial derivatives. 140 00:07:13,100 --> 00:07:16,710 So now you were asked also to compute this gradient 141 00:07:16,710 --> 00:07:17,970 at a particular point. 142 00:07:17,970 --> 00:07:23,020 So the point in question-- I have to look back over here. 143 00:07:23,020 --> 00:07:29,220 And the point in question was this point, 2, 6, minus 3. 144 00:07:29,220 --> 00:07:31,362 So at the point 2, 6, minus 3, we 145 00:07:31,362 --> 00:07:32,570 want to compute the gradient. 146 00:07:32,570 --> 00:07:35,080 So we just take these numbers back over 147 00:07:35,080 --> 00:07:37,570 to our formula over there, and we're going to put them in. 148 00:07:37,570 --> 00:07:44,940 So we take the gradient of g at 2, 6, minus 3. 149 00:07:44,940 --> 00:07:49,140 Well, OK, so this square root of x squared plus y squared plus z 150 00:07:49,140 --> 00:07:50,420 squared appears in all terms. 151 00:07:50,420 --> 00:07:51,610 So let's compute that first. 152 00:07:51,610 --> 00:07:56,370 So x squared is 4, y squared is 36, and z squared is 9. 153 00:07:56,370 --> 00:07:59,910 So I add those numbers together, I get 49. 154 00:07:59,910 --> 00:08:02,600 And then I take a square root of that and I get 7. 155 00:08:02,600 --> 00:08:06,480 So these denominators are all going to be 7, and then up 156 00:08:06,480 --> 00:08:08,820 top I just have x, y, and z. 157 00:08:08,820 --> 00:08:13,580 So this is going to be 2 over 7 comma 158 00:08:13,580 --> 00:08:19,640 6 over 7 comma minus 3 over 7. 159 00:08:19,640 --> 00:08:20,330 All right. 160 00:08:20,330 --> 00:08:23,790 So just what I get by plugging the values at our point 161 00:08:23,790 --> 00:08:24,630 into this formula. 162 00:08:24,630 --> 00:08:26,890 So this is the gradient at that point. 163 00:08:26,890 --> 00:08:29,940 And now once again, I want to compute 164 00:08:29,940 --> 00:08:32,770 a particular directional derivative of this function. 165 00:08:32,770 --> 00:08:35,740 So in order to do that, I just need the right unit vector, 166 00:08:35,740 --> 00:08:38,000 and I need to dot it. 167 00:08:38,000 --> 00:08:40,060 So the direction that I asked you 168 00:08:40,060 --> 00:08:46,380 was the direction v with coordinates 1, 1, 1. 169 00:08:46,380 --> 00:08:48,340 So of course again, this isn't a unit vector. 170 00:08:48,340 --> 00:08:51,170 So we need to divide it by its length to find the unit 171 00:08:51,170 --> 00:08:53,740 vector that we're going to use. 172 00:08:53,740 --> 00:08:56,520 So the length of this vector is the square root of 1 173 00:08:56,520 --> 00:08:58,105 squared plus 1 squared plus 1 squared, 174 00:08:58,105 --> 00:08:59,950 so that's the square root of 3. 175 00:08:59,950 --> 00:09:03,050 So u is equal to-- well, I'm just 176 00:09:03,050 --> 00:09:06,080 going to write it as 1 over the square root of 3 177 00:09:06,080 --> 00:09:08,970 times the vector [1, 1, 1]. 178 00:09:08,970 --> 00:09:13,410 179 00:09:13,410 --> 00:09:20,450 And so the directional derivative dg/ds 180 00:09:20,450 --> 00:09:24,030 in the direction u hat is-- again, it's what I get, 181 00:09:24,030 --> 00:09:32,500 I dot the gradient with this u-- it's gradient dot u. 182 00:09:32,500 --> 00:09:35,830 Which in our case, so that 1 over the square root of 3 183 00:09:35,830 --> 00:09:36,720 lives out front. 184 00:09:36,720 --> 00:09:40,240 185 00:09:40,240 --> 00:09:45,730 And now I dot 2/7, 6/7, minus 3/7 with [1, 1, 1]. 186 00:09:45,730 --> 00:09:55,287 And that's just going to give me 2/7 plus 6/7 minus 3/7. 187 00:09:55,287 --> 00:09:57,370 And OK, so we can finish off the arithmetic there, 188 00:09:57,370 --> 00:10:01,430 and I think that's 5 over 7 square root of 3 189 00:10:01,430 --> 00:10:03,550 if I didn't make any mistake. 190 00:10:03,550 --> 00:10:05,960 Now, the last one, very, very similar. 191 00:10:05,960 --> 00:10:08,880 Now we have a function of four variables. 192 00:10:08,880 --> 00:10:11,060 There's really nothing new there at all. 193 00:10:11,060 --> 00:10:12,565 So let me rewrite. 194 00:10:12,565 --> 00:10:20,110 So for part c, we have h of w, x, y, 195 00:10:20,110 --> 00:10:34,060 z is equal to w*x plus w*y plus w*z plus x*y plus x*z plus y*z. 196 00:10:34,060 --> 00:10:40,770 So, for the gradient of h, I just 197 00:10:40,770 --> 00:10:42,190 take the four partial derivatives. 198 00:10:42,190 --> 00:10:43,900 Now here, w is first. 199 00:10:43,900 --> 00:10:46,290 So I take the partial derivative with respect 200 00:10:46,290 --> 00:10:48,460 to w as the first coordinate. 201 00:10:48,460 --> 00:10:53,105 So that's going to be x plus y plus z. 202 00:10:53,105 --> 00:10:55,230 And then I take the partial derivative with respect 203 00:10:55,230 --> 00:10:57,080 to x as the second coordinate. 204 00:10:57,080 --> 00:11:00,845 So that's going to be w plus y plus z. 205 00:11:00,845 --> 00:11:09,894 And similarly, the last two are w plus x plus z, and w plus-- 206 00:11:09,894 --> 00:11:15,270 that's a plus-- x plus y. 207 00:11:15,270 --> 00:11:15,770 Whew. 208 00:11:15,770 --> 00:11:16,269 OK. 209 00:11:16,269 --> 00:11:18,760 So that's my gradient. 210 00:11:18,760 --> 00:11:20,260 Those are my partial derivatives. 211 00:11:20,260 --> 00:11:23,620 Now, I asked you again for the gradient at a particular point. 212 00:11:23,620 --> 00:11:30,690 So that's grad h at the point 2, 0, minus 1, minus 1. 213 00:11:30,690 --> 00:11:32,200 So we can just plug that in. 214 00:11:32,200 --> 00:11:36,330 Here, it's 0 plus minus 1 plus minus 1 is minus 2. 215 00:11:36,330 --> 00:11:41,290 Here it's 2 plus minus 1 plus minus 1, that's 0. 216 00:11:41,290 --> 00:11:45,660 Here, it's 2 plus 0 plus minus 1 so that's 1. 217 00:11:45,660 --> 00:11:51,560 And lastly, it's 2 plus 0 plus minus 1 is 1. 218 00:11:51,560 --> 00:11:59,360 So that's the gradient of this function h at this point P. 219 00:11:59,360 --> 00:12:02,800 And now I gave you again, I gave you a vector v. So this 220 00:12:02,800 --> 00:12:07,900 was the vector 1, minus 1, 1, minus 1. 221 00:12:07,900 --> 00:12:10,170 And I asked you to find the directional derivative 222 00:12:10,170 --> 00:12:11,930 at this point in that direction. 223 00:12:11,930 --> 00:12:13,770 Again, we need a unit vector. 224 00:12:13,770 --> 00:12:15,260 This isn't a unit vector. 225 00:12:15,260 --> 00:12:22,000 So u is equal to v over the length of v. Well, what is 226 00:12:22,000 --> 00:12:24,470 the length of v in this case? 227 00:12:24,470 --> 00:12:30,679 It's over the square root of-- well, we square the coordinates 228 00:12:30,679 --> 00:12:31,220 and add them. 229 00:12:31,220 --> 00:12:33,305 So that's 1 plus 1 plus 1 plus 1. 230 00:12:33,305 --> 00:12:35,520 So that's 4; square rooted is 2. 231 00:12:35,520 --> 00:12:36,970 So that's v over 2. 232 00:12:36,970 --> 00:12:40,330 233 00:12:40,330 --> 00:12:47,510 And finally, I get that the directional derivative dh/ds 234 00:12:47,510 --> 00:12:50,980 in this direction u, is what I get 235 00:12:50,980 --> 00:12:54,550 when I dot this gradient together 236 00:12:54,550 --> 00:12:57,340 with the direction in which I'm heading. 237 00:12:57,340 --> 00:13:02,160 So this is minus 2, 0, 1, 1. 238 00:13:02,160 --> 00:13:07,330 The gradient dotted with the unit vector of the direction. 239 00:13:07,330 --> 00:13:12,060 240 00:13:12,060 --> 00:13:13,500 Which we just computed. 241 00:13:13,500 --> 00:13:15,710 And so finally, you could expand this out yourself. 242 00:13:15,710 --> 00:13:17,800 I won't write down the final answer, 243 00:13:17,800 --> 00:13:21,610 but it's just a dot product, right? 244 00:13:21,610 --> 00:13:22,180 All right. 245 00:13:22,180 --> 00:13:25,950 So hopefully this has gotten you totally 246 00:13:25,950 --> 00:13:27,850 comfortable with computing gradients 247 00:13:27,850 --> 00:13:30,920 and with computing directional derivatives from gradients. 248 00:13:30,920 --> 00:13:32,580 So I'll end there. 249 00:13:32,580 --> 00:13:33,080