1 00:00:01,580 --> 00:00:03,920 The following content is provided under a Creative 2 00:00:03,920 --> 00:00:05,340 Commons license. 3 00:00:05,340 --> 00:00:07,550 Your support will help MIT OpenCourseWare 4 00:00:07,550 --> 00:00:11,640 continue to offer high quality educational resources for free. 5 00:00:11,640 --> 00:00:14,180 To make a donation or to view additional materials 6 00:00:14,180 --> 00:00:18,110 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:18,110 --> 00:00:19,340 at ocw.mit.edu. 8 00:00:24,420 --> 00:00:25,900 JAMES SWAN: OK, shall we begin? 9 00:00:29,000 --> 00:00:30,450 So on the syllabus, today's class 10 00:00:30,450 --> 00:00:33,580 is supposed to be a review for the next quiz. 11 00:00:33,580 --> 00:00:36,540 And I'm happy to answer any questions you 12 00:00:36,540 --> 00:00:40,350 have about the material or about the quiz 13 00:00:40,350 --> 00:00:42,120 to the best of my ability. 14 00:00:42,120 --> 00:00:45,270 And when we've exhausted those questions, 15 00:00:45,270 --> 00:00:49,679 I have some notes on another method for solving 16 00:00:49,679 --> 00:00:50,970 partial differential equations. 17 00:00:50,970 --> 00:00:52,428 We didn't really cover it in class, 18 00:00:52,428 --> 00:00:54,690 but I think it's quite interesting and applicable 19 00:00:54,690 --> 00:00:57,210 for chemical engineers in particular 20 00:00:57,210 --> 00:00:59,490 because of the classes of problems that we study. 21 00:00:59,490 --> 00:01:04,830 And then notes on how to construct a simulation of a PDE 22 00:01:04,830 --> 00:01:07,920 that follow from what Professor Green discussed 23 00:01:07,920 --> 00:01:10,160 during your last PDE lecture. 24 00:01:10,160 --> 00:01:12,570 And we'll do an example where we actually 25 00:01:12,570 --> 00:01:15,120 develop a code to solve the PDE and maybe refine it 26 00:01:15,120 --> 00:01:19,440 so that it runs more quickly by noticing 27 00:01:19,440 --> 00:01:21,760 certain things about the structure of the problem. 28 00:01:21,760 --> 00:01:23,010 OK? 29 00:01:23,010 --> 00:01:24,990 I have your gift cards. 30 00:01:24,990 --> 00:01:26,590 I remembered them. 31 00:01:26,590 --> 00:01:29,010 So I'll hand those out at the end the class, just in case 32 00:01:29,010 --> 00:01:30,840 more people trickle in. 33 00:01:30,840 --> 00:01:33,250 But it doesn't look like there's 53 people here, 34 00:01:33,250 --> 00:01:36,591 so maybe the TAs are going to be eating burritos for a while. 35 00:01:36,591 --> 00:01:38,090 There's going to be a lot left over. 36 00:01:38,090 --> 00:01:38,800 We'll see. 37 00:01:38,800 --> 00:01:41,790 I'll hold onto them. 38 00:01:41,790 --> 00:01:44,190 Try to make sure everyone gets their reward 39 00:01:44,190 --> 00:01:47,730 for responding to the class survey. 40 00:01:47,730 --> 00:01:50,970 So let's start with questions about the quiz, about 41 00:01:50,970 --> 00:01:54,930 the material that we've covered up to this point. 42 00:01:54,930 --> 00:01:58,590 I'm really going to leave it to you to point out things 43 00:01:58,590 --> 00:02:01,230 that you feel like you need help with, 44 00:02:01,230 --> 00:02:02,550 you think need to be reviewed. 45 00:02:02,550 --> 00:02:05,130 I know you've had a review session with the TAs already. 46 00:02:05,130 --> 00:02:06,833 Maybe that's been sufficient. 47 00:02:06,833 --> 00:02:07,720 OK? 48 00:02:07,720 --> 00:02:09,865 Questions. 49 00:02:09,865 --> 00:02:10,490 It's up to you. 50 00:02:10,490 --> 00:02:10,990 Yeah. 51 00:02:10,990 --> 00:02:14,392 AUDIENCE: Will the test contain chemical engineering material 52 00:02:14,392 --> 00:02:15,766 like last year's test, or will it 53 00:02:15,766 --> 00:02:17,181 be like Professor Green's test. 54 00:02:17,181 --> 00:02:18,430 JAMES SWAN: Oh, good question. 55 00:02:18,430 --> 00:02:22,870 So I'll tell you that I believe the problems 56 00:02:22,870 --> 00:02:25,930 on the quiz this year are motivated 57 00:02:25,930 --> 00:02:29,630 by chemical engineering problems, OK? 58 00:02:29,630 --> 00:02:32,050 The reason for that is, unlike linear algebra problems 59 00:02:32,050 --> 00:02:34,540 or optimization problems, those can 60 00:02:34,540 --> 00:02:36,690 be crafted out of whole cloth. 61 00:02:36,690 --> 00:02:41,260 But workable, right, boundary value problems, 62 00:02:41,260 --> 00:02:43,330 workable initial value problems really 63 00:02:43,330 --> 00:02:45,670 need to stem from something physical. 64 00:02:45,670 --> 00:02:49,390 You are not asked to derive anything 65 00:02:49,390 --> 00:02:51,850 from your extensive chemical engineering knowledge. 66 00:02:51,850 --> 00:02:55,150 This is not a qualifier for reactors or thermo 67 00:02:55,150 --> 00:02:55,900 or transport. 68 00:02:55,900 --> 00:02:58,251 We provide you with those details. 69 00:02:58,251 --> 00:02:58,750 OK? 70 00:02:58,750 --> 00:03:02,290 But they are-- I think they are of a chemical engineering 71 00:03:02,290 --> 00:03:03,280 origin. 72 00:03:03,280 --> 00:03:06,586 So you have equations that are reasonable to work with. 73 00:03:06,586 --> 00:03:08,290 OK? 74 00:03:08,290 --> 00:03:09,100 More questions. 75 00:03:15,420 --> 00:03:16,200 Yes. 76 00:03:16,200 --> 00:03:17,700 AUDIENCE: I would love to briefly go 77 00:03:17,700 --> 00:03:20,760 over some boundary value problems, specifically 78 00:03:20,760 --> 00:03:22,266 like the collocation and-- 79 00:03:22,266 --> 00:03:22,890 JAMES SWAN: OK. 80 00:03:22,890 --> 00:03:24,420 AUDIENCE: --Galerkin methods, maybe. 81 00:03:24,420 --> 00:03:26,080 JAMES SWAN: Sure. 82 00:03:26,080 --> 00:03:29,100 So OK. 83 00:03:29,100 --> 00:03:33,245 So let's just discuss boundary value problems first. 84 00:03:33,245 --> 00:03:35,877 Turns out PDEs are a class of boundary value problem, too, 85 00:03:35,877 --> 00:03:37,960 largely, at least the ones that chemical engineers 86 00:03:37,960 --> 00:03:38,780 are interested in. 87 00:03:38,780 --> 00:03:41,390 So if we understand boundary value problems in general, 88 00:03:41,390 --> 00:03:44,320 we should understand how to solve partial differential 89 00:03:44,320 --> 00:03:46,034 equations too. 90 00:03:46,034 --> 00:03:47,950 Many classes of partial differential equations 91 00:03:47,950 --> 00:03:50,366 that we're interested in can also be solved in these ways. 92 00:03:50,366 --> 00:03:53,620 So we talked about relaxation methods 93 00:03:53,620 --> 00:03:57,610 in general, which were these methods that 94 00:03:57,610 --> 00:04:02,890 rely on somehow discretizing the continuous function that we're 95 00:04:02,890 --> 00:04:05,980 trying to describe in this boundary value problem. 96 00:04:05,980 --> 00:04:07,480 So usually, you've got some-- 97 00:04:10,780 --> 00:04:14,410 linear function, some linear operator 98 00:04:14,410 --> 00:04:17,230 that operates on some variable that we're trying to understand 99 00:04:17,230 --> 00:04:18,550 in a boundary value problem. 100 00:04:18,550 --> 00:04:23,720 Maybe it's temperature, right, equals 0. 101 00:04:23,720 --> 00:04:27,850 So it's going to be something like thermal diffusion. 102 00:04:27,850 --> 00:04:29,350 This equation could represent that. 103 00:04:29,350 --> 00:04:31,480 Could represent some advection diffusion problem 104 00:04:31,480 --> 00:04:32,800 in some bounded domain. 105 00:04:32,800 --> 00:04:34,120 Could be a PDE. 106 00:04:34,120 --> 00:04:39,070 It could just be an ordinary differential equation, right, 107 00:04:39,070 --> 00:04:40,760 but a boundary value problem. 108 00:04:40,760 --> 00:04:43,960 And with this class of relaxation methods, 109 00:04:43,960 --> 00:04:46,990 we try not to exactly satisfy this equation. 110 00:04:46,990 --> 00:04:49,450 We relax that assumption. 111 00:04:49,450 --> 00:04:52,500 We try to somehow discretize this function. 112 00:04:52,500 --> 00:04:54,510 It could be temperature, could be energy, 113 00:04:54,510 --> 00:04:56,200 could be velocity or momentum. 114 00:04:56,200 --> 00:04:57,970 It could be lots of different things. 115 00:04:57,970 --> 00:05:01,570 Try to relax the constraint that this is satisfied everywhere. 116 00:05:01,570 --> 00:05:05,290 And we try to satisfy in some approximate sense instead. 117 00:05:05,290 --> 00:05:07,480 So we discussed collocation methods, 118 00:05:07,480 --> 00:05:09,700 where we take the domain we're interested in 119 00:05:09,700 --> 00:05:12,520 and we divide it up into a series of points. 120 00:05:12,520 --> 00:05:17,050 And we try to satisfy this equation at those points. 121 00:05:17,050 --> 00:05:20,030 And we have some approximation for the function, 122 00:05:20,030 --> 00:05:21,700 its representation at those points. 123 00:05:21,700 --> 00:05:24,460 That approximation could be a finite difference 124 00:05:24,460 --> 00:05:26,530 approximation. 125 00:05:26,530 --> 00:05:31,510 That approximation could be a basis set expansion. 126 00:05:31,510 --> 00:05:35,590 It could be a finite volume approximation. 127 00:05:35,590 --> 00:05:38,500 We could expand in terms of local basis functions. 128 00:05:38,500 --> 00:05:40,810 That's the finite element method. 129 00:05:40,810 --> 00:05:42,580 We covered all these different methods. 130 00:05:42,580 --> 00:05:44,344 That involves chopping the domain up 131 00:05:44,344 --> 00:05:45,760 into a series of points and trying 132 00:05:45,760 --> 00:05:47,760 to satisfy the function at each of those points. 133 00:05:50,830 --> 00:05:53,729 There was an alternative method, this sort of Galerkin method, 134 00:05:53,729 --> 00:05:56,020 where instead of trying to satisfy the function at each 135 00:05:56,020 --> 00:05:59,390 of those points, we have some basis set expansion. 136 00:05:59,390 --> 00:06:02,500 So we have some approximate representation 137 00:06:02,500 --> 00:06:06,260 of our function in terms of these basis sets-- 138 00:06:06,260 --> 00:06:08,050 in terms of this basis set. 139 00:06:08,050 --> 00:06:09,880 And instead, we try to make it be the case 140 00:06:09,880 --> 00:06:18,510 that the integral of our operator 141 00:06:18,510 --> 00:06:20,880 applied to our approximation-- 142 00:06:20,880 --> 00:06:22,950 I'm going to break chalk-- 143 00:06:22,950 --> 00:06:25,500 multiplied by each of the basis functions 144 00:06:25,500 --> 00:06:31,870 and then integrated over this entire domain is equal to 0. 145 00:06:31,870 --> 00:06:37,782 So we try to satisfy this equation with respect 146 00:06:37,782 --> 00:06:39,990 to each of these basis functions, essentially, right? 147 00:06:39,990 --> 00:06:42,120 There's some-- this isn't going to exactly satisfy 148 00:06:42,120 --> 00:06:43,184 the equation. 149 00:06:43,184 --> 00:06:44,225 This is an approximation. 150 00:06:44,225 --> 00:06:46,391 It's not going to exactly satisfy the boundary value 151 00:06:46,391 --> 00:06:47,940 problem we were after. 152 00:06:47,940 --> 00:06:50,880 But the projection of the residual, 153 00:06:50,880 --> 00:06:52,980 or how far off we are with this operator, 154 00:06:52,980 --> 00:06:54,850 on each of the basis functions, we're 155 00:06:54,850 --> 00:06:56,760 going to try to force to be 0. 156 00:06:56,760 --> 00:06:59,250 So rather than trying to get a pointwise solution 157 00:06:59,250 --> 00:07:02,910 of the problem, we're going to try to sort of smooth out 158 00:07:02,910 --> 00:07:05,730 the error with respect to the basis functions 159 00:07:05,730 --> 00:07:09,000 and make this equation is satisfied 160 00:07:09,000 --> 00:07:12,000 as it possibly can with respect to these basis functions. 161 00:07:12,000 --> 00:07:14,490 And that's the Galerkin view. 162 00:07:14,490 --> 00:07:15,240 So it's different. 163 00:07:15,240 --> 00:07:17,160 It's like you're trying to minimize 164 00:07:17,160 --> 00:07:20,460 sort of a global error with respect to the basis functions, 165 00:07:20,460 --> 00:07:23,190 as opposed to a pointwise error, OK? 166 00:07:23,190 --> 00:07:25,230 And again, these basis functions can be chosen 167 00:07:25,230 --> 00:07:26,355 in a lot of different ways. 168 00:07:26,355 --> 00:07:28,480 They can be chosen as sort of global functions. 169 00:07:28,480 --> 00:07:31,230 They can be things like sines and cosines. 170 00:07:31,230 --> 00:07:33,210 We may know that the solution to this equation 171 00:07:33,210 --> 00:07:36,060 looks a lot like sines and cosines, so that makes sense. 172 00:07:36,060 --> 00:07:38,350 Or we may choose local basis functions instead, 173 00:07:38,350 --> 00:07:41,190 little tent functions in 1D. 174 00:07:41,190 --> 00:07:43,970 They're actually tent functions in many dimensions as well. 175 00:07:43,970 --> 00:07:46,530 You can imagine sort of extending that to look 176 00:07:46,530 --> 00:07:48,210 like a tent in many dimensions. 177 00:07:48,210 --> 00:07:51,000 That's the finite element method. 178 00:07:51,000 --> 00:07:53,860 So we can choose those basis functions however we want. 179 00:07:53,860 --> 00:07:57,090 And the goal is to just minimize this residual with respect 180 00:07:57,090 --> 00:07:59,430 to each of the basis functions that we include 181 00:07:59,430 --> 00:08:01,005 in our approximate solution. 182 00:08:01,005 --> 00:08:04,440 And we would call that a reasonable approximation. 183 00:08:04,440 --> 00:08:06,450 Presumably, as the number of basis functions 184 00:08:06,450 --> 00:08:09,296 goes to infinity, this is going to converge. 185 00:08:09,296 --> 00:08:10,920 That's the applied mathematician's job, 186 00:08:10,920 --> 00:08:14,070 to show us that it's going to converge to the true solution 187 00:08:14,070 --> 00:08:15,610 of the equations. 188 00:08:15,610 --> 00:08:17,450 OK? 189 00:08:17,450 --> 00:08:20,120 So those are the methods that we-- 190 00:08:20,120 --> 00:08:22,310 those are the methods that we apply. 191 00:08:22,310 --> 00:08:24,860 Good choices of basis function are important. 192 00:08:24,860 --> 00:08:28,100 So there was this discussion about quantum chemistry, 193 00:08:28,100 --> 00:08:31,760 where you're trying to solve the Schrodinger 194 00:08:31,760 --> 00:08:35,350 equation for n electrons, there's 3n degrees of freedom. 195 00:08:35,350 --> 00:08:37,630 So a very high-dimensional space. 196 00:08:37,630 --> 00:08:38,929 How are you going to do that? 197 00:08:38,929 --> 00:08:40,640 You do it with basis set expansions. 198 00:08:40,640 --> 00:08:43,570 And the choice of those basis functions is really important. 199 00:08:43,570 --> 00:08:45,320 So if you read a quantum chemistry paper, 200 00:08:45,320 --> 00:08:48,320 you'll see they give a long series of digits and numbers 201 00:08:48,320 --> 00:08:51,440 that are meant to indicate which basis set expansion they used. 202 00:08:51,440 --> 00:08:53,090 And for certain classes of problem, 203 00:08:53,090 --> 00:08:54,590 some are better than others. 204 00:08:54,590 --> 00:08:56,540 And they make the problem actually 205 00:08:56,540 --> 00:09:00,880 solvable when it's not, if you were to just choose your basis 206 00:09:00,880 --> 00:09:04,800 functions without care for the physics of the problem. 207 00:09:04,800 --> 00:09:05,300 Sam. 208 00:09:05,300 --> 00:09:09,960 AUDIENCE: The last homework, in the Galerkin method, 209 00:09:09,960 --> 00:09:11,830 where you multiplied by the complex, 210 00:09:11,830 --> 00:09:14,580 how did you get one basis set, basis functions? 211 00:09:14,580 --> 00:09:18,630 Where does that fit into this? 212 00:09:18,630 --> 00:09:21,222 JAMES SWAN: Well, it should have been right here. 213 00:09:21,222 --> 00:09:22,680 So technically, the basis functions 214 00:09:22,680 --> 00:09:24,850 don't have to be real-valued functions. 215 00:09:24,850 --> 00:09:26,910 They can be complex-valued functions. 216 00:09:26,910 --> 00:09:31,440 And then this is, in some sense, a dot product, 217 00:09:31,440 --> 00:09:34,950 an inner product in the space of these basic functions. 218 00:09:34,950 --> 00:09:36,960 And the proper form for an inner product 219 00:09:36,960 --> 00:09:39,150 when we have complex-valued things 220 00:09:39,150 --> 00:09:41,310 is to take the real part of one and multiply it 221 00:09:41,310 --> 00:09:43,110 with the complex part of another. 222 00:09:43,110 --> 00:09:45,780 So that should have been right here. 223 00:09:45,780 --> 00:09:47,760 This should be the complex conjugate. 224 00:09:47,760 --> 00:09:48,986 OK? 225 00:09:48,986 --> 00:09:49,486 Yeah. 226 00:09:49,486 --> 00:09:51,496 AUDIENCE: So when we do the Galerkin method, 227 00:09:51,496 --> 00:09:54,810 we necessarily have to approximate these derivatives 228 00:09:54,810 --> 00:09:56,430 and things using basis functions. 229 00:09:56,430 --> 00:09:56,685 JAMES SWAN: Yes. 230 00:09:56,685 --> 00:09:58,505 AUDIENCE: But in the collocation method, 231 00:09:58,505 --> 00:10:00,546 there was lots of other ways that we could do it, 232 00:10:00,546 --> 00:10:01,690 like find differences. 233 00:10:01,690 --> 00:10:02,160 I know you mentioned a few of them earlier. 234 00:10:02,160 --> 00:10:02,970 JAMES SWAN: Yes. 235 00:10:02,970 --> 00:10:03,916 Yes. 236 00:10:03,916 --> 00:10:04,790 AUDIENCE: OK. 237 00:10:04,790 --> 00:10:05,150 JAMES SWAN: That's right. 238 00:10:05,150 --> 00:10:07,600 AUDIENCE: That [? LOT term ?] kind of contains also 239 00:10:07,600 --> 00:10:09,560 the basis function in the Galerkin method, 240 00:10:09,560 --> 00:10:11,825 or in the collocation method. 241 00:10:11,825 --> 00:10:15,250 JAMES SWAN: Well, in the-- if we have 242 00:10:15,250 --> 00:10:18,711 an expansion of the sort of objective 243 00:10:18,711 --> 00:10:20,960 that we're trying to calculate in terms of those basis 244 00:10:20,960 --> 00:10:25,130 functions, L is the real L, right? 245 00:10:25,130 --> 00:10:25,940 It is what it is. 246 00:10:25,940 --> 00:10:28,470 This is the model equation to be solved. 247 00:10:28,470 --> 00:10:33,140 We operate on our approximate solution with the real L. 248 00:10:33,140 --> 00:10:36,170 In the collocation method, it may be the real L, 249 00:10:36,170 --> 00:10:37,830 or it may be some approximation for L. 250 00:10:37,830 --> 00:10:40,100 If we do finite differences, we're approximating 251 00:10:40,100 --> 00:10:42,320 all these derivatives. 252 00:10:42,320 --> 00:10:44,480 If we do a basis set expansion and we 253 00:10:44,480 --> 00:10:47,990 try to satisfy that at a certain number of points, 254 00:10:47,990 --> 00:10:51,950 we're not approximating L. We're approximating T instead. 255 00:10:51,950 --> 00:10:54,008 So they're a little bit different. 256 00:10:57,220 --> 00:10:59,580 More questions? 257 00:10:59,580 --> 00:11:00,810 So that's BVPs. 258 00:11:00,810 --> 00:11:03,300 This picture applies for PDEs, too. 259 00:11:03,300 --> 00:11:06,570 So this is the integral over the domain 260 00:11:06,570 --> 00:11:10,110 of interest, the domain that's bounded by our boundary 261 00:11:10,110 --> 00:11:12,270 conditions. 262 00:11:12,270 --> 00:11:14,711 These basis functions don't have to be in one dimension. 263 00:11:14,711 --> 00:11:16,710 They can be in any number of dimensions we want. 264 00:11:16,710 --> 00:11:19,860 We just want them to be good basis functions in principle. 265 00:11:19,860 --> 00:11:22,705 So for finite elements, you use little tents. 266 00:11:22,705 --> 00:11:25,080 They're multi-dimensional tents, but they're still tents. 267 00:11:25,080 --> 00:11:27,810 The same as these hat functions that Professor Green 268 00:11:27,810 --> 00:11:28,860 talked about in 1D. 269 00:11:28,860 --> 00:11:30,779 Just do them in many dimensions. 270 00:11:30,779 --> 00:11:32,070 They work exactly the same way. 271 00:11:32,070 --> 00:11:33,736 They're easy to take the derivatives of. 272 00:11:33,736 --> 00:11:36,730 These intervals are, for the most part, simple to calculate. 273 00:11:36,730 --> 00:11:41,570 And that's why COMSOL, for example, uses that methodology. 274 00:11:41,570 --> 00:11:45,540 It's based on this sort of Galerkin picture. 275 00:11:45,540 --> 00:11:49,712 So PDEs, BVPs look very similar. 276 00:11:49,712 --> 00:11:51,920 Usually, when we're talking about spatial dimensions, 277 00:11:51,920 --> 00:11:53,640 they look very similar. 278 00:11:53,640 --> 00:11:55,650 When we go to the time domain, things 279 00:11:55,650 --> 00:11:57,600 get a little more confusing. 280 00:11:57,600 --> 00:12:02,272 That mixes together what we know from ODE IVPs with what 281 00:12:02,272 --> 00:12:03,980 we know from boundary value problems now. 282 00:12:03,980 --> 00:12:05,730 So you talked about the method of lines 283 00:12:05,730 --> 00:12:08,220 last time as one way of studying, 284 00:12:08,220 --> 00:12:11,430 for example, parabolic partial differential equations. 285 00:12:11,430 --> 00:12:14,400 You have the spatial discretization like this. 286 00:12:14,400 --> 00:12:17,970 And then in time, you have some ODE IVP technique 287 00:12:17,970 --> 00:12:19,490 that you integrate forward. 288 00:12:19,490 --> 00:12:22,470 You rely on these robust ODE methods that 289 00:12:22,470 --> 00:12:24,240 know how to control the numerical error, 290 00:12:24,240 --> 00:12:27,420 can detect, maybe, when there's some sort of an instability 291 00:12:27,420 --> 00:12:32,190 and try to damp it out by altering the time step so 292 00:12:32,190 --> 00:12:35,630 that things stay stable. 293 00:12:35,630 --> 00:12:36,157 Yes? 294 00:12:36,157 --> 00:12:37,990 AUDIENCE: I can't visualize the local basis. 295 00:12:37,990 --> 00:12:42,752 Can you give me an [INAUDIBLE] expression for the local basis? 296 00:12:42,752 --> 00:12:43,460 JAMES SWAN: Sure. 297 00:12:49,515 --> 00:12:51,890 So first of all, there are a lot of local basis functions 298 00:12:51,890 --> 00:12:53,460 we could write down, OK? 299 00:12:53,460 --> 00:12:53,970 AUDIENCE: This is just one of them. 300 00:12:53,970 --> 00:12:54,500 JAMES SWAN: There are many of them. 301 00:12:54,500 --> 00:12:56,310 So yes, let's do the hat. 302 00:12:56,310 --> 00:12:56,810 OK? 303 00:13:03,270 --> 00:13:06,570 Let's suppose I have this line in x, 304 00:13:06,570 --> 00:13:09,630 and I target in my collocation method 305 00:13:09,630 --> 00:13:13,050 a series of points, column x i minus 1, xi, x i plus 1, 306 00:13:13,050 --> 00:13:15,280 and they extend well beyond here. 307 00:13:15,280 --> 00:13:17,310 It doesn't matter where they are. 308 00:13:17,310 --> 00:13:20,280 I choose where they are based on the physics of the problem. 309 00:13:20,280 --> 00:13:22,230 I'll put them where I want them to go. 310 00:13:22,230 --> 00:13:25,877 And in fact, you might even try to optimize where they go. 311 00:13:25,877 --> 00:13:27,960 So you might start with some distribution of them, 312 00:13:27,960 --> 00:13:29,512 and then move them around in some way 313 00:13:29,512 --> 00:13:31,470 to improve the quality of your solution, right? 314 00:13:31,470 --> 00:13:34,060 Maybe you distribute them uniformly at first, 315 00:13:34,060 --> 00:13:36,060 and then you notice, oh, my solution is changing 316 00:13:36,060 --> 00:13:38,010 very quickly over here. 317 00:13:38,010 --> 00:13:42,091 I would like more points in this region. 318 00:13:42,091 --> 00:13:43,590 In MATLAB, there's a function called 319 00:13:43,590 --> 00:13:46,860 bvp4c, which is a boundary value problem solver. 320 00:13:46,860 --> 00:13:48,506 It solves 1D boundary value problems. 321 00:13:48,506 --> 00:13:49,630 And it does precisely this. 322 00:13:49,630 --> 00:13:52,080 It uses finite differences and collocation. 323 00:13:52,080 --> 00:13:54,090 And the good thing about it is it's 324 00:13:54,090 --> 00:13:56,040 trying to adaptively change where 325 00:13:56,040 --> 00:13:57,270 these points are positioned. 326 00:13:57,270 --> 00:14:00,930 So it solves it, it looks where things are changing quickly, 327 00:14:00,930 --> 00:14:05,496 and tries to shift its points around and resolve it in order 328 00:14:05,496 --> 00:14:07,120 to improve the quality of the solution, 329 00:14:07,120 --> 00:14:10,751 hit certain targets for the error. 330 00:14:10,751 --> 00:14:12,750 So what are these-- what would these local basis 331 00:14:12,750 --> 00:14:13,650 functions look like? 332 00:14:13,650 --> 00:14:15,660 So we talked about these hats. 333 00:14:15,660 --> 00:14:16,395 They're 1 here. 334 00:14:18,990 --> 00:14:21,820 They're going to be 0 on either side of this point. 335 00:14:21,820 --> 00:14:27,940 We could call this our hat i, which is centered at point xi. 336 00:14:27,940 --> 00:14:33,720 And it's going to be a piecewise sort of function. 337 00:14:33,720 --> 00:14:37,560 It's going to be an increasing linear function between x i 338 00:14:37,560 --> 00:14:39,120 minus 1 and xi. 339 00:14:39,120 --> 00:14:44,510 So for x between xi and x i minus 1, it'll have one form. 340 00:14:44,510 --> 00:14:45,670 Then it's going to switch. 341 00:14:45,670 --> 00:14:48,044 It's going to be a decreasing function on the other side. 342 00:14:48,044 --> 00:14:55,060 So between xi and x i plus 1, it'll have a different form. 343 00:14:55,060 --> 00:14:57,535 So here, it's going to increase between 0 and 1. 344 00:14:57,535 --> 00:14:59,160 So it's going to have to look something 345 00:14:59,160 --> 00:15:07,650 like x minus x i minus 1 divided by xi minus x i minus 1. 346 00:15:07,650 --> 00:15:09,847 So it goes from 0 to 1. 347 00:15:09,847 --> 00:15:11,430 And then on the other side, it's going 348 00:15:11,430 --> 00:15:13,920 to have to have the opposite sign. 349 00:15:13,920 --> 00:15:15,950 So this is going to have to look like-- 350 00:15:15,950 --> 00:15:24,250 let's see, x minus x i plus 1 divided by xi minus x i plus 1. 351 00:15:24,250 --> 00:15:25,500 Will that do it? 352 00:15:25,500 --> 00:15:26,540 I think so. 353 00:15:26,540 --> 00:15:28,380 OK? 354 00:15:28,380 --> 00:15:30,130 You want me to make it look like this one. 355 00:15:30,130 --> 00:15:33,430 So we could have plus 1 xi, and then put a minus sign 356 00:15:33,430 --> 00:15:35,210 in front of it if you want. 357 00:15:35,210 --> 00:15:37,780 You decide how you want to write it. 358 00:15:37,780 --> 00:15:40,210 But it describes this line here and this line here. 359 00:15:40,210 --> 00:15:42,420 But there are other choices. 360 00:15:42,420 --> 00:15:46,060 So it doesn't have to be piecewise linear necessarily. 361 00:15:46,060 --> 00:15:48,700 A lot of times, people choose different types 362 00:15:48,700 --> 00:15:52,240 of splines, different types of interpolating functions. 363 00:15:52,240 --> 00:15:54,130 They might not be localized to one point. 364 00:15:54,130 --> 00:15:56,620 They might be localized over a few points. 365 00:15:56,620 --> 00:15:59,260 Maybe something about the physics of a particular problem 366 00:15:59,260 --> 00:16:01,990 that tell you, you can't get away 367 00:16:01,990 --> 00:16:04,270 with these piecewise linear functions. 368 00:16:04,270 --> 00:16:06,130 They're not good enough to describe, 369 00:16:06,130 --> 00:16:08,430 say, higher-order derivatives in your equation. 370 00:16:08,430 --> 00:16:11,800 So you might instead interpolate with, I don't know, 371 00:16:11,800 --> 00:16:15,256 like a quadratic basis function that spans a few more points. 372 00:16:15,256 --> 00:16:15,880 That'd be fine. 373 00:16:15,880 --> 00:16:18,400 It would be easy to do the integration in your Galerkin 374 00:16:18,400 --> 00:16:19,240 method. 375 00:16:19,240 --> 00:16:21,500 You just do these integrals out. 376 00:16:21,500 --> 00:16:24,880 They're complicated, but you do them once for a generic point 377 00:16:24,880 --> 00:16:29,069 xi, and you know their value for every point in the domain. 378 00:16:29,069 --> 00:16:29,860 So you choose them. 379 00:16:29,860 --> 00:16:30,901 You choose the basis set. 380 00:16:33,430 --> 00:16:36,910 But that'll give me an equation for the tent function centered 381 00:16:36,910 --> 00:16:37,424 at xi. 382 00:16:37,424 --> 00:16:39,340 That's the tent function centered at any point 383 00:16:39,340 --> 00:16:42,250 in the domain, in principle. 384 00:16:42,250 --> 00:16:45,680 In many dimensions, right-- so if I have two dimensions, 385 00:16:45,680 --> 00:16:50,994 you see in COMSOL, you have a sort of a triangular mesh. 386 00:16:50,994 --> 00:16:52,410 And what does my tent function do? 387 00:16:52,410 --> 00:16:58,030 It sort of stands up, stands up above the triangle. 388 00:16:58,030 --> 00:16:58,980 It's a real tent now. 389 00:16:58,980 --> 00:16:59,850 It's coming out of the board. 390 00:16:59,850 --> 00:17:00,600 Can you see it? 391 00:17:00,600 --> 00:17:01,590 Put on your 3D glasses. 392 00:17:01,590 --> 00:17:02,240 You'll see it. 393 00:17:02,240 --> 00:17:03,860 But it's coming out of the board. 394 00:17:03,860 --> 00:17:06,545 It has height 1 above this triangular domain. 395 00:17:06,545 --> 00:17:08,670 It sits at the center of the triangle, for example. 396 00:17:08,670 --> 00:17:10,010 It's one way to draw these elements. 397 00:17:10,010 --> 00:17:11,490 There are actually many ways to draw these elements. 398 00:17:11,490 --> 00:17:13,676 This is just one way of drawing these elements. 399 00:17:13,676 --> 00:17:16,560 OK? 400 00:17:16,560 --> 00:17:17,060 Good. 401 00:17:17,060 --> 00:17:19,730 Other questions? 402 00:17:19,730 --> 00:17:21,646 AUDIENCE: Could you please explain why central 403 00:17:21,646 --> 00:17:24,569 differencing is second-order accurate and not-- 404 00:17:24,569 --> 00:17:25,829 JAMES SWAN: Oh, good question. 405 00:17:28,697 --> 00:17:29,280 Good question. 406 00:17:29,280 --> 00:17:33,331 So why is central differencing second-order accurate? 407 00:17:36,770 --> 00:17:40,520 So the central difference formula 408 00:17:40,520 --> 00:17:44,270 says that the derivative of a function x 409 00:17:44,270 --> 00:17:46,045 could be written as-- 410 00:17:46,045 --> 00:17:53,450 let's see, f at x i plus 1 minus f at x i minus 1, 411 00:17:53,450 --> 00:17:57,650 divided by 2 delta x. 412 00:17:57,650 --> 00:17:59,662 Or let's say these aren't equally spaced points. 413 00:17:59,662 --> 00:18:01,870 Well, let's make these equally spaced points for now. 414 00:18:01,870 --> 00:18:04,160 Let's make it easy. 415 00:18:04,160 --> 00:18:11,149 So let's say x i plus delta x and x i minus-- 416 00:18:11,149 --> 00:18:13,190 it'll make our lives easier if we do it this way. 417 00:18:13,190 --> 00:18:16,190 It can be generalized, but let's do it the easiest possible way. 418 00:18:16,190 --> 00:18:19,000 And this is the derivative at the point xi. 419 00:18:19,000 --> 00:18:24,890 Graphically, here's x, here's xi. 420 00:18:24,890 --> 00:18:26,680 Here's my function. 421 00:18:26,680 --> 00:18:28,490 I want to know what the slope here is. 422 00:18:31,340 --> 00:18:34,040 And I'm going to approximate it by looking one point upstream 423 00:18:34,040 --> 00:18:37,000 and one point downstream. 424 00:18:37,000 --> 00:18:40,730 And I'm going to connect those points with a line. 425 00:18:40,730 --> 00:18:42,800 You would agree that as the spacing gets 426 00:18:42,800 --> 00:18:45,350 smaller and smaller, it will be a good approximation for what 427 00:18:45,350 --> 00:18:46,100 the derivative is. 428 00:18:46,100 --> 00:18:48,370 So why is it second-order accurate? 429 00:18:48,370 --> 00:18:51,050 So you can show that. 430 00:18:51,050 --> 00:18:53,080 It's not too hard. 431 00:18:53,080 --> 00:18:55,190 You can show that using Taylor series expansion. 432 00:18:55,190 --> 00:18:56,750 Like everything else in this course, 433 00:18:56,750 --> 00:18:58,166 the Taylor series is really a key. 434 00:18:58,166 --> 00:19:00,230 So let's look at it. 435 00:19:00,230 --> 00:19:05,745 So f at x i plus delta x. 436 00:19:05,745 --> 00:19:07,370 I want to write this as a Taylor series 437 00:19:07,370 --> 00:19:10,220 expansion about the point xi. 438 00:19:10,220 --> 00:19:13,121 So tell me the first term. 439 00:19:13,121 --> 00:19:13,620 f of xi. 440 00:19:16,690 --> 00:19:19,842 OK, tell me the second term. 441 00:19:19,842 --> 00:19:22,590 AUDIENCE: f prime at xi. 442 00:19:22,590 --> 00:19:24,450 JAMES SWAN: f prime at xi. 443 00:19:24,450 --> 00:19:25,490 Times? 444 00:19:25,490 --> 00:19:26,240 AUDIENCE: Delta x. 445 00:19:26,240 --> 00:19:27,750 JAMES SWAN: Delta x. 446 00:19:27,750 --> 00:19:30,175 Tell me the third term. 447 00:19:30,175 --> 00:19:32,400 AUDIENCE: 1/2 f double prime. 448 00:19:32,400 --> 00:19:35,550 JAMES SWAN: 1/2 f double prime at? 449 00:19:35,550 --> 00:19:36,630 AUDIENCE: Xi. 450 00:19:36,630 --> 00:19:37,380 JAMES SWAN: Times? 451 00:19:37,380 --> 00:19:39,800 AUDIENCE: Delta x squared. 452 00:19:39,800 --> 00:19:41,537 JAMES SWAN: How big is the third term? 453 00:19:41,537 --> 00:19:43,297 AUDIENCE: [INAUDIBLE]. 454 00:19:43,297 --> 00:19:43,922 JAMES SWAN: OK. 455 00:19:47,270 --> 00:19:50,370 Is this always true, by the way? 456 00:19:50,370 --> 00:19:51,540 This? 457 00:19:51,540 --> 00:19:52,597 Not always, right? 458 00:19:52,597 --> 00:19:54,930 There are lots of functions, non-analytic functions that 459 00:19:54,930 --> 00:19:56,530 don't have these sorts of expansions. 460 00:19:56,530 --> 00:19:58,007 So we're sort of-- 461 00:19:58,007 --> 00:20:00,340 we've got to have a function that has these derivatives. 462 00:20:00,340 --> 00:20:02,010 They need to exist at the point xi. 463 00:20:02,010 --> 00:20:04,640 Let's assume that's true, OK? 464 00:20:04,640 --> 00:20:05,460 Good. 465 00:20:05,460 --> 00:20:07,770 OK, now I'm going to do something really simple. 466 00:20:07,770 --> 00:20:15,644 Let's write f at x i minus delta x. 467 00:20:15,644 --> 00:20:17,310 And let's just point out the differences 468 00:20:17,310 --> 00:20:18,780 between these two formulas. 469 00:20:18,780 --> 00:20:22,140 So this is the same. 470 00:20:22,140 --> 00:20:27,467 This switches sign because delta x switched signs. 471 00:20:27,467 --> 00:20:28,300 It was plus delta x. 472 00:20:28,300 --> 00:20:30,850 Now it's minus delta x. 473 00:20:30,850 --> 00:20:35,940 This is the same, delta x squared, same as minus delta 474 00:20:35,940 --> 00:20:36,440 x squared. 475 00:20:36,440 --> 00:20:38,020 Doesn't matter. 476 00:20:38,020 --> 00:20:40,510 This one down here-- well, OK. 477 00:20:40,510 --> 00:20:42,085 It's order delta x cubed. 478 00:20:46,350 --> 00:20:48,781 It'll actually look the same but have the opposite sign. 479 00:20:48,781 --> 00:20:49,280 OK? 480 00:20:55,070 --> 00:20:56,690 We can't resolve it, though. 481 00:20:56,690 --> 00:20:59,330 That's sort of the tricky part, right? 482 00:20:59,330 --> 00:21:01,250 We don't know. 483 00:21:01,250 --> 00:21:03,710 We don't know for sure what value that takes on. 484 00:21:03,710 --> 00:21:06,530 This just gives us a bound for how big 485 00:21:06,530 --> 00:21:08,390 the error is in this expansion. 486 00:21:11,760 --> 00:21:13,850 So let's now compute what's in that formula. 487 00:21:13,850 --> 00:21:18,620 So if you take the difference between this and this, 488 00:21:18,620 --> 00:21:21,890 these two will cancel. 489 00:21:21,890 --> 00:21:23,830 These two will combine. 490 00:21:23,830 --> 00:21:30,260 I'll get 2 f prime xi times delta x. 491 00:21:30,260 --> 00:21:33,240 These two will cancel. 492 00:21:33,240 --> 00:21:34,610 So I'll get 0. 493 00:21:34,610 --> 00:21:40,889 These two, I can't rely on them necessarily 494 00:21:40,889 --> 00:21:41,930 canceling each other out. 495 00:21:41,930 --> 00:21:44,112 In fact, they want to combine in principle, right? 496 00:21:44,112 --> 00:21:45,320 We've just bounded the error. 497 00:21:45,320 --> 00:21:46,903 Here, we don't really know what it is, 498 00:21:46,903 --> 00:21:53,750 but it gives me something that's order delta x cubed in size. 499 00:21:53,750 --> 00:21:55,900 So this is the-- 500 00:21:55,900 --> 00:22:04,390 this is 1 minus 2. 501 00:22:04,390 --> 00:22:08,380 It's 2 f prime xi times delta x plus the error, 502 00:22:08,380 --> 00:22:10,760 which is order delta x cubed. 503 00:22:10,760 --> 00:22:12,375 If I divide by 2 delta x-- 504 00:22:15,301 --> 00:22:17,550 I know you guys hate it when the instructor does this, 505 00:22:17,550 --> 00:22:20,430 but you know, you can't help it. 506 00:22:20,430 --> 00:22:24,360 Divide by delta x, the error becomes order delta x squared. 507 00:22:24,360 --> 00:22:27,780 So if the derivative is this thing plus some order delta 508 00:22:27,780 --> 00:22:31,680 x squared piece, it's second-order accurate, 509 00:22:31,680 --> 00:22:32,820 we would say, right? 510 00:22:32,820 --> 00:22:39,220 The error is going to be reduced like the square of the spacing. 511 00:22:39,220 --> 00:22:42,270 Now you can imagine all the finite difference formulas out 512 00:22:42,270 --> 00:22:44,730 there in the world are constructed in this way. 513 00:22:44,730 --> 00:22:46,110 You use Taylor series expansion. 514 00:22:46,110 --> 00:22:47,340 You've got as many terms as you need 515 00:22:47,340 --> 00:22:48,923 to go for the level of accuracy you're 516 00:22:48,923 --> 00:22:52,530 trying to achieve for different points based in different ways. 517 00:22:52,530 --> 00:22:56,400 And you try to dream up some linear combination 518 00:22:56,400 --> 00:23:00,180 of these things so that you get a certain level of accuracy. 519 00:23:00,180 --> 00:23:01,440 They're also not unique. 520 00:23:01,440 --> 00:23:04,890 I can construct these in a lot of different ways 521 00:23:04,890 --> 00:23:09,780 and have the same sort of error level out here, 522 00:23:09,780 --> 00:23:12,120 but different coefficients associated with the error, 523 00:23:12,120 --> 00:23:13,787 but the same overall scaling. 524 00:23:13,787 --> 00:23:15,870 And then you might choose different approximations 525 00:23:15,870 --> 00:23:16,670 for other reasons. 526 00:23:16,670 --> 00:23:16,970 Sam. 527 00:23:16,970 --> 00:23:18,594 AUDIENCE: What would stop me from going 528 00:23:18,594 --> 00:23:20,421 on further and then just subtracting 529 00:23:20,421 --> 00:23:21,900 f prime from both sides? 530 00:23:21,900 --> 00:23:24,365 I mean, it wouldn't really tell me anything, 531 00:23:24,365 --> 00:23:29,699 except maybe the order of [INAUDIBLE] approximately 0. 532 00:23:29,699 --> 00:23:30,990 JAMES SWAN: Well, I mean, yeah. 533 00:23:30,990 --> 00:23:32,520 So let's say you go out further. 534 00:23:32,520 --> 00:23:33,660 What's the next term here? 535 00:23:33,660 --> 00:23:41,130 It's going to be 1 over 6 f triple prime xi delta x cubed. 536 00:23:41,130 --> 00:23:44,790 And here, you'll have minus that because I cubed the delta x. 537 00:23:44,790 --> 00:23:46,890 So when I combine them, I'll actually 538 00:23:46,890 --> 00:23:49,780 get 1 over 3 f triple prime. 539 00:23:49,780 --> 00:23:51,030 So I could do a little better. 540 00:23:51,030 --> 00:23:52,404 If I knew what my function was, I 541 00:23:52,404 --> 00:23:55,260 can tell you exactly how big the error was. 542 00:23:55,260 --> 00:23:56,950 I can tell you that it was as big 543 00:23:56,950 --> 00:23:59,264 as the third derivative of f. 544 00:23:59,264 --> 00:24:01,680 My function doesn't have a third derivative at that point. 545 00:24:01,680 --> 00:24:03,460 The error might be huge. 546 00:24:03,460 --> 00:24:07,080 And it's possible to construct functions that lack 547 00:24:07,080 --> 00:24:09,939 that particular property, OK? 548 00:24:09,939 --> 00:24:12,480 So you can go further, and you can use it to sort of quantify 549 00:24:12,480 --> 00:24:15,390 exactly how many you think the error might 550 00:24:15,390 --> 00:24:17,200 be in the approximation. 551 00:24:17,200 --> 00:24:19,740 But it's all constructed from linear combinations 552 00:24:19,740 --> 00:24:24,510 of different Taylor expansions about nearby points. 553 00:24:24,510 --> 00:24:27,810 And the related problem, actually, 554 00:24:27,810 --> 00:24:32,250 the equivalent problem is polynomial interpolation. 555 00:24:32,250 --> 00:24:33,620 So the sort of-- 556 00:24:33,620 --> 00:24:36,030 if you can somehow, in your mind, transpose this problem, 557 00:24:36,030 --> 00:24:38,460 it looks a lot like polynomial interpolation. 558 00:24:38,460 --> 00:24:41,752 So these two are intimately related to each other. 559 00:24:41,752 --> 00:24:43,656 OK? 560 00:24:43,656 --> 00:24:44,608 Yes. 561 00:24:44,608 --> 00:24:46,149 AUDIENCE: How much do we have to know 562 00:24:46,149 --> 00:24:47,441 about polynomial interpolation? 563 00:24:47,441 --> 00:24:49,107 JAMES SWAN: How much do you have to know 564 00:24:49,107 --> 00:24:50,590 about polynomial interpolation? 565 00:24:50,590 --> 00:24:52,840 AUDIENCE: Yeah, like, do we have to be able to compute 566 00:24:52,840 --> 00:24:54,546 the primes and polynomials? 567 00:24:54,546 --> 00:24:55,670 JAMES SWAN: Say that again. 568 00:24:55,670 --> 00:24:57,419 AUDIENCE: Do we have to be able to compute 569 00:24:57,419 --> 00:24:59,610 the primes of polynomials? 570 00:24:59,610 --> 00:25:03,550 [INAUDIBLE] 571 00:25:03,550 --> 00:25:07,186 JAMES SWAN: What do I want to say about that? 572 00:25:07,186 --> 00:25:12,190 I wouldn't expect that level of detail. 573 00:25:12,190 --> 00:25:14,400 I think it's quite difficult to construct 574 00:25:14,400 --> 00:25:17,370 Lagrange polynomial expansions by hand. 575 00:25:17,370 --> 00:25:19,920 I don't know anyone who does that 576 00:25:19,920 --> 00:25:21,380 professionally or for pleasure. 577 00:25:24,660 --> 00:25:26,730 I think that's a bad idea. 578 00:25:26,730 --> 00:25:28,890 You should understand polynomial interpolation. 579 00:25:28,890 --> 00:25:30,420 You should understand the context 580 00:25:30,420 --> 00:25:32,880 in which it's important. 581 00:25:32,880 --> 00:25:37,150 What is polynomial interpolation important for, numerically? 582 00:25:37,150 --> 00:25:38,350 Do you recall? 583 00:25:38,350 --> 00:25:38,850 Hersch. 584 00:25:38,850 --> 00:25:39,870 AUDIENCE: Numerical integration. 585 00:25:39,870 --> 00:25:41,578 JAMES SWAN: Numerical integration, right. 586 00:25:41,578 --> 00:25:44,220 So this was really the key to numerical integration, 587 00:25:44,220 --> 00:25:48,150 was trying to construct appropriate approximations 588 00:25:48,150 --> 00:25:50,760 of our function from a finite set of data 589 00:25:50,760 --> 00:25:52,660 and figure out the area under the curve. 590 00:25:52,660 --> 00:25:56,940 So you should understand how one uses polynomial interpolation 591 00:25:56,940 --> 00:25:58,620 to do numerical integration. 592 00:25:58,620 --> 00:26:03,350 But I wouldn't expect us to ask you to actually compute 593 00:26:03,350 --> 00:26:06,780 a polynomial interpolant and numerically 594 00:26:06,780 --> 00:26:08,330 integrate it by hand. 595 00:26:08,330 --> 00:26:10,910 I think that's too much. 596 00:26:10,910 --> 00:26:11,410 OK? 597 00:26:11,410 --> 00:26:11,845 AUDIENCE: OK. 598 00:26:11,845 --> 00:26:12,470 JAMES SWAN: OK. 599 00:26:12,470 --> 00:26:13,387 More questions. 600 00:26:17,450 --> 00:26:17,969 Hersch. 601 00:26:17,969 --> 00:26:19,344 AUDIENCE: Now do you mind showing 602 00:26:19,344 --> 00:26:26,042 how the trapezoid rule is over delta t squared accurate? 603 00:26:26,042 --> 00:26:26,750 JAMES SWAN: Sure. 604 00:26:30,243 --> 00:26:32,240 AUDIENCE: For ODE IVPs. 605 00:26:32,240 --> 00:26:33,680 JAMES SWAN: For ODE-- 606 00:26:33,680 --> 00:26:34,850 AUDIENCE: IVPs. 607 00:26:34,850 --> 00:26:36,340 JAMES SWAN: ODE IVP, OK. 608 00:26:44,490 --> 00:26:47,520 OK, so we have to have an ODE we want to solve. 609 00:26:47,520 --> 00:26:50,321 Can I just do-- can I do a one-dimensional unknown? 610 00:26:50,321 --> 00:26:51,570 Do I need to do a vector here? 611 00:26:51,570 --> 00:26:53,850 Can I just-- would you be satisfied 612 00:26:53,850 --> 00:26:58,175 if I wrote this as f of y and t and that it's 613 00:26:58,175 --> 00:26:59,050 sufficiently general? 614 00:26:59,050 --> 00:27:00,550 That way, you don't have to blame me 615 00:27:00,550 --> 00:27:02,690 when I forget to underscore things along the way. 616 00:27:02,690 --> 00:27:03,870 And we don't have to think about the Jacobian 617 00:27:03,870 --> 00:27:04,786 or anything like that. 618 00:27:04,786 --> 00:27:05,880 OK. 619 00:27:05,880 --> 00:27:08,864 So oh, time derivative, right? 620 00:27:08,864 --> 00:27:10,530 So there's the ODE we're going to solve. 621 00:27:14,270 --> 00:27:15,480 The trapezoid rule. 622 00:27:19,750 --> 00:27:25,112 OK, so let's do this the following way. 623 00:27:25,112 --> 00:27:27,570 It's actually going to wind up looking very similar to what 624 00:27:27,570 --> 00:27:28,980 we just did, which is useful. 625 00:27:28,980 --> 00:27:30,975 I might even be able to pull that board down and reuse it 626 00:27:30,975 --> 00:27:31,766 at a certain point. 627 00:27:31,766 --> 00:27:32,766 So that'll be good. 628 00:27:32,766 --> 00:27:33,740 Let's do this. 629 00:27:33,740 --> 00:27:39,129 So what is-- ultimately, what is ODE IVP solving like? 630 00:27:39,129 --> 00:27:41,670 What are you trying to do when you solve one of these things? 631 00:27:41,670 --> 00:27:42,770 AUDIENCE: Extrapolate. 632 00:27:42,770 --> 00:27:46,540 JAMES SWAN: It's extrapolation, right? 633 00:27:46,540 --> 00:27:49,080 I know the value of y initially. 634 00:27:49,080 --> 00:27:53,670 I'm trying to figure out where the hell this thing is going. 635 00:27:53,670 --> 00:27:55,100 I've got to extrapolate for it. 636 00:27:55,100 --> 00:27:57,720 And you should be very uncomfortable with the notion 637 00:27:57,720 --> 00:28:00,240 that I can do that, right? 638 00:28:00,240 --> 00:28:03,050 How good a job can I do predicting the future 639 00:28:03,050 --> 00:28:05,700 knowing how things are now? 640 00:28:05,700 --> 00:28:08,890 It's really quite complicated. 641 00:28:08,890 --> 00:28:11,370 In fact, it's so complicated, there 642 00:28:11,370 --> 00:28:14,760 are certain circumstances in which it's not really possible. 643 00:28:14,760 --> 00:28:16,590 Discovered here at MIT, actually. 644 00:28:16,590 --> 00:28:18,570 So there was weather research going 645 00:28:18,570 --> 00:28:21,020 on at a certain point at MIT. 646 00:28:21,020 --> 00:28:22,200 It's a very famous case. 647 00:28:22,200 --> 00:28:24,720 A researcher, a very famous researcher 648 00:28:24,720 --> 00:28:28,050 was doing numerical simulations of a weather model in an ODE 649 00:28:28,050 --> 00:28:29,430 IVP. 650 00:28:29,430 --> 00:28:32,300 He ran it for a while, and he stopped. 651 00:28:32,300 --> 00:28:35,630 He looked at his end state, the last value of y 652 00:28:35,630 --> 00:28:37,100 in his simulation. 653 00:28:37,100 --> 00:28:40,490 He put in three digits, used that as the initial condition, 654 00:28:40,490 --> 00:28:43,340 and started his simulation again, and it went wacky. 655 00:28:43,340 --> 00:28:45,688 Didn't look anything like the initial solution. 656 00:28:45,688 --> 00:28:47,567 OK? 657 00:28:47,567 --> 00:28:48,400 How did that happen? 658 00:28:48,400 --> 00:28:50,980 It seemed fine up to that point. 659 00:28:50,980 --> 00:28:52,670 Solution's cranking along. 660 00:28:52,670 --> 00:28:54,577 He stopped. 661 00:28:54,577 --> 00:28:56,660 He took three digits accuracy out of the computer, 662 00:28:56,660 --> 00:28:57,535 and he started again. 663 00:28:57,535 --> 00:29:00,450 And it, I don't know, did something else. 664 00:29:00,450 --> 00:29:03,620 So there are problems that are inherently chaotic and very 665 00:29:03,620 --> 00:29:05,780 sensitive to their initial conditions. 666 00:29:05,780 --> 00:29:07,970 They're hard to resolve. 667 00:29:07,970 --> 00:29:11,090 So the entire point of doing this sort of analysis 668 00:29:11,090 --> 00:29:15,470 of ODE IVPs is, at least in the best-case scenarios, 669 00:29:15,470 --> 00:29:18,530 we want to try to manage the error associated 670 00:29:18,530 --> 00:29:19,990 with these kinds of extrapolation. 671 00:29:19,990 --> 00:29:23,529 In some case, it's really not very possible. 672 00:29:23,529 --> 00:29:25,070 You don't know the initial conditions 673 00:29:25,070 --> 00:29:27,920 well enough to predict what the final state is. 674 00:29:27,920 --> 00:29:30,650 So there are problems that are inherently 675 00:29:30,650 --> 00:29:33,180 unstable or sensitive to their initial conditions. 676 00:29:33,180 --> 00:29:35,150 They don't have to blow up either. 677 00:29:35,150 --> 00:29:38,240 They can find themselves moving through the phase space 678 00:29:38,240 --> 00:29:40,460 in some way that's very, very sensitive. 679 00:29:40,460 --> 00:29:42,110 And two points that start very close 680 00:29:42,110 --> 00:29:45,710 together can wind up very far apart from each other. 681 00:29:45,710 --> 00:29:48,140 So that's deterministic chaos. 682 00:29:48,140 --> 00:29:51,470 But outside of those problems, we try to do this extrapolation 683 00:29:51,470 --> 00:29:55,820 and figure out sort of a best approximation for where 684 00:29:55,820 --> 00:30:00,830 we think our target function is going. 685 00:30:00,830 --> 00:30:02,270 So what are we trying to do? 686 00:30:02,270 --> 00:30:08,470 In principle, we know y at a certain point. 687 00:30:08,470 --> 00:30:11,860 And we want to know where it's going to go. 688 00:30:11,860 --> 00:30:17,670 And so you might say, well, maybe I know dy dt initially. 689 00:30:17,670 --> 00:30:21,850 And so I should just move a small increment 690 00:30:21,850 --> 00:30:22,900 along that slope. 691 00:30:22,900 --> 00:30:24,233 And that's a good approximation. 692 00:30:24,233 --> 00:30:26,740 That's the forward Euler approximation. 693 00:30:26,740 --> 00:30:28,510 Trapezoid rule-- or equivalently, 694 00:30:28,510 --> 00:30:30,190 the midpoint rule-- 695 00:30:30,190 --> 00:30:34,970 says, well, maybe that initial slope 696 00:30:34,970 --> 00:30:37,250 isn't really the right one to use. 697 00:30:37,250 --> 00:30:39,200 Maybe y does something like this, 698 00:30:39,200 --> 00:30:43,840 and we should actually look sort of halfway 699 00:30:43,840 --> 00:30:45,970 between the point we're trying to extrapolate 700 00:30:45,970 --> 00:30:50,860 to and the current point, and use that value as the best 701 00:30:50,860 --> 00:30:53,350 approximation of the derivative and extrapolate 702 00:30:53,350 --> 00:30:54,347 for it along that. 703 00:30:54,347 --> 00:30:55,930 And it turns out that's more accurate. 704 00:30:55,930 --> 00:30:57,560 So what does that look like? 705 00:30:57,560 --> 00:31:02,610 So one typically says, you know, y 706 00:31:02,610 --> 00:31:13,570 i plus 1 is equal to yi plus delta t times f y 707 00:31:13,570 --> 00:31:16,420 i plus 1/2 comma. 708 00:31:16,420 --> 00:31:18,320 And we won't worry about the t here, 709 00:31:18,320 --> 00:31:22,080 but it's going to have to be t i plus 1/2. 710 00:31:22,080 --> 00:31:25,000 So I look halfway forward in time. 711 00:31:25,000 --> 00:31:27,970 And I say, that's the slope, that's the derivative of y. 712 00:31:27,970 --> 00:31:30,950 So let me step forward along that line. 713 00:31:30,950 --> 00:31:34,510 It turns out this is going to be reasonably accurate if I 714 00:31:34,510 --> 00:31:37,780 can get a good approximation for y i plus 1/2. 715 00:31:37,780 --> 00:31:39,621 OK? 716 00:31:39,621 --> 00:31:40,120 OK. 717 00:31:40,120 --> 00:31:42,420 So let's-- [COUGH]. 718 00:31:42,420 --> 00:31:44,140 Excuse me. 719 00:31:44,140 --> 00:31:44,640 Yeah. 720 00:31:44,640 --> 00:31:46,390 AUDIENCE: Is this the midpoint method or-- 721 00:31:46,390 --> 00:31:48,930 JAMES SWAN: They're functionally equivalent to each other. 722 00:31:48,930 --> 00:31:52,340 They work in precisely the same fashion. 723 00:31:52,340 --> 00:31:54,840 So whether it's the trapezoidal rule or the midpoint method, 724 00:31:54,840 --> 00:31:59,420 they have fundamentally the same pictures there. 725 00:31:59,420 --> 00:31:59,920 OK? 726 00:32:02,590 --> 00:32:04,840 Here, if you do forward Euler, you're 727 00:32:04,840 --> 00:32:07,930 doing numerical integration, assuming the slope is 728 00:32:07,930 --> 00:32:09,100 the value at this point. 729 00:32:09,100 --> 00:32:11,710 If you're doing the midpoint method or the trapezoid rule, 730 00:32:11,710 --> 00:32:13,930 you're trying to get a better approximation for the slope, 731 00:32:13,930 --> 00:32:14,230 right? 732 00:32:14,230 --> 00:32:15,771 So you're trying to build a trapezoid 733 00:32:15,771 --> 00:32:18,260 and integrate the area under that trapezoid. 734 00:32:18,260 --> 00:32:22,260 So they're fundamentally the same thing. 735 00:32:22,260 --> 00:32:27,810 Now the question becomes, I don't know f at y i plus 2. 736 00:32:27,810 --> 00:32:31,020 So I need to use a Taylor expansion of this quantity 737 00:32:31,020 --> 00:32:33,510 in terms of the value of f that I know. 738 00:32:33,510 --> 00:32:38,070 So I need to expand this in terms of f at yi. 739 00:32:38,070 --> 00:32:43,770 And I'll know the derivative of y with respect to t at yi. 740 00:32:43,770 --> 00:32:45,430 I know it from this formula. 741 00:32:45,430 --> 00:32:48,270 So if I take this Taylor expansion 742 00:32:48,270 --> 00:32:52,520 and I carry it out to the first term I don't know, 743 00:32:52,520 --> 00:32:55,280 which is the order delta t squared term, 744 00:32:55,280 --> 00:32:57,320 and I carry through all of the errors, 745 00:32:57,320 --> 00:33:01,460 I'll find out that there's a numerical error proportional 746 00:33:01,460 --> 00:33:03,050 to order delta t squared. 747 00:33:03,050 --> 00:33:10,560 So I need to do exactly this and substitute 748 00:33:10,560 --> 00:33:14,634 in terms of quantities I know and quantities I don't know. 749 00:33:14,634 --> 00:33:16,050 And the leading-order contribution 750 00:33:16,050 --> 00:33:18,550 of the quantities I don't know will give me this order delta 751 00:33:18,550 --> 00:33:20,089 t squared piece. 752 00:33:20,089 --> 00:33:21,755 And that'll give me the local truncation 753 00:33:21,755 --> 00:33:23,672 error in the solution. 754 00:33:23,672 --> 00:33:26,090 Does that make sense? 755 00:33:26,090 --> 00:33:28,160 So it's still Taylor expansions. 756 00:33:28,160 --> 00:33:29,420 Good. 757 00:33:29,420 --> 00:33:32,000 Other questions. 758 00:33:32,000 --> 00:33:33,170 Yes. 759 00:33:33,170 --> 00:33:37,698 AUDIENCE: Why is the central difference 0, not [INAUDIBLE]?? 760 00:33:40,324 --> 00:33:42,115 JAMES SWAN: Why is the central difference-- 761 00:33:42,115 --> 00:33:44,253 AUDIENCE: No, why's the outlook [INAUDIBLE] the one 762 00:33:44,253 --> 00:33:49,306 we did [INAUDIBLE]? 763 00:33:49,306 --> 00:33:52,240 That one is not implicit, right? 764 00:33:52,240 --> 00:33:58,020 JAMES SWAN: I don't think I said anything like that. 765 00:33:58,020 --> 00:34:00,330 So implicit versus explicit really 766 00:34:00,330 --> 00:34:04,350 depends on what you're trying to do. 767 00:34:04,350 --> 00:34:06,990 So if I'm trying to use a central difference 768 00:34:06,990 --> 00:34:13,050 formula of some sort to solve an ODE which progresses forward 769 00:34:13,050 --> 00:34:14,460 in time-- 770 00:34:14,460 --> 00:34:18,000 it has a direction associated with it that things always 771 00:34:18,000 --> 00:34:21,540 progress in-- then this might be an explicit formula. 772 00:34:21,540 --> 00:34:27,600 Because I could solve for f at x i plus 1 in terms of what's 773 00:34:27,600 --> 00:34:30,179 going on in the past. 774 00:34:30,179 --> 00:34:32,610 If we tried to do finite differences in a boundary value 775 00:34:32,610 --> 00:34:35,760 problem instead, and that boundary value problem 776 00:34:35,760 --> 00:34:39,210 doesn't have some direction associated with it anymore-- 777 00:34:39,210 --> 00:34:41,520 so it's not like space has some preferred direction. 778 00:34:41,520 --> 00:34:43,949 Time goes in a preferred direction. 779 00:34:43,949 --> 00:34:45,960 Space does not. 780 00:34:45,960 --> 00:34:50,310 You may find that the pointwise equations you write down cannot 781 00:34:50,310 --> 00:34:54,164 be solved strictly in terms of one of these. 782 00:34:54,164 --> 00:34:56,580 You can't just move this to the other side of the equation 783 00:34:56,580 --> 00:34:58,163 and solve in terms of everything else. 784 00:34:58,163 --> 00:35:00,450 So you'll have a coupled set of equations 785 00:35:00,450 --> 00:35:06,472 that can't be diagonalized, can't be simply reduced. 786 00:35:06,472 --> 00:35:08,430 They won't have the form of, say, of triangular 787 00:35:08,430 --> 00:35:10,260 matrix, for example. 788 00:35:10,260 --> 00:35:12,180 This will happen. 789 00:35:12,180 --> 00:35:15,069 And in that case, you would say this formula is implicit. 790 00:35:15,069 --> 00:35:17,610 So it really depends on which problem you're trying to solve, 791 00:35:17,610 --> 00:35:20,250 whether you label them explicit or implicit. 792 00:35:20,250 --> 00:35:24,810 Explicit is going to mean that the data I want 793 00:35:24,810 --> 00:35:27,960 can be found with a simple equation 794 00:35:27,960 --> 00:35:29,844 solve in terms of the data I know. 795 00:35:29,844 --> 00:35:31,260 Implicit is going to mean I've got 796 00:35:31,260 --> 00:35:35,540 to do some complicated equation-solving methodology. 797 00:35:35,540 --> 00:35:37,530 I've got to go do Gaussian elimination, 798 00:35:37,530 --> 00:35:40,650 or I need to go to fsolve and solve this thing. 799 00:35:40,650 --> 00:35:42,930 The data that I want is not available 800 00:35:42,930 --> 00:35:47,580 through some simple scheme where I can just write explicitly 801 00:35:47,580 --> 00:35:51,190 a thing I want equals some function of things I know. 802 00:35:51,190 --> 00:35:51,690 OK? 803 00:35:54,636 --> 00:35:56,109 Other questions. 804 00:35:59,560 --> 00:36:00,460 OK. 805 00:36:00,460 --> 00:36:00,960 Yeah. 806 00:36:00,960 --> 00:36:01,460 Yeah, yeah. 807 00:36:01,460 --> 00:36:04,136 AUDIENCE: [INAUDIBLE],, how many questions will there be? 808 00:36:04,136 --> 00:36:07,082 And for each question, how many subquestions? 809 00:36:07,082 --> 00:36:09,046 Could you just roughly-- 810 00:36:09,046 --> 00:36:10,028 JAMES SWAN: Oh, man. 811 00:36:12,545 --> 00:36:14,090 The question was, how many questions 812 00:36:14,090 --> 00:36:17,300 and how many subquestions on the quiz? 813 00:36:17,300 --> 00:36:19,510 Yeah. 814 00:36:19,510 --> 00:36:23,330 The quiz is-- in my opinion, it's 815 00:36:23,330 --> 00:36:27,800 now shorter than the last one that you took. 816 00:36:27,800 --> 00:36:30,662 We've been pretty sensitive to time concerns. 817 00:36:30,662 --> 00:36:32,120 We know that was something that was 818 00:36:32,120 --> 00:36:34,820 an issue on the previous quiz. 819 00:36:34,820 --> 00:36:41,090 I think there's only going to be two problems on it. 820 00:36:41,090 --> 00:36:43,910 They have many parts, but we've really 821 00:36:43,910 --> 00:36:48,530 tried to refine the questions in those parts. 822 00:36:48,530 --> 00:36:50,289 That's what you should expect. 823 00:36:50,289 --> 00:36:51,080 It's comprehensive. 824 00:36:51,080 --> 00:36:53,330 It Covers all the things from this section. 825 00:36:53,330 --> 00:36:54,230 OK? 826 00:36:54,230 --> 00:36:55,046 Yes. 827 00:36:55,046 --> 00:36:57,892 AUDIENCE: Also, DAEs problem-- 828 00:36:57,892 --> 00:36:58,600 JAMES SWAN: Yeah. 829 00:36:58,600 --> 00:37:01,760 AUDIENCE: It says that as index increases, 830 00:37:01,760 --> 00:37:04,420 we have less degrees of freedom. 831 00:37:04,420 --> 00:37:06,344 JAMES SWAN: Yes. 832 00:37:06,344 --> 00:37:07,510 AUDIENCE: Could you explain? 833 00:37:07,510 --> 00:37:09,070 JAMES SWAN: Sure. 834 00:37:09,070 --> 00:37:10,780 Sure. 835 00:37:10,780 --> 00:37:16,340 So higher-index DAEs come up all the time. 836 00:37:16,340 --> 00:37:20,850 And the degrees of freedom refers 837 00:37:20,850 --> 00:37:23,820 to your ability to choose initial conditions 838 00:37:23,820 --> 00:37:26,060 for the problem. 839 00:37:26,060 --> 00:37:28,665 And we saw several examples in which, 840 00:37:28,665 --> 00:37:34,110 if we tried to convert that DAE to an ODE, 841 00:37:34,110 --> 00:37:36,450 we found along the way that there were certain hidden 842 00:37:36,450 --> 00:37:39,210 conditions that all the initial conditions would need 843 00:37:39,210 --> 00:37:43,440 to satisfy in order for this ODE, the system of ODEs 844 00:37:43,440 --> 00:37:47,550 that we built from the DAEs, to follow the same solution path 845 00:37:47,550 --> 00:37:51,120 or solution manifold as the original DAE system would 846 00:37:51,120 --> 00:37:52,860 follow. 847 00:37:52,860 --> 00:37:54,630 The higher the index is, the more 848 00:37:54,630 --> 00:37:56,325 of these hidden constraints you find. 849 00:37:58,830 --> 00:38:00,480 And those hidden constraints tell you 850 00:38:00,480 --> 00:38:02,970 that the initial conditions have to be very particular. 851 00:38:02,970 --> 00:38:04,261 So there are-- 852 00:38:04,261 --> 00:38:06,510 I would encourage you to look at the specific examples 853 00:38:06,510 --> 00:38:07,590 in the notes. 854 00:38:07,590 --> 00:38:10,170 And you'll see there was a simple CSTR 855 00:38:10,170 --> 00:38:14,160 example that was index 1 and almost unconstrained, 856 00:38:14,160 --> 00:38:15,300 basically. 857 00:38:15,300 --> 00:38:18,200 There was an index 2 DAE in which 858 00:38:18,200 --> 00:38:21,112 the consistent initial conditions, you actually 859 00:38:21,112 --> 00:38:23,070 couldn't specify any of the initial conditions. 860 00:38:23,070 --> 00:38:27,600 They were fixed by the equations themselves. 861 00:38:27,600 --> 00:38:30,810 But remember, that sort of happened because certain DAEs 862 00:38:30,810 --> 00:38:33,270 are pathological in nature. 863 00:38:33,270 --> 00:38:35,970 They often ask us to do something we can't do 864 00:38:35,970 --> 00:38:42,840 physically, like try to control the input by-- or try 865 00:38:42,840 --> 00:38:44,880 to predict-- 866 00:38:44,880 --> 00:38:46,780 let's see, how do I say this? 867 00:38:46,780 --> 00:38:49,270 It's easy for us to predict the output knowing the input. 868 00:38:49,270 --> 00:38:53,140 It's very hard for us to predict the input knowing the output. 869 00:38:53,140 --> 00:38:55,270 And these higher-index DAEs were essentially 870 00:38:55,270 --> 00:38:58,180 asking us to do that. 871 00:38:58,180 --> 00:39:00,790 There's a lag in how we measure things. 872 00:39:00,790 --> 00:39:03,610 And it's easier to go forward through a process 873 00:39:03,610 --> 00:39:06,200 than backwards through a process and make these predictions. 874 00:39:06,200 --> 00:39:09,345 There's inherent sensitivity in doing the former. 875 00:39:09,345 --> 00:39:10,720 It's the same sort of sensitivity 876 00:39:10,720 --> 00:39:13,780 you get from these systems of ODEs, in fact. 877 00:39:13,780 --> 00:39:15,460 A small change in the initial conditions 878 00:39:15,460 --> 00:39:18,460 can lead to big changes in the outlet. 879 00:39:18,460 --> 00:39:21,790 So if I measure the outlet, it's hard to predict the inlet. 880 00:39:21,790 --> 00:39:24,740 It's just very inherently difficult to do. 881 00:39:24,740 --> 00:39:29,050 And so formulating a model which has this high index, 882 00:39:29,050 --> 00:39:31,930 you will naturally find that your choice 883 00:39:31,930 --> 00:39:34,180 of initial conditions for the solution of that model 884 00:39:34,180 --> 00:39:35,570 are constrained. 885 00:39:35,570 --> 00:39:37,320 And they're constrained because of the way 886 00:39:37,320 --> 00:39:38,920 you formulated the model. 887 00:39:38,920 --> 00:39:43,045 If you're actually trying to do control of a chemical process, 888 00:39:43,045 --> 00:39:49,580 it's going to be very difficult to try to somehow control the-- 889 00:39:49,580 --> 00:39:53,350 try to make the input be a certain thing by controlling 890 00:39:53,350 --> 00:39:55,357 the output. 891 00:39:55,357 --> 00:39:56,940 That doesn't make sense almost, right? 892 00:39:56,940 --> 00:39:58,420 It seems very, very strange. 893 00:39:58,420 --> 00:40:01,330 You would really want to change the input in order 894 00:40:01,330 --> 00:40:02,950 to hit a target in the output. 895 00:40:02,950 --> 00:40:05,410 How do you change the output and hit a target in the input? 896 00:40:05,410 --> 00:40:08,710 The process doesn't actually care about things in that way. 897 00:40:08,710 --> 00:40:09,610 And you saw that. 898 00:40:09,610 --> 00:40:11,762 Because in that particular CSTR example, 899 00:40:11,762 --> 00:40:13,720 you couldn't fix any of the initial conditions, 900 00:40:13,720 --> 00:40:14,560 actually, right? 901 00:40:14,560 --> 00:40:16,240 There was no free choice in the problem. 902 00:40:16,240 --> 00:40:18,105 Everything was automatically fixed, 903 00:40:18,105 --> 00:40:20,230 and you had to have perfect knowledge of everything 904 00:40:20,230 --> 00:40:21,170 in the system. 905 00:40:21,170 --> 00:40:24,170 I wasn't actually able to do control in a sense 906 00:40:24,170 --> 00:40:24,880 there, right? 907 00:40:24,880 --> 00:40:25,720 I could just measure the output, and I 908 00:40:25,720 --> 00:40:27,678 can tell you what the input was supposed to be. 909 00:40:27,678 --> 00:40:31,130 And it was super sensitive to my measurement. 910 00:40:31,130 --> 00:40:32,680 So these high-index problems tend 911 00:40:32,680 --> 00:40:35,800 to come up when we want to constrain things 912 00:40:35,800 --> 00:40:43,144 in a way that's, let's say, physically quite challenging. 913 00:40:43,144 --> 00:40:44,560 High-index problems are incredibly 914 00:40:44,560 --> 00:40:46,420 common in mechanical engineering, things 915 00:40:46,420 --> 00:40:49,690 like robotics where you want to make 916 00:40:49,690 --> 00:40:53,440 sure the robot's arm doesn't whack someone in the head. 917 00:40:53,440 --> 00:40:54,675 This is important. 918 00:40:54,675 --> 00:40:56,050 And so you're trying to constrain 919 00:40:56,050 --> 00:40:58,060 all these degrees of freedom and the paths 920 00:40:58,060 --> 00:40:59,710 that it's going to move on. 921 00:40:59,710 --> 00:41:00,990 And all those constraints-- 922 00:41:00,990 --> 00:41:03,400 I mean, there's actually a very narrow envelope in which 923 00:41:03,400 --> 00:41:05,680 this thing gets to operate. 924 00:41:05,680 --> 00:41:09,460 So accurately simulating the motion 925 00:41:09,460 --> 00:41:12,710 and then making the robot move that way is very empowering. 926 00:41:12,710 --> 00:41:14,380 In chemical processes, that's true, too. 927 00:41:14,380 --> 00:41:16,754 But oftentimes, we can make choices in model formulation, 928 00:41:16,754 --> 00:41:17,380 right? 929 00:41:17,380 --> 00:41:20,050 Like how you try to control the process that 930 00:41:20,050 --> 00:41:23,500 can ease those constraints. 931 00:41:23,500 --> 00:41:25,300 If I had some control or it doesn't control 932 00:41:25,300 --> 00:41:27,190 in an instantaneous fashion, even 933 00:41:27,190 --> 00:41:28,790 if it's a very high-bandwidth control, 934 00:41:28,790 --> 00:41:31,540 there's still a finite time for signals to propagate. 935 00:41:31,540 --> 00:41:33,790 There's dynamics associated with the controller that 936 00:41:33,790 --> 00:41:37,300 can convert that DAE system into a system of ODEs, for example. 937 00:41:37,300 --> 00:41:40,380 You don't have-- they may be stiff ODEs. 938 00:41:40,380 --> 00:41:43,630 DAEs are the limit of sort of infinite stiffness in ODEs. 939 00:41:43,630 --> 00:41:46,690 But they may not be as troublesome to solve 940 00:41:46,690 --> 00:41:48,475 as the DAE system would be. 941 00:41:48,475 --> 00:41:49,870 OK? 942 00:41:49,870 --> 00:41:53,640 It's about model formulation. 943 00:41:53,640 --> 00:41:56,030 OK, can I talk briefly about PDEs? 944 00:41:56,030 --> 00:41:57,301 Is that OK? 945 00:41:57,301 --> 00:41:58,800 I'll tell you a little bit about it. 946 00:41:58,800 --> 00:42:00,210 I like this finite volume method. 947 00:42:00,210 --> 00:42:02,784 I think it's very interesting. 948 00:42:02,784 --> 00:42:03,950 You've got some notes on it. 949 00:42:03,950 --> 00:42:05,430 I think I like it because I think 950 00:42:05,430 --> 00:42:06,846 it comes very naturally, actually, 951 00:42:06,846 --> 00:42:07,872 to chemical engineers. 952 00:42:07,872 --> 00:42:10,080 Because the problems we like to solve are of the type 953 00:42:10,080 --> 00:42:13,290 that finite volume eats for breakfast. 954 00:42:13,290 --> 00:42:17,310 These are problems of conservation. 955 00:42:17,310 --> 00:42:19,350 So we have a conserved quantity b. 956 00:42:19,350 --> 00:42:21,327 Is that what Dean uses in his book? 957 00:42:21,327 --> 00:42:23,910 The new version still uses b as the conserved quantity, right? 958 00:42:23,910 --> 00:42:26,400 So the time rate of change of b is 959 00:42:26,400 --> 00:42:29,899 equal to minus the gradient in the flux plus some, 960 00:42:29,899 --> 00:42:31,440 I don't know, some volumetric change. 961 00:42:31,440 --> 00:42:34,110 Maybe a reaction, maybe there's some injections 962 00:42:34,110 --> 00:42:39,150 somewhere of mass or momentum, or you know, some source. 963 00:42:39,150 --> 00:42:41,820 And our numerical solution, oftentimes, we 964 00:42:41,820 --> 00:42:44,700 would like it to also conserve b, right? 965 00:42:44,700 --> 00:42:48,540 Conserve mass, conserve momentum, conserve energy, 966 00:42:48,540 --> 00:42:51,320 conserve species. 967 00:42:51,320 --> 00:42:54,860 These collocation methods in general, 968 00:42:54,860 --> 00:42:57,650 or relaxation methods in general, don't do that. 969 00:42:57,650 --> 00:42:59,090 They're not designed to do that. 970 00:42:59,090 --> 00:43:02,450 You might be able to construct, for example, basis functions 971 00:43:02,450 --> 00:43:06,530 that have that property that they will satisfy conservation. 972 00:43:06,530 --> 00:43:11,600 You might be able to construct certain meshing methods, 973 00:43:11,600 --> 00:43:12,930 certain collocation methods-- 974 00:43:12,930 --> 00:43:15,410 and this is one of them, the finite volume method-- 975 00:43:15,410 --> 00:43:17,210 that respects conservation. 976 00:43:17,210 --> 00:43:19,730 And here's how you do it. 977 00:43:19,730 --> 00:43:22,430 So you worked really hard in transport 978 00:43:22,430 --> 00:43:25,790 to derive these differential forms of the transport 979 00:43:25,790 --> 00:43:26,450 equations. 980 00:43:26,450 --> 00:43:28,900 But finite volume actually likes the integral form. 981 00:43:28,900 --> 00:43:31,250 So you've got to go back. 982 00:43:31,250 --> 00:43:33,650 So you've got to take the integral of these equations 983 00:43:33,650 --> 00:43:38,500 over some volume V. And then the time derivative 984 00:43:38,500 --> 00:43:41,000 of the amount of b in this volume 985 00:43:41,000 --> 00:43:46,310 is related to the flux of b through the surfaces 986 00:43:46,310 --> 00:43:49,910 of that volume plus the amount of generation 987 00:43:49,910 --> 00:43:53,760 or consumption of the conserved quantity within that volume V, 988 00:43:53,760 --> 00:43:54,620 right? 989 00:43:54,620 --> 00:43:56,357 And this volume is my finite volume. 990 00:43:56,357 --> 00:43:58,190 I take the domain of interest, and I chop it 991 00:43:58,190 --> 00:44:00,590 up into all these little volumes. 992 00:44:00,590 --> 00:44:04,620 And then I just need to conserve b within that volume. 993 00:44:04,620 --> 00:44:06,680 So I have the first equation you learned 994 00:44:06,680 --> 00:44:08,030 in chemical engineering, right? 995 00:44:08,030 --> 00:44:10,196 The amount of accumulation of the conserved quantity 996 00:44:10,196 --> 00:44:13,160 is related to the fluxes in and out of the control volume 997 00:44:13,160 --> 00:44:15,647 plus the amount of generation or consumption 998 00:44:15,647 --> 00:44:16,730 within the control volume. 999 00:44:16,730 --> 00:44:18,730 This comes very naturally to chemical engineers. 1000 00:44:18,730 --> 00:44:21,290 It fits perfectly in the problems we like to solve. 1001 00:44:21,290 --> 00:44:21,936 Yeah. 1002 00:44:21,936 --> 00:44:25,670 AUDIENCE: Is the nominal vector pointing outwards or inwards? 1003 00:44:25,670 --> 00:44:28,160 JAMES SWAN: Well, it all depends on how we choose 1004 00:44:28,160 --> 00:44:30,020 to write j, actually, right? 1005 00:44:30,020 --> 00:44:33,740 So is j the flux into or out of this volume? 1006 00:44:33,740 --> 00:44:37,130 So I won't prescribe that here. 1007 00:44:37,130 --> 00:44:39,140 It depends on what you chose as the flux. 1008 00:44:39,140 --> 00:44:43,620 So maybe, I don't know, what does-- 1009 00:44:43,620 --> 00:44:47,420 Dean writes the stress tensor with the opposite sign of Bird, 1010 00:44:47,420 --> 00:44:48,480 Stewart, and Lightfoot. 1011 00:44:48,480 --> 00:44:50,820 So these guys, that's the flux of momentum, right? 1012 00:44:50,820 --> 00:44:51,889 They choose a sign. 1013 00:44:51,889 --> 00:44:53,680 Then the normals have to respect that sign. 1014 00:44:53,680 --> 00:44:54,596 Doesn't really matter. 1015 00:44:54,596 --> 00:44:55,680 The physics doesn't care. 1016 00:44:55,680 --> 00:44:58,070 You just have to choose the flux in the right direction. 1017 00:44:58,070 --> 00:45:01,860 If we think of j as the flux into the volume, 1018 00:45:01,860 --> 00:45:03,135 n should point in. 1019 00:45:08,600 --> 00:45:10,410 OK, so you have this conservation equation. 1020 00:45:10,410 --> 00:45:12,657 You've got to solve for each of your finite volumes. 1021 00:45:12,657 --> 00:45:14,490 And the finite volumes are coupled together, 1022 00:45:14,490 --> 00:45:19,300 because a flux out of one volume is a flux into another volume, 1023 00:45:19,300 --> 00:45:19,800 right? 1024 00:45:19,800 --> 00:45:23,760 So you can think of these volumes as being little CSTRs. 1025 00:45:23,760 --> 00:45:25,590 They're all sitting next to each other. 1026 00:45:25,590 --> 00:45:28,170 And they're all linked together by these volumetric flows 1027 00:45:28,170 --> 00:45:29,630 from one to another. 1028 00:45:29,630 --> 00:45:31,470 And that's, in fact, what they are. 1029 00:45:31,470 --> 00:45:35,442 The key is, how do I model these fluxes, basically? 1030 00:45:35,442 --> 00:45:36,900 The accuracy of the method is going 1031 00:45:36,900 --> 00:45:40,081 to be set by how big a volume am I going to model. 1032 00:45:40,081 --> 00:45:41,580 Can't have infinitely small volumes. 1033 00:45:41,580 --> 00:45:43,163 There are going to be too many of them 1034 00:45:43,163 --> 00:45:45,930 in my domain to solve the problem accurately. 1035 00:45:45,930 --> 00:45:49,346 And then, do I have good models for these fluxes? 1036 00:45:49,346 --> 00:45:51,799 And you can think about these terms in this way. 1037 00:45:51,799 --> 00:45:52,840 That sometimes is useful. 1038 00:45:52,840 --> 00:45:56,450 So this big B, the amount of b in the volume, 1039 00:45:56,450 --> 00:45:59,000 is like the volume times the density 1040 00:45:59,000 --> 00:46:02,090 of b, the volumetric density of b in the volume. 1041 00:46:02,090 --> 00:46:04,520 The average density in the volume. 1042 00:46:04,520 --> 00:46:07,730 R is like the volume multiplied by the average rate 1043 00:46:07,730 --> 00:46:10,520 of generation or consumption. 1044 00:46:10,520 --> 00:46:13,430 F is the flux in or out. 1045 00:46:13,430 --> 00:46:16,340 It's the sum over all the faces of the flux through each 1046 00:46:16,340 --> 00:46:21,260 of the faces, which is the area of the face multiplied 1047 00:46:21,260 --> 00:46:23,150 by the average flux through the face. 1048 00:46:23,150 --> 00:46:24,590 So this is the normal to the face, 1049 00:46:24,590 --> 00:46:28,510 and this is the flux through the face. 1050 00:46:28,510 --> 00:46:29,300 And so I just-- 1051 00:46:29,300 --> 00:46:30,970 I'm going to solve this equation. 1052 00:46:30,970 --> 00:46:37,140 I try to figure out, in each volume, what's the average b? 1053 00:46:37,140 --> 00:46:38,670 That's what this tells me. 1054 00:46:38,670 --> 00:46:40,350 On average, what is b? 1055 00:46:40,350 --> 00:46:42,690 On average, what is the concentration? 1056 00:46:42,690 --> 00:46:44,790 On average, what is the amount of momentum? 1057 00:46:44,790 --> 00:46:48,020 On average, what is the total energy? 1058 00:46:48,020 --> 00:46:49,980 That's fine. 1059 00:46:49,980 --> 00:46:51,420 So finite volume, very simple. 1060 00:46:55,190 --> 00:46:56,780 What's nice about it? 1061 00:46:56,780 --> 00:47:00,067 Well, you know, it's really suitable to any sort 1062 00:47:00,067 --> 00:47:01,400 of geometry you want to look at. 1063 00:47:01,400 --> 00:47:05,210 We want to solve this equation, say, in this square domain. 1064 00:47:05,210 --> 00:47:07,880 We divide the domain up into a bunch of little square volumes. 1065 00:47:07,880 --> 00:47:12,380 And in each volume, we just make sure that the amount of this b 1066 00:47:12,380 --> 00:47:16,160 balances the fluxes coming through the volume 1067 00:47:16,160 --> 00:47:20,000 and the amount of consumption or generation 1068 00:47:20,000 --> 00:47:22,370 of that quantity within the volume. 1069 00:47:22,370 --> 00:47:24,485 But it didn't have to be a square domain, right? 1070 00:47:24,485 --> 00:47:26,132 A square domain, that's OK. 1071 00:47:26,132 --> 00:47:28,340 But maybe I want to solve it on some circular domain. 1072 00:47:28,340 --> 00:47:30,214 Well, I can divide that up into volumes, too. 1073 00:47:30,214 --> 00:47:32,780 And actually, these equations are the same. 1074 00:47:32,780 --> 00:47:34,370 They look identical. 1075 00:47:34,370 --> 00:47:37,450 I've just got to calculate the flux through each of the faces. 1076 00:47:37,450 --> 00:47:39,280 OK? 1077 00:47:39,280 --> 00:47:41,170 But maybe I'm interested in, I don't know, 1078 00:47:41,170 --> 00:47:43,080 pollution in one of the Great Lakes. 1079 00:47:43,080 --> 00:47:45,670 And I want to know how concentration of some pollutant 1080 00:47:45,670 --> 00:47:47,390 is transformed. 1081 00:47:47,390 --> 00:47:49,730 I'd divide this up into a bunch of little volumes, too. 1082 00:47:49,730 --> 00:47:50,950 And now I've got to calculate the flux 1083 00:47:50,950 --> 00:47:52,116 through each of these faces. 1084 00:47:52,116 --> 00:47:55,570 And that links all these domains together. 1085 00:47:55,570 --> 00:47:57,430 Maybe I'm interested in transport 1086 00:47:57,430 --> 00:48:00,347 within some porous medium-- say, a bone. 1087 00:48:00,347 --> 00:48:01,930 I think it's someone's hip joint here. 1088 00:48:01,930 --> 00:48:04,054 OK, well, I divide that up into a bunch of volumes. 1089 00:48:04,054 --> 00:48:07,220 And I still solve the exact same conservation equation. 1090 00:48:07,220 --> 00:48:10,510 So I've sort of decoupled the problem of meshing 1091 00:48:10,510 --> 00:48:13,504 and equations, the governing equations associated 1092 00:48:13,504 --> 00:48:14,170 with the meshes. 1093 00:48:14,170 --> 00:48:16,830 As long as I have a way to divide the domain up. 1094 00:48:16,830 --> 00:48:18,390 It may be very complicated. 1095 00:48:18,390 --> 00:48:20,789 I'm going to go ask a buddy in applied math to do that. 1096 00:48:20,789 --> 00:48:23,080 But I'm going to come to him with the right engineering 1097 00:48:23,080 --> 00:48:25,450 equations for each of those domains, a little equation 1098 00:48:25,450 --> 00:48:26,420 for a CSTR. 1099 00:48:26,420 --> 00:48:28,360 OK? 1100 00:48:28,360 --> 00:48:35,950 Turns out this-- you know, one of the most common 1101 00:48:35,950 --> 00:48:38,260 fluid mechanical codes out there that people use now 1102 00:48:38,260 --> 00:48:39,840 is OpenFOAM. 1103 00:48:39,840 --> 00:48:42,010 So it's very common. 1104 00:48:42,010 --> 00:48:42,990 Lots of people use it. 1105 00:48:42,990 --> 00:48:44,230 It's a very general solver. 1106 00:48:44,230 --> 00:48:45,610 Does finite volume. 1107 00:48:45,610 --> 00:48:47,110 That's the method it chooses to use. 1108 00:48:47,110 --> 00:48:48,318 Why does it choose to use it? 1109 00:48:48,318 --> 00:48:50,700 Because it wants to conserved momentum? 1110 00:48:50,700 --> 00:48:53,260 A guaranteed momentum conservation. 1111 00:48:53,260 --> 00:48:56,330 Can't lose momentum, can't lose energy. 1112 00:48:56,330 --> 00:48:57,770 Can't lose mass. 1113 00:48:57,770 --> 00:48:59,560 I just have to pass the right amount 1114 00:48:59,560 --> 00:49:01,420 between each of these faces. 1115 00:49:01,420 --> 00:49:03,340 As long as my calculation of that is accurate, 1116 00:49:03,340 --> 00:49:05,470 I've conserved the quantity. 1117 00:49:05,470 --> 00:49:06,910 Never evaporates. 1118 00:49:06,910 --> 00:49:11,260 Finite difference, finite element, different basis 1119 00:49:11,260 --> 00:49:14,640 set expansions-- they will have this problem 1120 00:49:14,640 --> 00:49:16,480 that at low levels of accuracy, you 1121 00:49:16,480 --> 00:49:20,320 can have sort of artificial consumption of, say, 1122 00:49:20,320 --> 00:49:22,870 the quantity, or artificial production 1123 00:49:22,870 --> 00:49:26,420 of the conserved quantity of interest. 1124 00:49:26,420 --> 00:49:29,020 So this can be a very nice way to solve these problems. 1125 00:49:29,020 --> 00:49:30,370 It's another relaxation method. 1126 00:49:30,370 --> 00:49:31,510 It's a type of collocation. 1127 00:49:31,510 --> 00:49:34,030 I divide the domain up. 1128 00:49:34,030 --> 00:49:36,891 And then I try to satisfy conservation equations on each 1129 00:49:36,891 --> 00:49:37,890 of these little volumes. 1130 00:49:37,890 --> 00:49:40,604 Hence finite volume. 1131 00:49:40,604 --> 00:49:42,410 OK? 1132 00:49:42,410 --> 00:49:42,970 OK. 1133 00:49:42,970 --> 00:49:46,990 So how do you solve PDEs by hand or write your own code? 1134 00:49:46,990 --> 00:49:48,700 There's a nice little tutorial here. 1135 00:49:48,700 --> 00:49:51,283 We'll see how far we're able to get through it before I've got 1136 00:49:51,283 --> 00:49:52,480 to give you guys your cards. 1137 00:49:52,480 --> 00:49:54,790 But I'll illustrate some key points 1138 00:49:54,790 --> 00:49:56,380 that I think are really important. 1139 00:49:56,380 --> 00:49:58,960 So step one, no matter what method 1140 00:49:58,960 --> 00:50:02,290 you choose, whether you choose collocation, whether you choose 1141 00:50:02,290 --> 00:50:05,050 Galerkin, whether you're using basis sets 1142 00:50:05,050 --> 00:50:08,034 or you're using finite elements or finite volumes, 1143 00:50:08,034 --> 00:50:10,450 you've got some domain you're trying to solve your PDE in. 1144 00:50:10,450 --> 00:50:13,020 And you've got to discretize it. 1145 00:50:13,020 --> 00:50:16,269 You've got to figure out how to decompose the domain. 1146 00:50:16,269 --> 00:50:18,310 So for finite differences, you might decompose it 1147 00:50:18,310 --> 00:50:19,990 into a series of nodes at which you 1148 00:50:19,990 --> 00:50:22,750 want to know the value of your function, whatever 1149 00:50:22,750 --> 00:50:24,162 that function is. 1150 00:50:24,162 --> 00:50:25,870 For finite volume, you would decompose it 1151 00:50:25,870 --> 00:50:27,550 into cells in which you would like 1152 00:50:27,550 --> 00:50:30,790 to know the average value of your conserved quantity. 1153 00:50:30,790 --> 00:50:36,490 For finite elements, you divide the domain up into some points, 1154 00:50:36,490 --> 00:50:40,680 across which local basis functions span the region. 1155 00:50:40,680 --> 00:50:43,330 We would like to know the weighting of these local basis 1156 00:50:43,330 --> 00:50:45,716 functions near each of these points. 1157 00:50:45,716 --> 00:50:47,340 But you've got to divide the domain up. 1158 00:50:47,340 --> 00:50:50,590 And the most important thing is you always 1159 00:50:50,590 --> 00:50:54,910 choose the spacing of the nodes, or the dimensions of the cells, 1160 00:50:54,910 --> 00:50:56,470 to match the physics. 1161 00:50:56,470 --> 00:50:59,890 A very natural thing to want to do is to pick-- 1162 00:50:59,890 --> 00:51:02,380 say I've got this square grid-- to pick the number of grid 1163 00:51:02,380 --> 00:51:04,000 points to discretize with. 1164 00:51:04,000 --> 00:51:05,710 I say, I'm going to use 100 points 1165 00:51:05,710 --> 00:51:07,917 in this dimension and 100 points in that dimension. 1166 00:51:07,917 --> 00:51:09,250 Actually, that tells me nothing. 1167 00:51:09,250 --> 00:51:11,350 That's an irrelevant number. 1168 00:51:11,350 --> 00:51:15,590 The physics has no idea how many grid nodes you put in there. 1169 00:51:15,590 --> 00:51:17,500 Doesn't care. 1170 00:51:17,500 --> 00:51:20,860 There are length scales that are intrinsic to the problem you're 1171 00:51:20,860 --> 00:51:22,540 trying to study. 1172 00:51:22,540 --> 00:51:26,080 And the discretization should resolve those physically 1173 00:51:26,080 --> 00:51:28,330 relevant length scales. 1174 00:51:28,330 --> 00:51:31,030 So it might be the case that I only 1175 00:51:31,030 --> 00:51:36,070 need a resolution of one part in 10 along this dimension 1176 00:51:36,070 --> 00:51:38,110 and one part in 10 along this dimension 1177 00:51:38,110 --> 00:51:40,540 because the physics are such that that's 1178 00:51:40,540 --> 00:51:43,780 good to get a description of the solution to this problem. 1179 00:51:43,780 --> 00:51:47,140 It might be that I need one part in a million in this dimension 1180 00:51:47,140 --> 00:51:49,120 and one part in 10 in that dimension 1181 00:51:49,120 --> 00:51:51,770 because the physics are that way. 1182 00:51:51,770 --> 00:51:53,795 So you really want to think about length scales, 1183 00:51:53,795 --> 00:51:54,670 not numbers of nodes. 1184 00:51:54,670 --> 00:51:55,795 It's a very common mistake. 1185 00:51:55,795 --> 00:51:58,600 You say, well, 100 and 100, that makes sense, or 10 and 10. 1186 00:51:58,600 --> 00:52:00,280 Or you know, you pick these randomly. 1187 00:52:00,280 --> 00:52:02,113 But you want to think about physics instead. 1188 00:52:02,113 --> 00:52:03,250 Here's a good example. 1189 00:52:03,250 --> 00:52:05,580 This is my fault. You'll solve a problem like this. 1190 00:52:05,580 --> 00:52:08,710 You already saw it in some sense in the finite element 1191 00:52:08,710 --> 00:52:10,010 or COMSOL tutorial. 1192 00:52:10,010 --> 00:52:13,330 But there's a little drug patch here near this red zone. 1193 00:52:13,330 --> 00:52:15,610 It's leaking drug into a sheer flow, 1194 00:52:15,610 --> 00:52:18,610 and it's all being advected down. 1195 00:52:18,610 --> 00:52:21,500 Here's my solution to the problem. 1196 00:52:21,500 --> 00:52:23,080 I think it's a pretty good one. 1197 00:52:23,080 --> 00:52:27,270 Here's a solution from when I taught of course two years ago 1198 00:52:27,270 --> 00:52:28,780 that the TAs produced. 1199 00:52:28,780 --> 00:52:32,050 And I didn't talk with the TAs about this issue with length 1200 00:52:32,050 --> 00:52:32,940 scales. 1201 00:52:32,940 --> 00:52:34,800 And it sort of got the right structure. 1202 00:52:34,800 --> 00:52:36,790 You can see, here's the patch, and there's 1203 00:52:36,790 --> 00:52:39,850 some advection and diffusion. 1204 00:52:39,850 --> 00:52:42,010 But it's not a very stable solution, it turns out. 1205 00:52:42,010 --> 00:52:44,740 It's also not very accurate. 1206 00:52:44,740 --> 00:52:46,570 It doesn't reflect the essential physics. 1207 00:52:46,570 --> 00:52:48,210 And the point is actually the scales. 1208 00:52:48,210 --> 00:52:52,180 So here, the patch was 1 centimeter in diameter. 1209 00:52:52,180 --> 00:52:53,950 And so here, you got many centimeters 1210 00:52:53,950 --> 00:52:56,680 long this direction, where you get advection. 1211 00:52:56,680 --> 00:52:58,990 Here, you've got 2 centimeters in this direction. 1212 00:52:58,990 --> 00:53:01,570 But actually, the solution is really confined down 1213 00:53:01,570 --> 00:53:02,770 to this small space. 1214 00:53:02,770 --> 00:53:10,060 The physics all happens at fractions of a centimeter. 1215 00:53:10,060 --> 00:53:12,070 You took Transport, so you know that this 1216 00:53:12,070 --> 00:53:14,110 is a problem in which there's a boundary layer. 1217 00:53:14,110 --> 00:53:16,900 And all the change in concentration 1218 00:53:16,900 --> 00:53:19,450 is confined to that little boundary layer. 1219 00:53:19,450 --> 00:53:21,430 So really, when you do your numerical solution, 1220 00:53:21,430 --> 00:53:23,205 you'll do like was done up here. 1221 00:53:23,205 --> 00:53:25,330 Now the lengths are made dimensionless on the width 1222 00:53:25,330 --> 00:53:26,470 of the patch, but they're-- you know, 1223 00:53:26,470 --> 00:53:27,910 you can think of these as measured in centimeters. 1224 00:53:27,910 --> 00:53:29,380 But look at the dimension here. 1225 00:53:29,380 --> 00:53:31,210 We need to resolve the solution down 1226 00:53:31,210 --> 00:53:34,900 at the 0.1 centimeter and smaller scale. 1227 00:53:34,900 --> 00:53:37,270 I want to put all my little discretization or my nodes 1228 00:53:37,270 --> 00:53:42,490 down here so that I can see how the concentration field changes 1229 00:53:42,490 --> 00:53:43,900 as a function of distance. 1230 00:53:43,900 --> 00:53:45,649 I have to know something about the physics 1231 00:53:45,649 --> 00:53:46,690 to do that, though, OK? 1232 00:53:46,690 --> 00:53:48,670 Can't just solve this blindly. 1233 00:53:48,670 --> 00:53:51,520 It may or may not be the case that COMSOL 1234 00:53:51,520 --> 00:53:53,990 recognizes the physical situation 1235 00:53:53,990 --> 00:53:56,620 and remeshes your problem to put mesh points down 1236 00:53:56,620 --> 00:53:58,350 where they matter. 1237 00:53:58,350 --> 00:53:59,150 It may do that. 1238 00:53:59,150 --> 00:54:00,150 It may not do that. 1239 00:54:00,150 --> 00:54:02,230 It just doesn't know. 1240 00:54:02,230 --> 00:54:04,884 People build heuristics to try to solve these remeshing 1241 00:54:04,884 --> 00:54:06,550 problems, but they may not always apply. 1242 00:54:06,550 --> 00:54:08,800 So it's good to understand the physics of the problem. 1243 00:54:08,800 --> 00:54:11,300 This drug patch problem, this is a pretty common transport 1244 00:54:11,300 --> 00:54:11,800 problem. 1245 00:54:11,800 --> 00:54:14,140 I mean, did Professor Bazant give you guys 1246 00:54:14,140 --> 00:54:15,570 a talk during your visit weekend? 1247 00:54:15,570 --> 00:54:17,100 Was that this last year? 1248 00:54:17,100 --> 00:54:18,875 Was that two years ago? 1249 00:54:18,875 --> 00:54:19,750 It was two years ago. 1250 00:54:19,750 --> 00:54:22,790 He does problems with bromine flow batteries. 1251 00:54:22,790 --> 00:54:24,190 And they worked exactly this way. 1252 00:54:24,190 --> 00:54:26,850 You have flow of bromine in. 1253 00:54:26,850 --> 00:54:29,522 An electrochemical reaction takes place at the surface. 1254 00:54:29,522 --> 00:54:31,230 This entire thing is premised on the fact 1255 00:54:31,230 --> 00:54:32,646 that you have a very thin boundary 1256 00:54:32,646 --> 00:54:36,240 layer in which the electrochemical-- in which 1257 00:54:36,240 --> 00:54:37,740 the reagents are confined. 1258 00:54:37,740 --> 00:54:39,450 And if that boundary layer gets too thick 1259 00:54:39,450 --> 00:54:42,420 and reaches the other electrode, it screws up the reaction 1260 00:54:42,420 --> 00:54:44,310 and doesn't work as a battery anymore. 1261 00:54:44,310 --> 00:54:47,582 So being able to resolve concentration gradients 1262 00:54:47,582 --> 00:54:50,040 in this small domain, it's not just important for this drug 1263 00:54:50,040 --> 00:54:50,325 problem. 1264 00:54:50,325 --> 00:54:51,585 It's important in general. 1265 00:54:51,585 --> 00:54:55,140 It's a common sort of transport-y type problem. 1266 00:54:55,140 --> 00:54:56,640 And the numerical solution is really 1267 00:54:56,640 --> 00:54:59,190 going to hinge on your ability to recognize the physics 1268 00:54:59,190 --> 00:55:02,460 and resolve the solution over the length scales that 1269 00:55:02,460 --> 00:55:03,940 are important in the problem. 1270 00:55:03,940 --> 00:55:05,220 OK? 1271 00:55:05,220 --> 00:55:07,290 So that's the number one most important thing 1272 00:55:07,290 --> 00:55:08,460 for doing these PDEs. 1273 00:55:08,460 --> 00:55:11,400 The rest of the notes will take you 1274 00:55:11,400 --> 00:55:13,980 through the construction of a numerical solution 1275 00:55:13,980 --> 00:55:18,660 to the diffusion equation in 2D, and some different scenarios 1276 00:55:18,660 --> 00:55:22,090 that you might try to employ in MATLAB to solve them, 1277 00:55:22,090 --> 00:55:25,230 and how you can accelerate the solution using different MATLAB 1278 00:55:25,230 --> 00:55:26,340 functions. 1279 00:55:26,340 --> 00:55:27,930 It's fun to try out and play with. 1280 00:55:27,930 --> 00:55:30,221 You'll see that I can make the solution to this problem 1281 00:55:30,221 --> 00:55:32,280 go very fast for a domain that's quite highly 1282 00:55:32,280 --> 00:55:36,790 discretized by recognizing certain forms of the equations, 1283 00:55:36,790 --> 00:55:39,330 choosing certain solvers to solve with. 1284 00:55:39,330 --> 00:55:40,470 OK? 1285 00:55:40,470 --> 00:55:41,467 Good. 1286 00:55:41,467 --> 00:55:43,050 All right, I'll meet you guys in back, 1287 00:55:43,050 --> 00:55:45,600 and we'll hand out these gift cards. 1288 00:55:45,600 --> 00:55:47,780 And good luck on your quiz.