1 00:00:00 --> 00:00:01 2 00:00:01 --> 00:00:02 The following content is provided under a Creative 3 00:00:02 --> 00:00:03 Commons license. 4 00:00:03 --> 00:00:07 Your support will help MIT OpenCourseWare offer high 5 00:00:07 --> 00:00:09 quality educational resources for free. 6 00:00:09 --> 00:00:12 To make a donation or to view additional materials from 7 00:00:12 --> 00:00:16 hundreds of MIT courses, visit MIT OpenCourseWare 8 00:00:16 --> 00:00:19 at ocw.mit.edu. 9 00:00:19 --> 00:00:22 PROFESSOR STRANG: Starting with a differential equation. 10 00:00:22 --> 00:00:27 So key point here in this lecture is how do you start 11 00:00:27 --> 00:00:31 with a differential equation and end up with a discrete 12 00:00:31 --> 00:00:38 problem that you can solve? 13 00:00:38 --> 00:00:40 But simple differential equation. 14 00:00:40 --> 00:00:44 It's got a second derivative and I put a minus sign for a 15 00:00:44 --> 00:00:46 reason that you will see. 16 00:00:46 --> 00:00:51 Second derivatives are essentially negative definite 17 00:00:51 --> 00:00:55 things so that minus sign is to really make it 18 00:00:55 --> 00:00:56 positive definite. 19 00:00:56 --> 00:01:02 And notice we have boundary conditions that at one end 20 00:01:02 --> 00:01:04 the solution is zero, at the other end it's zero. 21 00:01:04 --> 00:01:07 So this is fixed-fixed. 22 00:01:07 --> 00:01:10 And it's a boundary value problem. 23 00:01:10 --> 00:01:14 That's different from an initial value problem. 24 00:01:14 --> 00:01:17 We have x space, not time. 25 00:01:17 --> 00:01:20 So we're not starting from some thing and oscillating or 26 00:01:20 --> 00:01:24 growing or decaying in time. 27 00:01:24 --> 00:01:25 We have a fixed thing. 28 00:01:25 --> 00:01:27 Think of an elastic bar. 29 00:01:27 --> 00:01:31 An elastic bar fixed at both ends, maybe hanging 30 00:01:31 --> 00:01:33 by its own weight. 31 00:01:33 --> 00:01:37 So that load f(x) could represent the weight. 32 00:01:37 --> 00:01:40 Maybe the good place to sit is over there, there are tables 33 00:01:40 --> 00:01:43 just, how about that? 34 00:01:43 --> 00:01:48 It's more comfortable. 35 00:01:48 --> 00:01:51 So we can solve that equation. 36 00:01:51 --> 00:01:54 Especially when I change f(x) to be one. 37 00:01:54 --> 00:01:56 As I plan to do. 38 00:01:56 --> 00:01:59 So I'm going to change, I'm going to make it-- it's a 39 00:01:59 --> 00:02:03 uniform bar because there's no variable coefficient in 40 00:02:03 --> 00:02:07 there and let me make it a uniform load, just one. 41 00:02:07 --> 00:02:12 So it actually shows you that, I mentioned differential 42 00:02:12 --> 00:02:15 equations and we'll certainly get onto Laplace's equation, 43 00:02:15 --> 00:02:18 but essentially our differential equations will 44 00:02:18 --> 00:02:23 not-- this isn't a course in how to solve ODEs or PDEs. 45 00:02:23 --> 00:02:25 Especially not ODEs. 46 00:02:25 --> 00:02:28 It's a course in how to compute solutions. 47 00:02:28 --> 00:02:32 So the key idea will be to replace the differential 48 00:02:32 --> 00:02:34 equation by a difference equation. 49 00:02:34 --> 00:02:37 So there's the difference equation. 50 00:02:37 --> 00:02:40 And I have to talk about that. 51 00:02:40 --> 00:02:43 That's the sort of key point. 52 00:02:43 --> 00:02:50 That up here you see what I would call a second difference. 53 00:02:50 --> 00:02:54 Actually with a minus sign. 54 00:02:54 --> 00:02:58 And on the right-hand side you see the load, still f(x). 55 00:02:59 --> 00:03:03 Can I move to this board to explain differences? 56 00:03:03 --> 00:03:07 Because this is like, key step is given the differential 57 00:03:07 --> 00:03:11 equation replace it by difference equation. 58 00:03:11 --> 00:03:15 And the interesting point is you have many choices. 59 00:03:15 --> 00:03:19 There's one differential equation but even for a first 60 00:03:19 --> 00:03:26 derivative, so this if you remember from calculus, how did 61 00:03:26 --> 00:03:28 you start with the derivative? 62 00:03:28 --> 00:03:34 You started by something before going to the limit. h or delta 63 00:03:34 --> 00:03:38 x goes to zero in the end to get the derivative. 64 00:03:38 --> 00:03:41 But this was a finite difference. 65 00:03:41 --> 00:03:44 You moved a finite amount. 66 00:03:44 --> 00:03:48 And this is the one you always see in calculus courses. 67 00:03:48 --> 00:03:55 U(x + h)-U(x) just how much did that step go. 68 00:03:55 --> 00:04:02 You divide by the delta x, the h and that's approximately 69 00:04:02 --> 00:04:03 the derivative, U'(x). 70 00:04:03 --> 00:04:07 71 00:04:07 --> 00:04:11 Let me just continue with these others. 72 00:04:11 --> 00:04:15 I don't remember if calculus mentions a backward difference. 73 00:04:15 --> 00:04:21 But you won't be surprised that another possibility, equally 74 00:04:21 --> 00:04:25 good more or less, would be to take the point and the point 75 00:04:25 --> 00:04:29 before, take the difference, divide by delta x. 76 00:04:29 --> 00:04:32 So again all these approximate U'. 77 00:04:32 --> 00:04:38 And now here's one that actually is really important. 78 00:04:38 --> 00:04:39 A center difference. 79 00:04:39 --> 00:04:43 It's the average of the forward and back. 80 00:04:43 --> 00:04:47 If I take that plus that, the U(x)'s cancel and I'm left 81 00:04:47 --> 00:04:50 with, I'm centering it. 82 00:04:50 --> 00:04:53 This idea of centering is a good thing actually. 83 00:04:53 --> 00:04:57 And of course I have to divide by 2h because this step 84 00:04:57 --> 00:05:00 is now 2h, two delta x's. 85 00:05:00 --> 00:05:02 So that again is going to represent U'. 86 00:05:02 --> 00:05:05 87 00:05:05 --> 00:05:10 But so we have a choice if we have a first derivative. 88 00:05:10 --> 00:05:15 And actually that's a big issue. 89 00:05:15 --> 00:05:19 You know, one might be called upwind, one might be called 90 00:05:19 --> 00:05:21 downwind, one may be called centered. 91 00:05:21 --> 00:05:24 It comes up constantly in aero and mechanical 92 00:05:24 --> 00:05:26 engineering, everywhere. 93 00:05:26 --> 00:05:28 You have these choices to make. 94 00:05:28 --> 00:05:30 Especially for the first difference. 95 00:05:30 --> 00:05:36 We don't have, I didn't allow a first derivative in that 96 00:05:36 --> 00:05:41 equation because I wanted to keep it symmetric and first 97 00:05:41 --> 00:05:45 derivatives, first differences tend to be anti-symmetric. 98 00:05:45 --> 00:05:50 So if we want to get our good matrix K, and I better remember 99 00:05:50 --> 00:05:55 to divide by h squared because the K just has those that I 100 00:05:55 --> 00:05:59 introduced last time and will repeat, the K just has 101 00:05:59 --> 00:06:00 the numbers -1, 2, -1. 102 00:06:02 --> 00:06:09 Now, first point before we leave these guys 103 00:06:09 --> 00:06:11 what's up with them? 104 00:06:11 --> 00:06:13 How do we decide which one is better? 105 00:06:13 --> 00:06:17 There's something called the order of accuracy. 106 00:06:17 --> 00:06:21 How close is the difference to the derivative? 107 00:06:21 --> 00:06:26 And the answer is the error is of size h. 108 00:06:26 --> 00:06:33 So I would call that first order accurate. 109 00:06:33 --> 00:06:39 And I can repeat here but the text does it, how you recognize 110 00:06:39 --> 00:06:44 what this is the, sort of local error, truncation error, 111 00:06:44 --> 00:06:50 whatever, you've chopped off the exact answer and 112 00:06:50 --> 00:06:51 just did differences. 113 00:06:51 --> 00:06:55 This one is also order of h. 114 00:06:55 --> 00:07:00 And in fact, the h terms, the leading error, which is going 115 00:07:00 --> 00:07:05 to multiply the h, has opposite sign in these two and 116 00:07:05 --> 00:07:08 that's the reason center differences are great. 117 00:07:08 --> 00:07:13 Because when you average them you center things. 118 00:07:13 --> 00:07:19 This is correct to order h squared. 119 00:07:19 --> 00:07:24 And I may come back and find out why that h squared term is. 120 00:07:24 --> 00:07:25 Maybe I'll do that. 121 00:07:25 --> 00:07:26 Yeah. 122 00:07:26 --> 00:07:27 Why don't I just? 123 00:07:27 --> 00:07:29 Second differences are so important. 124 00:07:29 --> 00:07:31 Why don't we just see. 125 00:07:31 --> 00:07:32 And center differences. 126 00:07:32 --> 00:07:34 So let me see. 127 00:07:34 --> 00:07:36 How do you figure U(x + h)? 128 00:07:36 --> 00:07:40 129 00:07:40 --> 00:07:48 This is a chance to remember something called Taylor series. 130 00:07:48 --> 00:07:51 But that was in calculus. 131 00:07:51 --> 00:07:55 If you forgot it, you're a normal person. 132 00:07:55 --> 00:07:58 So but what does it say? 133 00:07:58 --> 00:08:01 That's the whole point of calculus, in a way. 134 00:08:01 --> 00:08:07 That if I move a little bit, I start from the point x and then 135 00:08:07 --> 00:08:11 there's a little correction and that's given by the derivative 136 00:08:11 --> 00:08:14 and then there's a further correction if I want to go 137 00:08:14 --> 00:08:18 further and that's given by half of h squared, you see 138 00:08:18 --> 00:08:23 the second order correction, times the second derivative. 139 00:08:23 --> 00:08:25 And then, of course, more. 140 00:08:25 --> 00:08:28 But that's all you ever have to remember. 141 00:08:28 --> 00:08:29 It's pretty rare. 142 00:08:29 --> 00:08:35 Second order accuracy is often the goal in 143 00:08:35 --> 00:08:38 scientific computing. 144 00:08:38 --> 00:08:41 First order accuracy is, like, the lowest level. 145 00:08:41 --> 00:08:44 You start there, you write a code, you test it and so on. 146 00:08:44 --> 00:08:48 But if you want production, if you want accuracy, get to 147 00:08:48 --> 00:08:50 second order if possible. 148 00:08:50 --> 00:08:52 Now, what about this U(x - h)? 149 00:08:53 --> 00:08:55 Well, that's a step backwards, so that's U(x). 150 00:08:56 --> 00:09:02 Now the step is -h, but then when I square that step I'm 151 00:09:02 --> 00:09:08 back to +h squared, U''(x) and so on. 152 00:09:08 --> 00:09:09 Ooh! 153 00:09:09 --> 00:09:14 Am I going to find even more accuracy? 154 00:09:14 --> 00:09:17 I could tell you what the next turn is. 155 00:09:17 --> 00:09:22 Plus h cubed upon six, that's three times 156 00:09:22 --> 00:09:25 two times one, U''' . 157 00:09:25 --> 00:09:30 And this would be, since this step is -h now, it would be 158 00:09:30 --> 00:09:34 -h cubed upon six U''' . 159 00:09:34 --> 00:09:37 So what happens when I take the difference of these two? 160 00:09:37 --> 00:09:40 Remember now that center differences subtract 161 00:09:40 --> 00:09:42 this from this. 162 00:09:42 --> 00:09:51 So now that U(x + h)-U(x-h) is zero. 163 00:09:51 --> 00:09:58 2hU' subtracting that from that is zero, two of these, so I 164 00:09:58 --> 00:10:02 guess that we really have an h cubed over three, U'''. 165 00:10:02 --> 00:10:05 166 00:10:05 --> 00:10:09 And now when I divide by the 2h, can I just 167 00:10:09 --> 00:10:11 divide by 2h here? 168 00:10:11 --> 00:10:15 Oh yeah, it's coming out right, divide by 2h, divide this by 169 00:10:15 --> 00:10:19 2h, that'll make it an h squared over six. 170 00:10:19 --> 00:10:22 I've done what looks like a messy computation. 171 00:10:22 --> 00:10:26 I'm a little sad to start a good lecture, important 172 00:10:26 --> 00:10:29 lecture by such grungy stuff. 173 00:10:29 --> 00:10:33 But it makes the key point. 174 00:10:33 --> 00:10:38 That the center difference gives the correct derivative 175 00:10:38 --> 00:10:41 with an error of order h squared. 176 00:10:41 --> 00:10:47 Where the error if for the first differences the h 177 00:10:47 --> 00:10:49 would have been there. 178 00:10:49 --> 00:10:51 And we can test it. 179 00:10:51 --> 00:10:54 Actually we'll test it. 180 00:10:54 --> 00:10:55 Okay for that? 181 00:10:55 --> 00:10:57 This is first differences. 182 00:10:57 --> 00:11:00 And that's a big question; what do you replace the first 183 00:11:00 --> 00:11:03 derivative by if there is one? 184 00:11:03 --> 00:11:05 And you've got these three choices. 185 00:11:05 --> 00:11:08 And usually this is the best choice. 186 00:11:08 --> 00:11:10 Now to second derivatives. 187 00:11:10 --> 00:11:17 Because our equation has got U'' in it. 188 00:11:17 --> 00:11:20 So what's a second derivative? 189 00:11:20 --> 00:11:23 It's the derivative of the derivative. 190 00:11:23 --> 00:11:24 So what's the second difference? 191 00:11:24 --> 00:11:27 It's the difference, first difference of 192 00:11:27 --> 00:11:29 the first difference. 193 00:11:29 --> 00:11:32 So the second difference, the natural second difference would 194 00:11:32 --> 00:11:39 be-- so now let me use this space for second differences. 195 00:11:39 --> 00:11:42 Second differences. 196 00:11:42 --> 00:11:46 I could take the forward difference of the 197 00:11:46 --> 00:11:48 backward difference. 198 00:11:48 --> 00:11:51 Or I could take the backward difference of 199 00:11:51 --> 00:11:52 the forward difference. 200 00:11:52 --> 00:11:55 Or you may say why don't I take the center difference 201 00:11:55 --> 00:11:57 of the center difference. 202 00:11:57 --> 00:12:02 All those, in some sense it's delta squared, 203 00:12:02 --> 00:12:05 but which to take? 204 00:12:05 --> 00:12:12 Well actually those are the same and that's the good 205 00:12:12 --> 00:12:16 choice, that's the 1, -2, 1 choice. 206 00:12:16 --> 00:12:18 So let me show you that. 207 00:12:18 --> 00:12:20 Let me say what's the matter with that. 208 00:12:20 --> 00:12:25 Because now having said how great center differences are, 209 00:12:25 --> 00:12:29 first differences, why don't I just repeat them for 210 00:12:29 --> 00:12:31 second differences? 211 00:12:31 --> 00:12:35 Well the trouble is, let me say in a word without even writing, 212 00:12:35 --> 00:12:40 well I could even write a little, the center difference, 213 00:12:40 --> 00:12:43 suppose I'm at a typical mesh point here. 214 00:12:43 --> 00:12:46 The center difference is going to take that value minus that 215 00:12:46 --> 00:12:51 value But then if I take the center difference of that 216 00:12:51 --> 00:12:52 I'm going to be out here. 217 00:12:52 --> 00:12:56 I'm going to take this value, this value, and this value. 218 00:12:56 --> 00:12:58 I'll get something correct. 219 00:12:58 --> 00:13:00 Its accuracy will be second order, good. 220 00:13:00 --> 00:13:05 But it stretches too far. 221 00:13:05 --> 00:13:09 We want compact difference molecules. 222 00:13:09 --> 00:13:15 We don't want this one, minus two of this, plus one of that. 223 00:13:15 --> 00:13:22 So this would give us a 1, 0, -2 , 0, 1. 224 00:13:22 --> 00:13:26 I'm just saying this and then I'll never come back to it 225 00:13:26 --> 00:13:32 because I don't like this one, these guys give 1, -2, 226 00:13:32 --> 00:13:36 1 without any gaps. 227 00:13:36 --> 00:13:37 And that's the right choice. 228 00:13:37 --> 00:13:40 And that's the choice made here. 229 00:13:40 --> 00:13:46 So I'm not thinking you can see it in your head, the 230 00:13:46 --> 00:13:48 difference of the difference. 231 00:13:48 --> 00:13:51 But well, you almost can. 232 00:13:51 --> 00:13:53 If I take this, yeah. 233 00:13:53 --> 00:13:56 Can you sort of see this without my writing it? 234 00:13:56 --> 00:14:02 If I take the forward difference and then I subtract 235 00:14:02 --> 00:14:07 the forward difference to the left, do you see that 236 00:14:07 --> 00:14:08 I'll have minus two. 237 00:14:08 --> 00:14:10 So there is what I started with. 238 00:14:10 --> 00:14:18 I subtract U(x)-U(x-h) and I get two -U(x)'s. 239 00:14:19 --> 00:14:22 This is what I get. 240 00:14:22 --> 00:14:23 Now I'm calling that ui. 241 00:14:23 --> 00:14:29 242 00:14:29 --> 00:14:33 I better make completely clear about the minus sign. 243 00:14:33 --> 00:14:36 The forward difference or the backward difference, what 244 00:14:36 --> 00:14:41 this leads is 1, -2, 1. 245 00:14:41 --> 00:14:44 That's the second difference. 246 00:14:44 --> 00:14:48 Very important to remember, the second difference of a function 247 00:14:48 --> 00:14:53 is the function, the value ahead, minus two of the 248 00:14:53 --> 00:14:56 center, plus one of the left. 249 00:14:56 --> 00:14:59 It's centered obviously, symmetric, right? 250 00:14:59 --> 00:15:02 Second differences are symmetric. 251 00:15:02 --> 00:15:07 And because I want a minus sign I want minus the second 252 00:15:07 --> 00:15:11 difference and that's why you see here -1, 2, -1 . 253 00:15:14 --> 00:15:18 Because I wanted positive twos there. 254 00:15:18 --> 00:15:18 Are you ok? 255 00:15:18 --> 00:15:24 This is the natural replacement for -U''. 256 00:15:26 --> 00:15:32 And I claim that this second difference is like the second 257 00:15:32 --> 00:15:34 derivative, of course. 258 00:15:34 --> 00:15:38 And why don't we just check some examples to see how like 259 00:15:38 --> 00:15:40 the second derivative it is. 260 00:15:40 --> 00:15:41 So I'm going to take the second difference or 261 00:15:41 --> 00:15:47 some easy functions. 262 00:15:47 --> 00:15:51 It's very important that these come out so well. 263 00:15:51 --> 00:15:54 So I'm going to take the second difference. 264 00:15:54 --> 00:15:56 I'm going to write it as sort of a matrix. 265 00:15:56 --> 00:15:58 So this is like the second different. 266 00:15:58 --> 00:16:02 Yeah, because this is good. 267 00:16:02 --> 00:16:04 I'm inside the region, here. 268 00:16:04 --> 00:16:07 I'm not worried about the boundaries now. 269 00:16:07 --> 00:16:09 Let me just think of myself as inside. 270 00:16:09 --> 00:16:14 So I have second differences and suppose I'm applying it 271 00:16:14 --> 00:16:18 to a vector of all ones. 272 00:16:18 --> 00:16:22 What answer should I get? 273 00:16:22 --> 00:16:28 So if I think of calculus it's the second derivative of one, 274 00:16:28 --> 00:16:30 of the constant function. 275 00:16:30 --> 00:16:32 So what answer am I going to get? 276 00:16:32 --> 00:16:33 Zero. 277 00:16:33 --> 00:16:34 And do I get zero? 278 00:16:34 --> 00:16:35 Of course. 279 00:16:35 --> 00:16:35 I get zero. 280 00:16:35 --> 00:16:36 Right? 281 00:16:36 --> 00:16:39 All these second differences are zero. 282 00:16:39 --> 00:16:43 Because I'm not worrying about the boundary yet. 283 00:16:43 --> 00:16:46 So that's like, check one. 284 00:16:46 --> 00:16:48 It passed that simple test. 285 00:16:48 --> 00:16:57 Now let me move up from constant to linear. 286 00:16:57 --> 00:16:58 And so on. 287 00:16:58 --> 00:17:01 So let me apply second differences to a vector 288 00:17:01 --> 00:17:04 that's growing linearly. 289 00:17:04 --> 00:17:08 What answer do I expect to get for that? 290 00:17:08 --> 00:17:11 So remember I'm doing second differences, like second 291 00:17:11 --> 00:17:16 derivatives, or minus second derivatives, actually. 292 00:17:16 --> 00:17:20 So what do second derivatives do to a linear function? 293 00:17:20 --> 00:17:23 If I take a straight line I take the-- sorry, 294 00:17:23 --> 00:17:25 second derivatives. 295 00:17:25 --> 00:17:29 If I take second derivatives of a linear function I get? 296 00:17:29 --> 00:17:30 Zero, right. 297 00:17:30 --> 00:17:34 So I would hope to get zero again here and I do. 298 00:17:34 --> 00:17:35 Right? 299 00:17:35 --> 00:17:36 -1+4-3=0. 300 00:17:38 --> 00:17:41 Minus one, sorry, let me do it here, -2+6-4. 301 00:17:44 --> 00:17:47 And actually, that's consistent with our little 302 00:17:47 --> 00:17:49 Taylor series stuff. 303 00:17:49 --> 00:17:52 The function x should come out right. 304 00:17:52 --> 00:17:55 Now what about-- now comes the moment. 305 00:17:55 --> 00:17:57 What about x squared? 306 00:17:57 --> 00:18:00 So I'm going to put squares in now. 307 00:18:00 --> 00:18:04 Do I expect to get zeroes? 308 00:18:04 --> 00:18:06 I don't think so. 309 00:18:06 --> 00:18:10 Because let me again test it by thinking about 310 00:18:10 --> 00:18:12 what second derivative. 311 00:18:12 --> 00:18:17 So now I'm sort of copying second derivative of 312 00:18:17 --> 00:18:20 x squared, which is? 313 00:18:20 --> 00:18:24 Second derivative of x squared is? 314 00:18:24 --> 00:18:25 Two, right? 315 00:18:25 --> 00:18:29 First derivative's 2x, second derivative is just two. 316 00:18:29 --> 00:18:31 So it's a constant. 317 00:18:31 --> 00:18:35 And remember I put in a minus sign so I'm wondering, do I 318 00:18:35 --> 00:18:39 get the answer minus two? 319 00:18:39 --> 00:18:41 All the way down. 320 00:18:42 --> 00:18:43 -4+8-9. 321 00:18:45 --> 00:18:47 Whoops. 322 00:18:47 --> 00:18:50 What's that? 323 00:18:50 --> 00:18:52 What do I get there? 324 00:18:52 --> 00:18:57 What do I get from that second difference of these squares? 325 00:18:57 --> 00:19:00 -4+8-9 is? 326 00:19:00 --> 00:19:03 Minus two, good. 327 00:19:03 --> 00:19:04 So can we keep going? 328 00:19:04 --> 00:19:05 -4+18-16. 329 00:19:08 --> 00:19:10 What's that? 330 00:19:10 --> 00:19:15 -4+18-16, so I've got -20+18 . 331 00:19:15 --> 00:19:19 332 00:19:19 --> 00:19:20 I got minus two again. 333 00:19:21 --> 00:19:24 -9, 32, -25, it's right. 334 00:19:24 --> 00:19:32 The second differences of the vector of squares, you could 335 00:19:32 --> 00:19:37 say, is a constant vector with the right number. 336 00:19:37 --> 00:19:39 And that's because that second difference is 337 00:19:39 --> 00:19:41 second order accurate. 338 00:19:41 --> 00:19:45 It not only got constants right and linears right, 339 00:19:45 --> 00:19:48 it got quadratics right. 340 00:19:48 --> 00:19:52 So that's, you're seeing second differences. 341 00:19:52 --> 00:19:57 We'll soon see that second differences are also on 342 00:19:57 --> 00:20:01 the ball when you apply them to other vectors. 343 00:20:01 --> 00:20:04 Like vectors of sines or vectors of cosines or 344 00:20:04 --> 00:20:08 exponentials, they do well. 345 00:20:08 --> 00:20:12 So that's just a useful check which will help us over here. 346 00:20:12 --> 00:20:17 Okay, can I come back to the part of the lecture now? 347 00:20:17 --> 00:20:23 Having prepared the way for this. 348 00:20:23 --> 00:20:25 Well, let's start right off by solving the 349 00:20:25 --> 00:20:29 differential equation. 350 00:20:29 --> 00:20:33 So I'm bringing you back years and years and years, right? 351 00:20:33 --> 00:20:37 Solve that differential equation with these two 352 00:20:37 --> 00:20:40 boundary conditions. 353 00:20:40 --> 00:20:42 How would you do that in a systematic way? 354 00:20:42 --> 00:20:47 You could almost guess after a while, but systematically if I 355 00:20:47 --> 00:20:51 have a linear, I notice-- What do I notice about this thing? 356 00:20:51 --> 00:20:53 It's linear. 357 00:20:53 --> 00:20:55 So what am I expecting? 358 00:20:55 --> 00:20:58 I'm expecting, like, a particular solution that gives 359 00:20:58 --> 00:21:06 the correct answer one and some null space solution or whatever 360 00:21:06 --> 00:21:11 I want to call it, homogenous solution that gives zero and 361 00:21:11 --> 00:21:13 has some arbitrary constants in it. 362 00:21:13 --> 00:21:15 Give me a particular solution. 363 00:21:15 --> 00:21:18 So this is going to be our answer. 364 00:21:18 --> 00:21:23 This'll be the general solution to this differential equation. 365 00:21:23 --> 00:21:27 What functions have minus the second derivative equal 366 00:21:27 --> 00:21:28 one, that's all I'm asking. 367 00:21:28 --> 00:21:30 What are they? 368 00:21:30 --> 00:21:33 So what is one of them? 369 00:21:33 --> 00:21:38 One function that has its second derivative as a constant 370 00:21:38 --> 00:21:41 and that constant is minus one. 371 00:21:41 --> 00:21:44 So if I want the second derivative to be a constant, 372 00:21:44 --> 00:21:47 what am I looking at? x squared. 373 00:21:47 --> 00:21:49 I'm looking at x squared. 374 00:21:49 --> 00:21:51 And I just want to figure out how many x 375 00:21:51 --> 00:21:53 squareds to get a one. 376 00:21:53 --> 00:21:58 So some number of x squareds and how many do I want? 377 00:21:58 --> 00:21:59 -1/2, good. 378 00:21:59 --> 00:22:01 Good. 379 00:22:01 --> 00:22:01 -1/2. 380 00:22:01 --> 00:22:05 Because x squared would give me two but I want minus 381 00:22:05 --> 00:22:07 one so I need -1/2. 382 00:22:07 --> 00:22:10 Okay that's the particular solution. 383 00:22:10 --> 00:22:18 Now throw in all the solutions, I can add in any solution that 384 00:22:18 --> 00:22:22 has a zero on the right side, so what functions have second 385 00:22:22 --> 00:22:30 derivatives equals zero? x is good. 386 00:22:30 --> 00:22:34 I'm looking for two because it's a second derivative, 387 00:22:34 --> 00:22:35 second order equation. 388 00:22:35 --> 00:22:37 What's the other guy? 389 00:22:37 --> 00:22:38 Constant, good. 390 00:22:38 --> 00:22:43 So let me put the constant first, C, say, and Dx. 391 00:22:43 --> 00:22:46 Two constants that I can play with and what use am 392 00:22:46 --> 00:22:49 I going to make of them? 393 00:22:49 --> 00:22:52 I'm going to use those to satisfy the two 394 00:22:52 --> 00:22:56 boundary conditions. 395 00:22:56 --> 00:22:59 And it won't be difficult. 396 00:22:59 --> 00:23:04 You could say plug in the first boundary condition, get an 397 00:23:04 --> 00:23:07 equation for the constants, plug in the second, got another 398 00:23:07 --> 00:23:09 equation, we'll have two boundary conditions, two 399 00:23:09 --> 00:23:11 equations, two constants. 400 00:23:11 --> 00:23:15 Everything's going to come out. 401 00:23:15 --> 00:23:22 So if I plug in U(0)=0, what do I learn? 402 00:23:22 --> 00:23:23 C is zero, right? 403 00:23:23 --> 00:23:25 If I plug in, is that right? 404 00:23:25 --> 00:23:28 If I plug in zero, then that's zero already, this 405 00:23:28 --> 00:23:32 is zero already, so I just learned that C is zero. 406 00:23:32 --> 00:23:36 So C is zero. 407 00:23:36 --> 00:23:42 So I'm down to one constant, one unused boundary condition. 408 00:23:42 --> 00:23:43 Plug that in. 409 00:23:43 --> 00:23:43 U(1)=-1/2. 410 00:23:48 --> 00:23:50 What's D? 411 00:23:50 --> 00:23:51 It's 1/2, right. 412 00:23:51 --> 00:23:54 D is 1/2. 413 00:23:54 --> 00:23:56 So can I close this up? 414 00:23:56 --> 00:23:58 There's 1/2. 415 00:23:58 --> 00:24:00 Dx is 1/2. 416 00:24:00 --> 00:24:03 Now it just always pays to look back. 417 00:24:03 --> 00:24:06 At x=0, that's obviously zero. 418 00:24:06 --> 00:24:11 At x=1 it's zero because those are the same and I get zero. 419 00:24:11 --> 00:24:14 So -1/2x squared plus 1/2x. 420 00:24:14 --> 00:24:19 421 00:24:19 --> 00:24:23 That's the kind of differential equation and solution 422 00:24:23 --> 00:24:25 that we're looking for. 423 00:24:25 --> 00:24:28 Not complicated nonlinear stuff. 424 00:24:28 --> 00:24:35 So now I'm ready to move to the difference equation. 425 00:24:35 --> 00:24:41 So again, this is a major step. 426 00:24:41 --> 00:24:46 I'll draw a picture of this from zero to one. 427 00:24:46 --> 00:24:51 And if I graph that I think I get a parabola, right? 428 00:24:51 --> 00:24:53 A parabola that has to go through here. 429 00:24:53 --> 00:24:56 So it's some parabola like that. 430 00:24:56 --> 00:25:01 That would be always good, to draw a graph of the solution. 431 00:25:01 --> 00:25:03 Now, what do I get here? 432 00:25:03 --> 00:25:06 Moving to the difference equation. 433 00:25:06 --> 00:25:09 So that's the equation, and notice it's 434 00:25:09 --> 00:25:12 boundary conditions. 435 00:25:12 --> 00:25:16 Those boundary conditions just copied this one because 436 00:25:16 --> 00:25:20 I've chopped this up. 437 00:25:20 --> 00:25:25 I've got i equal one, two, three, four, five and this 438 00:25:25 --> 00:25:32 is one, the last point then is 6h . h is 1/6. 439 00:25:32 --> 00:25:35 440 00:25:35 --> 00:25:38 What's going to be the size of my matrix and my vector 441 00:25:38 --> 00:25:41 and my unknown u here? 442 00:25:41 --> 00:25:43 How many unknowns am I going to have? 443 00:25:43 --> 00:25:46 Let's just get the overall picture right. 444 00:25:46 --> 00:25:47 What are the unknowns going to be? 445 00:25:47 --> 00:25:49 They're going to be u_1, u_2, u_3, u_4, u_5. 446 00:25:49 --> 00:25:51 447 00:25:51 --> 00:25:52 Those are unknown. 448 00:25:52 --> 00:25:56 Those will be some values, I don't know where, maybe 449 00:25:56 --> 00:25:59 something like this because they'll be sort of 450 00:25:59 --> 00:26:01 like that one. 451 00:26:01 --> 00:26:05 And this is not an unknown, u_6 , this is not an unknown, u_0 452 00:26:05 --> 00:26:08 , those are the ones we know. 453 00:26:08 --> 00:26:13 So this is what the solution to a difference 454 00:26:13 --> 00:26:15 equation looks like. 455 00:26:15 --> 00:26:18 It gives you a discreet set of unknowns. 456 00:26:18 --> 00:26:22 And then, of course MATLAB or any code could connect them up 457 00:26:22 --> 00:26:28 by straight lines and give you a function. 458 00:26:28 --> 00:26:33 But the heart of it is these five values. 459 00:26:33 --> 00:26:38 Okay, good. 460 00:26:38 --> 00:26:44 And those five values come from these equations. 461 00:26:44 --> 00:26:47 I'm introducing this subscript stuff but I won't need it all 462 00:26:47 --> 00:26:49 the time because you'll see the picture. 463 00:26:49 --> 00:26:56 This equation applies for i equal one up to five. 464 00:26:56 --> 00:27:01 Five inside points and then you notice how when i is one, this 465 00:27:01 --> 00:27:04 needs u_0 , but we know u_0. 466 00:27:04 --> 00:27:08 And when I is five, this needs u_6 , but we know u_6 . 467 00:27:08 --> 00:27:12 So it's a closed five by five system and it 468 00:27:12 --> 00:27:17 will be our matrix. 469 00:27:17 --> 00:27:21 That -1, 2, -1 is what sits on the matrix. 470 00:27:21 --> 00:27:25 When we close it with the two boundary conditions it chops 471 00:27:25 --> 00:27:30 off the zero column, you could say and chops off the six 472 00:27:30 --> 00:27:37 column and leaves us with a five by five problem and yeah. 473 00:27:37 --> 00:27:44 I guess this is a step not to jump past because it 474 00:27:44 --> 00:27:48 takes a little practice. 475 00:27:48 --> 00:27:51 You see I've written the same thing two ways. 476 00:27:51 --> 00:27:53 Let me write it a third way. 477 00:27:53 --> 00:27:55 Let me write it out clearly. 478 00:27:55 --> 00:27:59 So now here I'm going to complete this matrix with a two 479 00:27:59 --> 00:28:03 and a minus one and a two and a minus one and now 480 00:28:03 --> 00:28:05 it's five by five. 481 00:28:05 --> 00:28:10 And those might be u but I don't know if they are so 482 00:28:10 --> 00:28:18 let me put in u_1, u_2, u_3, u_4, and u_5. 483 00:28:18 --> 00:28:23 484 00:28:23 --> 00:28:26 Oh and divide by h squared. 485 00:28:26 --> 00:28:31 I'll often forget that. 486 00:28:31 --> 00:28:34 So I'm asking you to see something that if you haven't, 487 00:28:34 --> 00:28:38 after you get the hang of it it's like, automatic. 488 00:28:38 --> 00:28:40 But I have to remember it's not automatic. 489 00:28:40 --> 00:28:42 Things aren't automatic until you've done them 490 00:28:42 --> 00:28:43 a couple of times. 491 00:28:43 --> 00:28:53 So do you see that that is a concrete statement of this? 492 00:28:53 --> 00:28:56 This delta x squared is the h squared. 493 00:28:56 --> 00:29:00 And do you see those differences when I do that 494 00:29:00 --> 00:29:04 multiplication that they produce those differences? 495 00:29:04 --> 00:29:07 And now, what's my right-hand side? 496 00:29:07 --> 00:29:10 Well I've changed the right-hand side to 497 00:29:10 --> 00:29:12 one to make it easy. 498 00:29:12 --> 00:29:17 So this right-hand side is all ones. 499 00:29:17 --> 00:29:25 And this is the problem that MATLAB would solve 500 00:29:25 --> 00:29:27 or whatever code. 501 00:29:27 --> 00:29:30 Find a difference code. 502 00:29:30 --> 00:29:36 I've got to a linear system, five by five, it's fortunately, 503 00:29:36 --> 00:29:44 the matrix is not singular, there is a solution. 504 00:29:44 --> 00:29:45 How does MATLAB find it? 505 00:29:45 --> 00:29:50 It does not find it by finding the inverse of that matrix. 506 00:29:50 --> 00:29:55 Monday's lecture will quickly review how to solve five 507 00:29:55 --> 00:29:58 equations and five unknowns. 508 00:29:58 --> 00:30:02 It's by elimination, I'll tell you the key word. 509 00:30:02 --> 00:30:05 And that's what every code does. 510 00:30:05 --> 00:30:09 And sometimes you would have to exchange rows, but not for a 511 00:30:09 --> 00:30:10 positive definite matrix like that. 512 00:30:10 --> 00:30:13 It'll just go bzzz, right through. 513 00:30:13 --> 00:30:17 When it's tridiagonal it'll go like with the speed of light 514 00:30:17 --> 00:30:20 and you'll get the answer. 515 00:30:20 --> 00:30:23 And those five answers will be these five heights. u_1, 516 00:30:23 --> 00:30:23 u_2, u_3, u_4, and u_5. 517 00:30:23 --> 00:30:29 518 00:30:29 --> 00:30:31 And we could figure it out. 519 00:30:31 --> 00:30:36 Actually I think section 1.2 gives the formula for this 520 00:30:36 --> 00:30:42 particular model problem for any size, and particular 521 00:30:42 --> 00:30:44 for five by five. 522 00:30:44 --> 00:30:52 And there is something wonderful for this 523 00:30:52 --> 00:30:55 special case. 524 00:30:55 --> 00:31:00 The five points fall right on the correct parabola, 525 00:31:00 --> 00:31:01 they're exactly right. 526 00:31:01 --> 00:31:06 So for this particular case when the solution was a 527 00:31:06 --> 00:31:09 quadratic, the exact solution was a quadratic, a parabola, 528 00:31:09 --> 00:31:14 it will turn out, and that quadratic matches these 529 00:31:14 --> 00:31:21 boundary conditions, it will turn out that those points 530 00:31:21 --> 00:31:25 are right on the money. 531 00:31:25 --> 00:31:27 So that's, you could call, is like, super 532 00:31:27 --> 00:31:29 convergence or something. 533 00:31:29 --> 00:31:35 I mean that won't happen every time, otherwise life 534 00:31:35 --> 00:31:39 would be like, too easy. 535 00:31:39 --> 00:31:46 It's a good life, but it's not that good as a rule. 536 00:31:46 --> 00:31:56 So they fall right on that curve. 537 00:31:56 --> 00:31:59 And we can say what those numbers are. 538 00:31:59 --> 00:32:01 Actually, we know what they are. 539 00:32:01 --> 00:32:03 Actually, I guess I could find them. 540 00:32:03 --> 00:32:09 What are those numbers then? 541 00:32:09 --> 00:32:13 And of course, one over h squared is-- What's one over h 542 00:32:13 --> 00:32:16 squared, just to not forget? 543 00:32:16 --> 00:32:20 One over h squared there, h is what? 544 00:32:20 --> 00:32:22 1/6. 545 00:32:22 --> 00:32:24 Squared is going to be a 36. 546 00:32:24 --> 00:32:30 So if I bring it up here, bring the h squared up here, 547 00:32:30 --> 00:32:33 it would be times a 36. 548 00:32:33 --> 00:32:37 Well let me leave it here, 36. 549 00:32:37 --> 00:32:41 And I'm just saying that these numbers would come out right. 550 00:32:41 --> 00:32:42 Maybe I'll just do the first one. 551 00:32:42 --> 00:32:44 What's the exact u_1, u_2? 552 00:32:45 --> 00:32:48 u_1 and u_2 would be what? 553 00:32:48 --> 00:32:51 The exact u_1, ooh! 554 00:32:51 --> 00:32:53 Oh shoot, I've got to figure it out. 555 00:32:53 --> 00:32:55 If I plug in x=1/6... 556 00:32:55 --> 00:32:58 557 00:32:58 --> 00:33:04 Do we want to do this? 558 00:33:04 --> 00:33:04 Plug in x=1/6? 559 00:33:05 --> 00:33:08 No, we don't. 560 00:33:08 --> 00:33:08 We don't. 561 00:33:08 --> 00:33:11 We've got something better to do with our lives. 562 00:33:11 --> 00:33:15 But if we put that number in, whatever the heck it is, in 563 00:33:15 --> 00:33:19 this one, we would find out came out right. 564 00:33:19 --> 00:33:22 The fact that it comes out right is important. 565 00:33:22 --> 00:33:34 But I'd like to move on to a similar problem. 566 00:33:34 --> 00:33:38 But this one is going to be free-fixed. 567 00:33:38 --> 00:33:44 So if this problem was like having an elastic bar hanging 568 00:33:44 --> 00:33:49 under its own weight and these would be the displacements 569 00:33:49 --> 00:33:54 points on the bar and fixed at the ends, now I'm 570 00:33:54 --> 00:33:56 freeing up the top end. 571 00:33:56 --> 00:34:02 I'm not making u_0, zero anymore. 572 00:34:02 --> 00:34:07 I better maybe use a different blackboard because that's so 573 00:34:07 --> 00:34:12 important that I don't want to erase it. 574 00:34:12 --> 00:34:18 So let me take the same problem, uniform bar, uniform 575 00:34:18 --> 00:34:27 load, but I'm going to fix U over one, that's fixed, but 576 00:34:27 --> 00:34:30 I'm going to free this end. 577 00:34:30 --> 00:34:32 And from a differential equation point of view, that 578 00:34:32 --> 00:34:39 means I'm going to set the slope at zero to be zero. 579 00:34:39 --> 00:34:39 U'(0)=0. 580 00:34:39 --> 00:34:44 581 00:34:44 --> 00:34:48 That's going to have a different solution. 582 00:34:48 --> 00:34:51 Change the boundary conditions is going to change the answer. 583 00:34:51 --> 00:34:52 Let's find the solution. 584 00:34:52 --> 00:34:56 So here's another differential equation. 585 00:34:56 --> 00:34:58 Same equation, different boundary conditions, 586 00:34:58 --> 00:35:00 so how do we go? 587 00:35:00 --> 00:35:04 Well I had the general solution over there. 588 00:35:04 --> 00:35:05 It still works, right? 589 00:35:05 --> 00:35:10 U(x) is still -1/2 of x squared. 590 00:35:10 --> 00:35:13 The particular solution that gives me the one. 591 00:35:13 --> 00:35:19 Plus the Cx plus D that gives me zero, one, zero for second 592 00:35:19 --> 00:35:24 derivatives but gives me the possibility to satisfy the 593 00:35:24 --> 00:35:27 two boundary conditions. 594 00:35:27 --> 00:35:29 And now again, plug in the boundary conditions 595 00:35:29 --> 00:35:33 to find C and D. 596 00:35:33 --> 00:35:35 Slope is zero at zero. 597 00:35:35 --> 00:35:37 What does that tell me? 598 00:35:37 --> 00:35:39 I have to plug that in. 599 00:35:39 --> 00:35:43 Here's my solution, I have to take it's derivative 600 00:35:43 --> 00:35:46 and set x to zero. 601 00:35:46 --> 00:35:50 So it's derivative is a 2x or a minus x or 602 00:35:50 --> 00:35:53 something which is zero. 603 00:35:53 --> 00:36:00 The derivative of that is C and the derivative of that is zero. 604 00:36:00 --> 00:36:03 What am I learning from that left, the free 605 00:36:03 --> 00:36:06 boundary condition? 606 00:36:06 --> 00:36:08 C is zero, right? 607 00:36:08 --> 00:36:12 C is zero because the slope here is C and it's 608 00:36:12 --> 00:36:12 supposed to be zero. 609 00:36:12 --> 00:36:16 So C is zero. 610 00:36:16 --> 00:36:19 Now the other boundary condition. 611 00:36:19 --> 00:36:21 Plug in x=1. 612 00:36:21 --> 00:36:24 I want to get the answer zero. 613 00:36:24 --> 00:36:27 The answer I do get is minus 1/2 at x=1 , plus D . 614 00:36:28 --> 00:36:32 So what is D then? 615 00:36:32 --> 00:36:33 What's D? 616 00:36:33 --> 00:36:36 Let me raise that. 617 00:36:36 --> 00:36:40 What do I learn about D? 618 00:36:40 --> 00:36:43 It's 1/2. 619 00:36:43 --> 00:36:45 I need 1/2. 620 00:36:45 --> 00:36:57 So the answer is -1/2 of x squared plus 1/2. 621 00:36:57 --> 00:37:04 Not 1/2x as it was over there, but 1/2. 622 00:37:04 --> 00:37:06 And now let's graph it. 623 00:37:06 --> 00:37:08 Always pays to graph these things between x 624 00:37:08 --> 00:37:12 equals zero and one. 625 00:37:12 --> 00:37:15 What does this looks like? 626 00:37:15 --> 00:37:17 It starts at 1/2, right? 627 00:37:17 --> 00:37:18 At x=0. 628 00:37:19 --> 00:37:21 And it's a parabola, right? 629 00:37:21 --> 00:37:22 It's a parabola. 630 00:37:22 --> 00:37:24 And I know it goes through this point. 631 00:37:24 --> 00:37:28 What else do I know? 632 00:37:28 --> 00:37:32 Slope starts at? 633 00:37:32 --> 00:37:33 The slope starts to zero. 634 00:37:33 --> 00:37:36 The other, the boundary condition, the free condition 635 00:37:36 --> 00:37:40 at the left-hand end, so slope starts at zero, so the parabola 636 00:37:40 --> 00:37:42 comes down like that. 637 00:37:42 --> 00:37:46 It's like half a-- where that was a symmetric bit of a 638 00:37:46 --> 00:37:51 parabola, this is just half of it. 639 00:37:51 --> 00:37:56 The slope is zero. 640 00:37:56 --> 00:38:00 And so that's a graph of U(x) . 641 00:38:00 --> 00:38:07 Now I'm ready to replace it by a difference equation. 642 00:38:07 --> 00:38:09 So what'll be the difference equation? 643 00:38:09 --> 00:38:13 It'll be the same equation for the -u''. 644 00:38:13 --> 00:38:16 No change. 645 00:38:16 --> 00:38:23 So minus u_(i+1) minus 2u_i , minus u_(i-1) 646 00:38:23 --> 00:38:28 over h squared equals. 647 00:38:28 --> 00:38:34 I'm taking f(x) to be one, so let's stay with one. 648 00:38:34 --> 00:38:38 Okay, big moment. 649 00:38:38 --> 00:38:40 What boundary conditions? 650 00:38:40 --> 00:38:42 What boundary conditions? 651 00:38:42 --> 00:38:45 Well, this guy is pretty clear. 652 00:38:45 --> 00:38:51 That says u_(n+1) is zero. 653 00:38:51 --> 00:38:55 What do I do for zero slope? 654 00:38:55 --> 00:38:57 What do I do for a zero slope? 655 00:38:57 --> 00:39:00 Okay, let me suggest one possibility. 656 00:39:00 --> 00:39:04 It's not the greatest, but one possibility for a zero 657 00:39:04 --> 00:39:06 slope is (u_1-u_0)/h . 658 00:39:06 --> 00:39:08 659 00:39:08 --> 00:39:14 That's the approximate slope, should be zero. 660 00:39:14 --> 00:39:21 So that's my choice for the left-hand boundary condition. 661 00:39:21 --> 00:39:24 It says u_1 is u_0 . 662 00:39:24 --> 00:39:28 It says that u_1 is u_0 . 663 00:39:28 --> 00:39:39 So now I've got again five equations for five unknowns, 664 00:39:39 --> 00:39:39 u_1, u_2, u_3, u_4, and u_5. 665 00:39:39 --> 00:39:44 666 00:39:44 --> 00:39:46 I'll write down what they are. 667 00:39:46 --> 00:39:49 Well, you know what they are. 668 00:39:49 --> 00:39:56 So this thing divided by h squared is all ones, 669 00:39:56 --> 00:39:57 just like before. 670 00:39:57 --> 00:40:05 And of course all these rows are not changed. 671 00:40:05 --> 00:40:07 But the first row is changed because we have a new boundary 672 00:40:07 --> 00:40:09 condition at the left end. 673 00:40:09 --> 00:40:11 And it's this. 674 00:40:11 --> 00:40:17 So u_1, well u_0 isn't in the picture, but previously what 675 00:40:17 --> 00:40:22 happened to u_0 , when i is one, I'm in the first equation 676 00:40:22 --> 00:40:24 here, that's where I'm looking. i is one. 677 00:40:24 --> 00:40:25 It had a u_0. 678 00:40:26 --> 00:40:28 Gone. 679 00:40:28 --> 00:40:34 In this case it's not gone. u_0 comes back in, u_0 is u_1. 680 00:40:34 --> 00:40:36 That might-- Ooh! 681 00:40:36 --> 00:40:38 Don't let me do this wrong. 682 00:40:38 --> 00:40:38 Ah! 683 00:40:38 --> 00:40:42 Don't let me do it worse! 684 00:40:42 --> 00:40:43 All right. 685 00:40:43 --> 00:40:43 There we go. 686 00:40:43 --> 00:40:44 Good. 687 00:40:44 --> 00:40:47 Okay. 688 00:40:47 --> 00:40:53 Please, last time I videotaped lecture 10 had to fix up 689 00:40:53 --> 00:40:56 lecture 9, because I don't go in. 690 00:40:56 --> 00:41:00 Professor Lewin in the physics lectures, he cheats, doesn't 691 00:41:00 --> 00:41:03 cheat, but he goes into the lectures afterwards 692 00:41:03 --> 00:41:05 and fixes them. 693 00:41:05 --> 00:41:10 But you get exactly what it looks like. 694 00:41:10 --> 00:41:13 So now it's fixed, I hope. 695 00:41:13 --> 00:41:16 But don't let me screw up. 696 00:41:16 --> 00:41:22 So now, what's on this top row? 697 00:41:22 --> 00:41:23 When i is one. 698 00:41:23 --> 00:41:26 I have minus u_2, that's fine. 699 00:41:26 --> 00:41:32 I have 2u_1 as before, but now I have a minus u_1 because 700 00:41:32 --> 00:41:34 u_0 and u_1 are the same. 701 00:41:34 --> 00:41:37 So I just have a one in there. 702 00:41:37 --> 00:41:40 That's our matrix that we called T. 703 00:41:40 --> 00:41:44 The top row is changed, the top row is free. 704 00:41:44 --> 00:41:49 This is the equation T * U divided by h squared is 705 00:41:49 --> 00:41:52 the right-hand side ones. 706 00:41:52 --> 00:41:57 Ones of five, would call that. 707 00:41:57 --> 00:42:01 Properly I would call it ones of five one, because the MATLAB 708 00:42:01 --> 00:42:06 command ones wants matrix and it's a matrix with five 709 00:42:06 --> 00:42:08 rows, one column. 710 00:42:08 --> 00:42:12 But it's T, that's the important thing. 711 00:42:12 --> 00:42:20 And would you like to guess what the solution looks like? 712 00:42:20 --> 00:42:25 In particular, is it again exactly right? 713 00:42:25 --> 00:42:29 Is it right on the money? 714 00:42:29 --> 00:42:35 Or if not, why not? 715 00:42:35 --> 00:42:38 The computer will tell us, of course. 716 00:42:38 --> 00:42:41 It will tell us whether we get agreement with this. 717 00:42:41 --> 00:42:48 This is the exact solution here and this is the exact parabola 718 00:42:48 --> 00:42:51 starting with zero slope. 719 00:42:51 --> 00:42:54 So but I solved this problem. 720 00:42:54 --> 00:42:58 Oh, let me see, I didn't get u_1, u_2 to u_5 in there. 721 00:42:58 --> 00:43:00 So it didn't look right. u_1, u_2, u_3, u_4, and u_5. 722 00:43:00 --> 00:43:04 723 00:43:04 --> 00:43:06 And that's the right-hand side. 724 00:43:06 --> 00:43:08 Sorry about that. 725 00:43:08 --> 00:43:13 So that's T divided by h squared, T with that top 726 00:43:13 --> 00:43:19 row changed times U is the right-hand side. 727 00:43:19 --> 00:43:25 By the way, I better just say what was the reason that we 728 00:43:25 --> 00:43:30 came out exactly right on this problem? 729 00:43:30 --> 00:43:34 Would we come out exactly right if it was some 730 00:43:34 --> 00:43:36 general load f(x) ? 731 00:43:36 --> 00:43:38 No. 732 00:43:38 --> 00:43:42 Finding differences can't do miracles. 733 00:43:42 --> 00:43:45 They have no way to know what's happening to f(x) between 734 00:43:45 --> 00:43:47 the mesh points, right? 735 00:43:47 --> 00:43:52 If I took this to be f(x) and took this at the five points, 736 00:43:52 --> 00:43:57 at these five points, this wouldn't know what f(x) is in 737 00:43:57 --> 00:44:00 between, couldn't be exactly right. 738 00:44:00 --> 00:44:07 It's exactly right in this lucky special case because, of 739 00:44:07 --> 00:44:11 course, it has the right ones. 740 00:44:11 --> 00:44:15 But also because, the reason it's exactly right is that 741 00:44:15 --> 00:44:19 second differences of quadratics are exactly right. 742 00:44:19 --> 00:44:24 That's what we checked on this board that's underneath there. 743 00:44:24 --> 00:44:29 Second differences of squares came out perfectly. 744 00:44:29 --> 00:44:34 And that's why the second differences of this guy give 745 00:44:34 --> 00:44:40 the right answer, so that guy is the answer to both the 746 00:44:40 --> 00:44:43 differential and the difference equation. 747 00:44:43 --> 00:44:46 I had to say that word about why was that exactly right. 748 00:44:46 --> 00:44:48 It was exactly right because second differences of 749 00:44:48 --> 00:44:50 squares are exactly right. 750 00:44:50 --> 00:44:53 Now, again, we have second differences of squares. 751 00:44:53 --> 00:44:58 So you could say exactly right or no? 752 00:44:58 --> 00:44:58 What are you betting? 753 00:44:58 --> 00:45:00 How many think, yeah, it's going to come 754 00:45:00 --> 00:45:03 out on the parabola? 755 00:45:03 --> 00:45:04 Nobody. 756 00:45:04 --> 00:45:06 Right. 757 00:45:06 --> 00:45:10 Everybody thinks there's something going to miss here. 758 00:45:10 --> 00:45:11 And why? 759 00:45:11 --> 00:45:14 Why am I going to miss something? 760 00:45:14 --> 00:45:17 Yes? 761 00:45:17 --> 00:45:19 It's a first order approximation at 762 00:45:19 --> 00:45:20 the left boundary. 763 00:45:20 --> 00:45:22 Exactly right, exactly right. 764 00:45:22 --> 00:45:27 It's a first order approximation to take this and 765 00:45:27 --> 00:45:29 I'm not going to get it right. 766 00:45:29 --> 00:45:33 That first order approximation, that error of size h is 767 00:45:33 --> 00:45:39 going to penetrate over the whole interval. 768 00:45:39 --> 00:45:40 It'll be biggest here. 769 00:45:40 --> 00:45:43 Actually I think it turns out, and the book has a graph, 770 00:45:43 --> 00:45:47 I think it comes out wrong by 1/2h there. 771 00:45:47 --> 00:45:49 1/2h, first order. 772 00:45:49 --> 00:45:54 And then it, of course, it's discrete and of course it's 773 00:45:54 --> 00:45:57 straight across because that's the boundary condition, right? 774 00:45:57 --> 00:46:02 And then it starts down, it gets sort of closer, closer, 775 00:46:02 --> 00:46:06 closer and gets, of course, that's right at the end. 776 00:46:06 --> 00:46:08 But there's an error. 777 00:46:08 --> 00:46:13 The difference between U, the true U and the 778 00:46:13 --> 00:46:22 computed U is of order h. 779 00:46:22 --> 00:46:28 So you could say alright, if h is small I can live with that. 780 00:46:28 --> 00:46:33 But as I said in the end you really want to get second 781 00:46:33 --> 00:46:34 order accuracy if you can. 782 00:46:34 --> 00:46:36 And in a simple problem like this we should 783 00:46:36 --> 00:46:39 be able to do it. 784 00:46:39 --> 00:46:46 What I've done already covers section 1.2 but then there's a 785 00:46:46 --> 00:46:52 note, a worked example at the end of 1.2 that tells you how 786 00:46:52 --> 00:46:56 to upgrade to second order. 787 00:46:56 --> 00:47:00 And maybe we've got a moment to see how would we do it. 788 00:47:00 --> 00:47:04 What would you suggest that I do differently? 789 00:47:04 --> 00:47:07 I'll get a different matrix. 790 00:47:07 --> 00:47:09 I'll get a different discrete problem. 791 00:47:09 --> 00:47:10 But that'll be ok. 792 00:47:10 --> 00:47:12 I can solve that just as well. 793 00:47:12 --> 00:47:17 And what shall I replace that by? because that was the 794 00:47:17 --> 00:47:19 guilty party, as you said. 795 00:47:19 --> 00:47:21 That was guilty. 796 00:47:21 --> 00:47:23 That's only a first order approximation to 797 00:47:23 --> 00:47:28 zero slope at zero. 798 00:47:28 --> 00:47:30 A couple of ways we could go. 799 00:47:30 --> 00:47:33 This is a correct second order approximation 800 00:47:33 --> 00:47:38 at what mesh point? 801 00:47:38 --> 00:47:44 That is a correct second order approximation to U'=0, but not 802 00:47:44 --> 00:47:48 at that point or at that point where? 803 00:47:48 --> 00:47:50 Halfway between. 804 00:47:50 --> 00:47:53 If I was looking at a point halfway between that, that 805 00:47:53 --> 00:47:56 would be centered there, that would be a centered difference 806 00:47:56 --> 00:47:57 and it would be good. 807 00:47:57 --> 00:48:00 But we're not looking there. 808 00:48:00 --> 00:48:02 So I'm looking here. 809 00:48:02 --> 00:48:06 So what do you suggest I do? 810 00:48:06 --> 00:48:10 Well I've got to center it. 811 00:48:10 --> 00:48:15 Essentially I'm going to use U, minus one. 812 00:48:15 --> 00:48:17 I'm going to use U, minus one. 813 00:48:17 --> 00:48:23 And let me just say what the effect is. 814 00:48:23 --> 00:48:27 You remember we started with the usual second difference 815 00:48:27 --> 00:48:31 here, 2, -1, -1. 816 00:48:31 --> 00:48:34 This is what got chopped off for the fixed method. 817 00:48:34 --> 00:48:37 It got brought back here by our first order method. 818 00:48:37 --> 00:48:42 Our second order method will-- You see what's 819 00:48:42 --> 00:48:43 likely to happen? 820 00:48:43 --> 00:48:48 That -1 is going to show up where? 821 00:48:48 --> 00:48:50 Over here. 822 00:48:50 --> 00:48:52 To center it around zero. 823 00:48:52 --> 00:48:59 So that guy will make this into a minus two. 824 00:48:59 --> 00:49:03 Now that matrix is still fine. 825 00:49:03 --> 00:49:07 It's not one of our special matrices. 826 00:49:07 --> 00:49:10 When I say fine, it's not beautiful is it? 827 00:49:10 --> 00:49:18 It's got one, like, flaw, it needs what do you call it when 828 00:49:18 --> 00:49:22 you have your face-- cosmetic surgery or something. 829 00:49:22 --> 00:49:25 It needs a small improvement. 830 00:49:25 --> 00:49:27 So what's the matter with it? 831 00:49:27 --> 00:49:30 It's not symmetric. 832 00:49:30 --> 00:49:34 It's not symmetric and a person isn't happy with a un-symmetric 833 00:49:34 --> 00:49:38 problem, approximation to a perfectly symmetric thing. 834 00:49:38 --> 00:49:41 So I could just divide that row by two. 835 00:49:41 --> 00:49:45 If I divide that row by 2, which you won't mind if I do 836 00:49:45 --> 00:49:50 that, make that one, minus one and makes this 1/2. 837 00:49:50 --> 00:49:55 I divided the first equation by two. 838 00:49:55 --> 00:50:02 Look in the notes in the text if you can. 839 00:50:02 --> 00:50:05 And the result is now it's right on. 840 00:50:05 --> 00:50:07 It's exactly on. 841 00:50:07 --> 00:50:12 Because again, the solution, the true solution is squares. 842 00:50:12 --> 00:50:17 This is now second order and we'll get it exactly right. 843 00:50:17 --> 00:50:21 And I say all this for two reasons. 844 00:50:21 --> 00:50:25 One is to emphasize again that the boundary conditions are 845 00:50:25 --> 00:50:30 critical and that they penetrate into the region. 846 00:50:30 --> 00:50:34 The second reason for my saying this is looking forward 847 00:50:34 --> 00:50:37 way into October. 848 00:50:37 --> 00:50:42 So let me just say the finite element method, which you may 849 00:50:42 --> 00:50:45 know a little about, you may have heard about, it's 850 00:50:45 --> 00:50:48 another-- this was finite differences. 851 00:50:48 --> 00:50:51 Courses starting with finite differences, because that's 852 00:50:51 --> 00:50:52 the most direct way. 853 00:50:52 --> 00:50:53 You just go for it. 854 00:50:53 --> 00:50:57 You've got derivatives, you replace them by differences. 855 00:50:57 --> 00:51:07 But another approach which turns out to be great for big 856 00:51:07 --> 00:51:13 codes and also turns out to be great for making, for keeping 857 00:51:13 --> 00:51:16 the properties of the problem, the finite element method, 858 00:51:16 --> 00:51:22 you'll see it, it's weeks away, but when it comes, notice, the 859 00:51:22 --> 00:51:25 finite element method automatically produces 860 00:51:25 --> 00:51:27 that first equation. 861 00:51:27 --> 00:51:29 Automatically gets it right. 862 00:51:29 --> 00:51:33 So that's pretty special. 863 00:51:33 --> 00:51:37 And so, the finite element method just has, it produces 864 00:51:37 --> 00:51:44 that second order accuracy that we didn't get automatically 865 00:51:44 --> 00:51:48 for finite differences. 866 00:51:48 --> 00:51:52 Ok, questions on today or on the homework. 867 00:51:52 --> 00:51:55 So the homework is really wide open. 868 00:51:55 --> 00:51:59 It's really just a chance to start to see. 869 00:51:59 --> 00:52:03 I mean, the real homework is read those two sections of the 870 00:52:03 --> 00:52:09 book to capture what these two lectures have done. 871 00:52:09 --> 00:52:11 So Monday I'll see. 872 00:52:11 --> 00:52:13 We'll do elimination. 873 00:52:13 --> 00:52:17 We'll solve these equations quickly and then move on 874 00:52:17 --> 00:52:21 to the inverse matrix. 875 00:52:21 --> 00:52:25 More understanding of these problems. 876 00:52:25 --> 00:52:26 Thanks.