1 00:00:00,030 --> 00:00:02,400 The following content is provided under a Creative 2 00:00:02,400 --> 00:00:03,780 Commons license. 3 00:00:03,780 --> 00:00:06,020 Your support will help MIT OpenCourseWare 4 00:00:06,020 --> 00:00:10,100 continue to offer high quality educational resources for free. 5 00:00:10,100 --> 00:00:12,670 To make a donation or to view additional materials 6 00:00:12,670 --> 00:00:16,580 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:16,580 --> 00:00:17,235 at ocw.mit.edu. 8 00:00:26,246 --> 00:00:28,340 PROFESSOR: All right, let's get started. 9 00:00:31,150 --> 00:00:34,210 So here, as I said, I assume that everybody [INAUDIBLE] 10 00:00:34,210 --> 00:00:36,760 has already done the reading. 11 00:00:36,760 --> 00:00:40,390 OK, what I'm going to do today is not 12 00:00:40,390 --> 00:00:45,060 [INAUDIBLE] repeat any of the things you have already read. 13 00:00:45,060 --> 00:00:48,690 But I also don't assume you already mastered 14 00:00:48,690 --> 00:00:51,330 all the material [INAUDIBLE]. 15 00:00:51,330 --> 00:00:54,890 So what I'm going to do is kind of [INAUDIBLE] 16 00:00:54,890 --> 00:00:58,677 to give you a view of more or less the same material, maybe 17 00:00:58,677 --> 00:00:59,790 a little bit more. 18 00:00:59,790 --> 00:01:03,564 But from a slightly different angle. 19 00:01:03,564 --> 00:01:05,825 And which means we are going to [INAUDIBLE] 20 00:01:05,825 --> 00:01:11,801 but like [INAUDIBLE] may look like this one. 21 00:01:11,801 --> 00:01:15,600 The syntax may be different and may denote things 22 00:01:15,600 --> 00:01:16,940 with a different symbol. 23 00:01:16,940 --> 00:01:19,290 But, like, any [INAUDIBLE] is the same 24 00:01:19,290 --> 00:01:22,840 and you should be able to read the style. 25 00:01:22,840 --> 00:01:26,420 You should read what I'm going to be writing. 26 00:01:26,420 --> 00:01:28,120 And in addition to that, I'm going 27 00:01:28,120 --> 00:01:31,820 to ask you to work out some problems for yourself 28 00:01:31,820 --> 00:01:35,725 or actually in teams based on what you read 29 00:01:35,725 --> 00:01:38,568 and what I'm going to be discussing today. 30 00:01:38,568 --> 00:01:40,746 So I brought these things. 31 00:01:40,746 --> 00:01:43,142 I'm going to be actually [INAUDIBLE]. 32 00:01:48,070 --> 00:01:50,781 And I also brought [INAUDIBLE] each of you 33 00:01:50,781 --> 00:01:52,280 are going to be working [INAUDIBLE]. 34 00:02:00,270 --> 00:02:06,000 OK, and [INAUDIBLE] say which is the most active [INAUDIBLE]. 35 00:02:06,000 --> 00:02:12,400 OK, to start this, I'm going to be-- wait, OK. 36 00:02:12,400 --> 00:02:14,560 I'm going to be briefly reviewing 37 00:02:14,560 --> 00:02:17,890 what you read, which is how to basically write the function. 38 00:02:17,890 --> 00:02:20,890 And then in addition to writing down formulas, 39 00:02:20,890 --> 00:02:24,970 I'm going to be demonstrating things in MATLAB, OK? 40 00:02:24,970 --> 00:02:29,120 Discretize a function-- let's start with a function 41 00:02:29,120 --> 00:02:34,930 that, like, most of you very commonly see [INAUDIBLE] ODEs. 42 00:02:34,930 --> 00:02:39,984 When you write down f-- let me change to a different color. 43 00:02:44,630 --> 00:02:49,800 OK, if you write down F of T equal to E to the minus lambda 44 00:02:49,800 --> 00:02:56,880 T-- OK, can somebody tell me why this function is commonly ODEs? 45 00:02:56,880 --> 00:02:59,290 It's a solution to essentially the simplest 46 00:02:59,290 --> 00:03:06,805 ODE you can find in the world-- df dt equal to what? 47 00:03:06,805 --> 00:03:08,740 AUDIENCE: [INAUDIBLE] 48 00:03:08,740 --> 00:03:12,820 PROFESSOR: Minus lambda times f of t, right? 49 00:03:12,820 --> 00:03:16,090 So if I solve this ordinary differential equation, 50 00:03:16,090 --> 00:03:19,990 I'm going to get this function. 51 00:03:19,990 --> 00:03:24,305 OK, if I draw the function, if I draw this function 52 00:03:24,305 --> 00:03:29,120 as a function of time, at t equal to 0, 53 00:03:29,120 --> 00:03:31,940 the function has a value of 1, right? 54 00:03:31,940 --> 00:03:34,620 This is f of t, this is t. 55 00:03:34,620 --> 00:03:37,155 And how does the function look like for positive lambda? 56 00:03:40,240 --> 00:03:42,380 It's going to decay exponentially. 57 00:03:42,380 --> 00:03:47,160 That is what we call exponential decay to the minus lambda t, 58 00:03:47,160 --> 00:03:48,600 right? 59 00:03:48,600 --> 00:03:52,000 OK, this function is a function. 60 00:03:52,000 --> 00:03:53,690 It is a continuous function, which 61 00:03:53,690 --> 00:03:57,700 means it is, in some sense, infinite dimensional. 62 00:03:57,700 --> 00:04:03,090 You need infinitely many numbers or infinitely much memory 63 00:04:03,090 --> 00:04:06,770 to memorize this function in a computer, right? 64 00:04:06,770 --> 00:04:09,900 Because for every t, every single t, 65 00:04:09,900 --> 00:04:13,910 you have a function value f of p. 66 00:04:13,910 --> 00:04:16,700 But computers have finite memory, 67 00:04:16,700 --> 00:04:20,040 although we have a lot of memory, but still finite. 68 00:04:20,040 --> 00:04:22,460 So we need to find a way to represent 69 00:04:22,460 --> 00:04:27,540 this function using a finite number of bits in a computer. 70 00:04:27,540 --> 00:04:28,531 How do we do that? 71 00:04:31,360 --> 00:04:33,910 OK, we do that by first selecting a range. 72 00:04:33,910 --> 00:04:37,130 We cannot discretize the function for infinite t. 73 00:04:37,130 --> 00:04:43,070 We have to select a range and let's say from 0 to some big t. 74 00:04:43,070 --> 00:04:45,910 Is that enough? 75 00:04:45,910 --> 00:04:51,260 No we also need to discretize this interval into small time 76 00:04:51,260 --> 00:04:52,600 steps. 77 00:04:52,600 --> 00:04:56,420 And the first time step is usually just 0. 78 00:04:56,420 --> 00:05:03,360 The second time step is delta t and the 2 delta t, 3 delta t, 79 00:05:03,360 --> 00:05:05,690 4 delta t, et cetera. 80 00:05:05,690 --> 00:05:09,800 And at t is the last time step. 81 00:05:09,800 --> 00:05:12,280 All right, so this discretization, 82 00:05:12,280 --> 00:05:14,590 when I do this thing in MATLAB-- let 83 00:05:14,590 --> 00:05:16,674 me actually start up MATLAB. 84 00:05:16,674 --> 00:05:19,610 And when I do it in MATLAB, it is usually 85 00:05:19,610 --> 00:05:22,420 how we actually draw the function in MATLAB, right? 86 00:05:22,420 --> 00:05:24,330 I believe a lot of you have done this before 87 00:05:24,330 --> 00:05:26,220 in some other classes. 88 00:05:26,220 --> 00:05:29,330 Here, I'm just trying to warm you up and get 89 00:05:29,330 --> 00:05:32,310 you, if you're not familiar, get you familiar 90 00:05:32,310 --> 00:05:36,610 again with how do we do things in computer. 91 00:05:36,610 --> 00:05:39,020 I think I started MATLAB. 92 00:05:39,020 --> 00:05:40,390 Right, so OK. 93 00:05:40,390 --> 00:05:43,750 So let me set a big T equal to 5. 94 00:05:43,750 --> 00:05:44,740 You see this? 95 00:05:44,740 --> 00:05:48,460 Is it big enough? 96 00:05:48,460 --> 00:05:51,040 Shall I change it to a little bit bigger? 97 00:05:51,040 --> 00:05:53,970 Anybody want it bigger? 98 00:05:53,970 --> 00:05:54,670 No? 99 00:05:54,670 --> 00:05:55,170 Good? 100 00:05:55,170 --> 00:05:57,050 OK. 101 00:05:57,050 --> 00:05:59,810 What [INAUDIBLE] do you want? 102 00:05:59,810 --> 00:06:00,778 What one? 103 00:06:00,778 --> 00:06:04,046 Good, OK. 104 00:06:04,046 --> 00:06:08,370 And what I want-- how I discretize the time is t 105 00:06:08,370 --> 00:06:13,010 equal 0 dt t, all right? 106 00:06:13,010 --> 00:06:16,330 This is going to give me a t 1 by 51 double. 107 00:06:16,330 --> 00:06:18,530 So if I click on it, it is going to show 108 00:06:18,530 --> 00:06:20,600 that the first one is 0, the second one 109 00:06:20,600 --> 00:06:22,260 is 0.1, et cetera, et cetera. 110 00:06:22,260 --> 00:06:30,780 And the last one should be-- whoops-- is 5, all right? 111 00:06:30,780 --> 00:06:33,230 And now the function value f of t 112 00:06:33,230 --> 00:06:37,660 is equal to any set of lambda of equal to 1, OK? 113 00:06:37,660 --> 00:06:39,540 Lambda equal to 1. 114 00:06:39,540 --> 00:06:42,720 And then my function value is equal to exponential 115 00:06:42,720 --> 00:06:45,830 of minus lambda times t. 116 00:06:45,830 --> 00:06:48,620 So that way, I computed discretized version 117 00:06:48,620 --> 00:06:51,560 of the function f. 118 00:06:51,560 --> 00:06:53,850 How would I show the function? 119 00:06:53,850 --> 00:06:57,120 I can go to plot and to do this plot. 120 00:06:57,120 --> 00:06:59,680 Like here, I'm just going to use the command line 121 00:06:59,680 --> 00:07:04,230 version to log t and f. 122 00:07:04,230 --> 00:07:08,200 Yeah, this gives us exactly the function we expect, right? 123 00:07:08,200 --> 00:07:10,350 Exponentially decaying function. 124 00:07:12,970 --> 00:07:19,550 And I would actually also prefer to plot this and look at what 125 00:07:19,550 --> 00:07:21,900 kind of discretization it is. 126 00:07:21,900 --> 00:07:24,860 So if I plot this function with a dash and the o, 127 00:07:24,860 --> 00:07:29,560 it is going to display a circle at every discretized point 128 00:07:29,560 --> 00:07:33,430 so that we are going to see that this function is actually 129 00:07:33,430 --> 00:07:34,760 a discretized function. 130 00:07:34,760 --> 00:07:36,880 It is not a continuous. 131 00:07:36,880 --> 00:07:39,640 In MATLAB, the plot is approximated 132 00:07:39,640 --> 00:07:42,320 by drawing a linear line, drawing a line, 133 00:07:42,320 --> 00:07:44,710 between these circles. 134 00:07:44,710 --> 00:07:47,670 But because delta t is small, 1.8, 135 00:07:47,670 --> 00:07:52,480 it looks like a small function, all right? 136 00:07:52,480 --> 00:07:56,600 OK, let's try another one. 137 00:07:56,600 --> 00:07:59,080 So here-- let's see. 138 00:07:59,080 --> 00:08:01,600 How do I insert another? 139 00:08:01,600 --> 00:08:06,680 Each option insert [INAUDIBLE] insert. 140 00:08:06,680 --> 00:08:10,536 OK, so let's try another function. 141 00:08:10,536 --> 00:08:15,530 We did df dt equal to minus lambda u. 142 00:08:15,530 --> 00:08:19,400 How about minus lambda f? 143 00:08:19,400 --> 00:08:23,630 How about minus ft squared? 144 00:08:23,630 --> 00:08:26,320 Anybody know how to solve this ODE analytically? 145 00:08:34,299 --> 00:08:37,849 Anybody who reviews ODE before this class where 146 00:08:37,849 --> 00:08:39,173 you are reading the readings? 147 00:08:39,173 --> 00:08:40,536 The original variables? 148 00:08:40,536 --> 00:08:44,740 Good, we are going to be dividing f square on each side, 149 00:08:44,740 --> 00:08:45,240 right? 150 00:08:45,240 --> 00:08:51,240 So we have df over-- not on this-- f square equal to minus 151 00:08:51,240 --> 00:08:53,740 dt, right? 152 00:08:53,740 --> 00:08:56,040 We're going to be integrating both sides. 153 00:08:56,040 --> 00:08:59,220 And on this side, we get minus f 1 over f 154 00:08:59,220 --> 00:09:04,151 plus an arbitrary constant equal to minus t, right? 155 00:09:06,800 --> 00:09:12,920 So we are going to get f of t is going to be equal to 1 156 00:09:12,920 --> 00:09:19,860 over-- we have t-- here is actually plus t, right? 157 00:09:23,530 --> 00:09:25,480 Agree? 158 00:09:25,480 --> 00:09:29,320 OK, in particular, if I set the same initial condition, which 159 00:09:29,320 --> 00:09:36,070 is f of 0 equal to 1, then it determines my constant c 160 00:09:36,070 --> 00:09:41,060 and my f of t is equal to 1 over, what? 161 00:09:41,060 --> 00:09:43,420 One over t, right? 162 00:09:43,420 --> 00:09:49,270 OK, so let's Test this function. 163 00:09:49,270 --> 00:09:51,860 And it is going to be useful later on, right? 164 00:09:51,860 --> 00:09:55,130 So my f2 is going to be 1 over t. 165 00:09:55,130 --> 00:09:58,300 OK, I'm going to be-- let me hold on 166 00:09:58,300 --> 00:10:07,170 and plot t f2 [INAUDIBLE]. 167 00:10:07,170 --> 00:10:08,960 Oh, OK. 168 00:10:08,960 --> 00:10:11,020 That's one, right? 169 00:10:11,020 --> 00:10:14,830 I'm going to have serious trouble if I do this. 170 00:10:14,830 --> 00:10:21,460 So let me just do this again-- equal to 1 divided by t plus 1. 171 00:10:21,460 --> 00:10:25,090 Yes, thank you for paying attention, OK? 172 00:10:25,090 --> 00:10:30,350 And plot t f2. 173 00:10:30,350 --> 00:10:34,540 Let me do dash dash and s. 174 00:10:34,540 --> 00:10:38,060 So, dash dash means the [INAUDIBLE] line 175 00:10:38,060 --> 00:10:39,980 and s means squares. 176 00:10:39,980 --> 00:10:42,550 So we are going to see how different these 177 00:10:42,550 --> 00:10:43,690 are going to be. 178 00:10:43,690 --> 00:10:49,180 So, one function is the solution of df dt equal to minus f. 179 00:10:49,180 --> 00:10:54,140 The other is df dt equal to minus f square, right? 180 00:10:54,140 --> 00:10:57,620 OK, so here is discretization function. 181 00:10:57,620 --> 00:11:00,290 But like, this is nothing new, right? 182 00:11:00,290 --> 00:11:01,860 We all know this. 183 00:11:01,860 --> 00:11:06,080 What's new is how do we approximate the derivative 184 00:11:06,080 --> 00:11:08,750 of these functions. 185 00:11:08,750 --> 00:11:11,370 Because if we can approximate the derivative 186 00:11:11,370 --> 00:11:16,480 of these function, then we can start to solve these ODEs 187 00:11:16,480 --> 00:11:18,350 numerically, right? 188 00:11:18,350 --> 00:11:24,530 These two ODEs I just showed you have exact solutions. 189 00:11:24,530 --> 00:11:25,930 But the reason we take this class 190 00:11:25,930 --> 00:11:29,500 is because we want to solve ODEs that do not 191 00:11:29,500 --> 00:11:33,090 have analytical solutions. 192 00:11:33,090 --> 00:11:36,880 If we have a way to approximate the derivative of any function 193 00:11:36,880 --> 00:11:39,360 we want, then I'm going to show you 194 00:11:39,360 --> 00:11:43,580 that we can solve any differential equation we want. 195 00:11:43,580 --> 00:11:49,330 OK, so approximated derivative-- not from analytical function, 196 00:11:49,330 --> 00:11:53,710 but from a function discretized like what we just had. 197 00:11:53,710 --> 00:11:57,120 Right, so pretend we have MATLAB. 198 00:11:57,120 --> 00:11:58,440 We have this app. 199 00:11:58,440 --> 00:12:01,510 We have f2 but we don't know where they're computed from. 200 00:12:01,510 --> 00:12:04,570 They are just some kind of discretized function. 201 00:12:04,570 --> 00:12:06,838 Now, how do we compute the derivatives? 202 00:12:09,830 --> 00:12:11,830 OK, any ideas? 203 00:12:11,830 --> 00:12:13,310 Any ideas? 204 00:12:13,310 --> 00:12:14,800 Any ideas? 205 00:12:14,800 --> 00:12:16,290 Any ideas? 206 00:12:16,290 --> 00:12:16,810 Any ideas? 207 00:12:16,810 --> 00:12:18,370 The linear definition of derivative-- 208 00:12:18,370 --> 00:12:20,300 what is the linear definition of derivative? 209 00:12:35,401 --> 00:12:43,010 f2 minus f1 over f1-- There is a [INAUDIBLE]. 210 00:12:43,010 --> 00:12:46,620 OK, you did, like, partial t's. 211 00:12:46,620 --> 00:12:50,412 Anybody wants to [INAUDIBLE] what's your name? [INAUDIBLE] 212 00:12:50,412 --> 00:12:53,644 OK, anybody wants to complete this [INAUDIBLE] answer 213 00:12:53,644 --> 00:12:55,575 by maybe changing something? 214 00:13:16,420 --> 00:13:20,985 [INAUDIBLE] is f of t plus delta t minus f 215 00:13:20,985 --> 00:13:24,488 of t divided by delta t, right? 216 00:13:27,800 --> 00:13:30,170 And this is, of course, the definition 217 00:13:30,170 --> 00:13:32,620 of exact derivatives. 218 00:13:32,620 --> 00:13:37,086 But in the computer, we cannot take delta t and go to zero, 219 00:13:37,086 --> 00:13:38,020 right? 220 00:13:38,020 --> 00:13:40,055 That would again require infinite memory 221 00:13:40,055 --> 00:13:42,760 and infinite computation time. 222 00:13:42,760 --> 00:13:45,530 We have to approximate it. 223 00:13:45,530 --> 00:13:50,800 We have to be satisfied with delta t being small enough. 224 00:13:50,800 --> 00:13:54,040 OK, so here, we have a function like this. 225 00:13:54,040 --> 00:13:55,840 We have a function like this. 226 00:13:55,840 --> 00:14:01,340 Each-- let's look at this one, the one with squares. 227 00:14:01,340 --> 00:14:07,360 These two squares is based over delta t in the horizontal side. 228 00:14:07,360 --> 00:14:14,750 On the vertical side, they are spaced by f2 minus f1, right? 229 00:14:14,750 --> 00:14:18,430 So if we take the vertical distance, 230 00:14:18,430 --> 00:14:21,140 divide by the horizontal distance, that [INAUDIBLE] 231 00:14:21,140 --> 00:14:25,700 approximation of this, right? 232 00:14:25,700 --> 00:14:36,450 f of t plus delta t minus of of t over delta t, all right? 233 00:14:36,450 --> 00:14:40,600 So that's a good way of approximating the derivative. 234 00:14:40,600 --> 00:14:44,518 Now, anybody who can transform this formula into MATLAB? 235 00:14:48,110 --> 00:14:51,880 I have two functions, f and f2, in MATLAB. 236 00:14:51,880 --> 00:14:54,460 How do you guys transform this formula, 237 00:14:54,460 --> 00:14:56,980 which is-- this is like one of the most important skills you 238 00:14:56,980 --> 00:14:59,930 are going to learn in this class-- that is, how 239 00:14:59,930 --> 00:15:03,300 to incorporate, how to translate, 240 00:15:03,300 --> 00:15:06,540 a mathematical formula you can write down on a piece of paper 241 00:15:06,540 --> 00:15:08,590 into a code like MATLAB. 242 00:15:11,994 --> 00:15:14,160 [INAUDIBLE] see [INAUDIBLE] is that going to keep me 243 00:15:14,160 --> 00:15:17,450 a code I can type into MATLAB. 244 00:15:17,450 --> 00:15:19,970 Like, here, I'm writing [INAUDIBLE] type. 245 00:15:19,970 --> 00:15:21,260 Please tell me what to type. 246 00:15:36,710 --> 00:15:39,350 Yeah, find the function-- the difference 247 00:15:39,350 --> 00:15:41,740 between functions between one point and other points. 248 00:15:48,883 --> 00:15:50,775 Let me do a [INAUDIBLE]. 249 00:15:55,980 --> 00:16:00,050 Yes, the difference and the approximate derivative-- OK. 250 00:16:02,940 --> 00:16:05,690 OK, you guys are good. 251 00:16:05,690 --> 00:16:07,600 So OK, so I'm going to do something new. 252 00:16:07,600 --> 00:16:09,940 I'm going to use if. 253 00:16:09,940 --> 00:16:12,180 I'm going to use if of f. 254 00:16:12,180 --> 00:16:13,990 What is that going to give me? 255 00:16:13,990 --> 00:16:18,090 So let me just say df equal to diff f, OK? 256 00:16:18,090 --> 00:16:23,150 And let me double click on df to show me what this is. 257 00:16:23,150 --> 00:16:28,600 And I'm going to see, compare this with f-- f and df. 258 00:16:28,600 --> 00:16:31,280 So what I can see is that df gives me 259 00:16:31,280 --> 00:16:34,000 this minus this, right? 260 00:16:34,000 --> 00:16:36,170 The first element of df is the second element 261 00:16:36,170 --> 00:16:41,710 of f minus the first element-- sorry, this minus this. 262 00:16:41,710 --> 00:16:49,345 Or what I can do is the same thing can be computed by f of 2 263 00:16:49,345 --> 00:16:49,905 to end. 264 00:16:49,905 --> 00:16:52,150 Do you know what this means? 265 00:16:52,150 --> 00:16:54,460 Exactly-- it gives me all the angles 266 00:16:54,460 --> 00:16:58,230 from the second to the end minus f1, 2, and minus 1. 267 00:16:58,230 --> 00:16:59,188 What will this give me? 268 00:17:02,120 --> 00:17:05,920 The first to the second last-- so this gets me exactly 269 00:17:05,920 --> 00:17:08,500 the same answer, right? 270 00:17:08,500 --> 00:17:17,680 And of course, I can just do this divided by et, all right? 271 00:17:17,680 --> 00:17:22,343 And so this df dt. 272 00:17:22,343 --> 00:17:24,910 This is an approximation of the derivative. 273 00:17:28,060 --> 00:17:33,870 OK, and this is an approximation of the derivative at which 274 00:17:33,870 --> 00:17:44,420 point, if I speak to this formula and the discrete time 275 00:17:44,420 --> 00:17:46,840 instances instances, but like [INAUDIBLE]. 276 00:17:46,840 --> 00:17:52,820 So if look at length of df dt-- 277 00:17:52,820 --> 00:17:54,920 AUDIENCE: [INAUDIBLE] 278 00:17:54,920 --> 00:17:57,130 PROFESSOR: Yes, this is an approximation 279 00:17:57,130 --> 00:18:01,660 to the derivative from 0 to t minus delta t, right? 280 00:18:01,660 --> 00:18:04,960 Because here, I'm taking the difference between t 281 00:18:04,960 --> 00:18:08,360 plus delta t, which goes all the way to big t, 282 00:18:08,360 --> 00:18:12,350 minus ft, which actually doesn't go all the way to big t, right? 283 00:18:12,350 --> 00:18:15,810 So I have the derivative from 0 all the way 284 00:18:15,810 --> 00:18:17,450 to big t minus delta t. 285 00:18:17,450 --> 00:18:19,910 I don't have the derivative of the last one 286 00:18:19,910 --> 00:18:23,298 because at the last one, I do not have f of t plus delta t. 287 00:18:26,070 --> 00:18:34,890 OK, now let me plot-- let me make another figure. 288 00:18:34,890 --> 00:18:38,540 I'm going to plot t1 1 to n minus 1 289 00:18:38,540 --> 00:18:40,550 because I don't have the derivative 290 00:18:40,550 --> 00:18:44,870 at the very end as df dt. 291 00:18:44,870 --> 00:18:49,175 I'm going to plot them using circles. 292 00:18:49,175 --> 00:18:54,190 And it's the derivative-- yeah, this is the derivative. 293 00:18:54,190 --> 00:18:59,060 It goes all the way to close minus 1 to 0. 294 00:18:59,060 --> 00:19:04,630 And you can see it is roughly an approximation of the slope 295 00:19:04,630 --> 00:19:08,380 of the circle line, right? 296 00:19:08,380 --> 00:19:09,640 The slope is negative. 297 00:19:09,640 --> 00:19:13,320 Therefore, the derivative is negative. 298 00:19:13,320 --> 00:19:18,310 Let's compare this against the real derivative. 299 00:19:18,310 --> 00:19:21,050 Now, what is the real derivative of this function? 300 00:19:31,540 --> 00:19:35,970 The real derivative of this function if f of t 301 00:19:35,970 --> 00:19:40,710 is equal to minus-- e to the minus t, 302 00:19:40,710 --> 00:19:45,590 df dt is just equal to negative of e to the minus t, right? 303 00:19:45,590 --> 00:19:51,040 OK, so let's take this bigger two and hold on. 304 00:19:51,040 --> 00:19:54,840 And the plot t exponential of minus t 305 00:19:54,840 --> 00:20:01,710 negative-- let's plot it using black, [INAUDIBLE] black. 306 00:20:01,710 --> 00:20:05,120 OK, we see we had a pretty good approximation 307 00:20:05,120 --> 00:20:06,900 of the real derivative. 308 00:20:06,900 --> 00:20:12,084 We can also see that it is not exact, right? 309 00:20:12,084 --> 00:20:14,879 So if the black line goes right through the center 310 00:20:14,879 --> 00:20:17,540 of the circle, then I have a very good approximation. 311 00:20:17,540 --> 00:20:18,890 But, like, [INAUDIBLE]. 312 00:20:24,390 --> 00:20:32,140 All right, so we can see we do have some approximation error, 313 00:20:32,140 --> 00:20:35,980 which in this case, we call truncation error. 314 00:20:35,980 --> 00:20:39,600 OK, so this, how big the truncation error is, 315 00:20:39,600 --> 00:20:45,250 is the real meat of this lecture, OK? 316 00:20:45,250 --> 00:20:46,690 Truncation error. 317 00:20:46,690 --> 00:20:50,540 And here, we start the Taylor series analysis. 318 00:20:50,540 --> 00:20:52,710 So, Professor Wilcox last lecture 319 00:20:52,710 --> 00:20:56,070 said you're going to have so much fun with Taylor series. 320 00:20:56,070 --> 00:20:58,860 So I hope you have already started 321 00:20:58,860 --> 00:21:03,970 looking at Taylor series and it is important you guys do 322 00:21:03,970 --> 00:21:05,970 look at Taylor series. 323 00:21:05,970 --> 00:21:10,320 Because of the importance, I use red, OK? 324 00:21:10,320 --> 00:21:13,930 Taylor series analysis-- OK, so we 325 00:21:13,930 --> 00:21:17,420 want to know how much approximation error do 326 00:21:17,420 --> 00:21:24,180 we have by approximating the limit with this finite delta t, 327 00:21:24,180 --> 00:21:25,830 all right? 328 00:21:25,830 --> 00:21:28,920 We want to know what is the difference between df 329 00:21:28,920 --> 00:21:34,740 dt and our approximation. 330 00:21:34,740 --> 00:21:37,875 So this is at some t and this approximation 331 00:21:37,875 --> 00:21:41,140 is t plus delta t minus f of t. 332 00:21:46,360 --> 00:21:48,362 OK, how do I figure out this difference? 333 00:21:51,140 --> 00:21:53,140 How should I figure out this difference? 334 00:21:53,140 --> 00:21:55,195 Then we can compute both because-- yeah, 335 00:21:55,195 --> 00:21:56,800 we can compute both. 336 00:21:56,800 --> 00:21:58,369 And then we can prove a difference. 337 00:21:58,369 --> 00:22:00,660 We can [INAUDIBLE] this line with this line [INAUDIBLE] 338 00:22:00,660 --> 00:22:01,160 lambda. 339 00:22:01,160 --> 00:22:06,270 Like, this is probably 0.05 or something like that. 340 00:22:06,270 --> 00:22:10,250 Yes, this is a translation error, right? 341 00:22:10,250 --> 00:22:12,200 Because this only works when we do 342 00:22:12,200 --> 00:22:16,500 have an additional solution, right? 343 00:22:22,110 --> 00:22:28,350 And so what-- is there any way to activate 344 00:22:28,350 --> 00:22:33,910 how big the trunctation error is in a more general way? 345 00:22:33,910 --> 00:22:35,810 AUDIENCE: Taylor series. 346 00:22:35,810 --> 00:22:37,980 PROFESSOR: Taylor series-- OK, good. 347 00:22:37,980 --> 00:22:41,540 Taylor series-- what is Taylor series? 348 00:22:41,540 --> 00:22:44,640 Anybody can summarize what Taylor series is in, like, 349 00:22:44,640 --> 00:22:45,210 one sentence? 350 00:22:48,673 --> 00:22:49,548 AUDIENCE: [INAUDIBLE] 351 00:22:52,356 --> 00:22:53,730 PROFESSOR: Yeah, an approximation 352 00:22:53,730 --> 00:22:58,240 of a function at some point using 353 00:22:58,240 --> 00:23:01,225 the values and derivatives of this function 354 00:23:01,225 --> 00:23:05,700 at a nearby point, right? 355 00:23:05,700 --> 00:23:10,800 OK, so here, what we-- we have three things. 356 00:23:10,800 --> 00:23:14,365 If you look at the formula we have, three things. [INAUDIBLE] 357 00:23:14,365 --> 00:23:17,810 The derivative at t, the functionality 358 00:23:17,810 --> 00:23:20,690 at t [INAUDIBLE] the functionality, 359 00:23:20,690 --> 00:23:22,060 like, we have two points. 360 00:23:22,060 --> 00:23:25,360 One point is at t, the other points [INAUDIBLE]. 361 00:23:25,360 --> 00:23:28,996 At [INAUDIBLE] t, we have a derivative of [INAUDIBLE]. 362 00:23:28,996 --> 00:23:31,258 At another point, we [INAUDIBLE]. 363 00:23:34,054 --> 00:23:37,470 We can employ Taylor series in two ways. 364 00:23:37,470 --> 00:23:39,530 One way is more convenient. 365 00:23:39,530 --> 00:23:42,640 The other [INAUDIBLE] is a little bit more inconvenient 366 00:23:42,640 --> 00:23:45,490 but still works. 367 00:23:45,490 --> 00:23:51,490 The most convenient way is [INAUDIBLE] f at t plus delta 368 00:23:51,490 --> 00:23:54,260 t using Taylor series. 369 00:23:54,260 --> 00:23:56,690 The more inconvenient way is to send 370 00:23:56,690 --> 00:24:01,990 both derivatives and the value [INAUDIBLE] using Taylor series 371 00:24:01,990 --> 00:24:04,560 [INAUDIBLE]. 372 00:24:04,560 --> 00:24:06,742 So let's do the convenient way first. 373 00:24:06,742 --> 00:24:08,200 And I'm going to show you and we're 374 00:24:08,200 --> 00:24:10,710 going to get something similar using the slightly more 375 00:24:10,710 --> 00:24:13,840 convenient way, all right? 376 00:24:13,840 --> 00:24:20,440 So the easy way-- let me use green to denote the easy way. 377 00:24:20,440 --> 00:24:27,730 OK, so easy-- f at t plus delta t. 378 00:24:27,730 --> 00:24:31,000 So, the start of Taylor series-- the Taylor series 379 00:24:31,000 --> 00:24:35,680 I write as a formula is k goes from 0 380 00:24:35,680 --> 00:24:41,930 to-- let me actually-- equal to infinity 381 00:24:41,930 --> 00:24:51,752 of f to the k-th derivative at t divided by k factorial delta t 382 00:24:51,752 --> 00:24:53,550 to the k-th. 383 00:24:53,550 --> 00:24:58,130 This is what Taylor series is. 384 00:24:58,130 --> 00:25:03,300 And in this case, we do not want to keep anything 385 00:25:03,300 --> 00:25:06,380 above the first derivative. 386 00:25:09,350 --> 00:25:12,280 So I'm just going to be writing that-- I'm just 387 00:25:12,280 --> 00:25:13,750 going to be keeping two terms. 388 00:25:13,750 --> 00:25:16,510 The first term is k equal to 0. 389 00:25:16,510 --> 00:25:21,170 What is f to the 0-th derivative? 390 00:25:21,170 --> 00:25:23,170 It's just f itself, right? 391 00:25:23,170 --> 00:25:24,630 This is k equal to 0. 392 00:25:24,630 --> 00:25:27,240 What is 0 factorial? 393 00:25:27,240 --> 00:25:28,050 One. 394 00:25:28,050 --> 00:25:31,360 What is delta t to the 0-th? 395 00:25:31,360 --> 00:25:31,950 one. 396 00:25:31,950 --> 00:25:34,780 OK, so that is the first term. 397 00:25:34,780 --> 00:25:36,930 Now let's do k equal to 1. 398 00:25:36,930 --> 00:25:38,870 What is the first derivative of k? 399 00:25:38,870 --> 00:25:41,820 It's df dt. 400 00:25:41,820 --> 00:25:43,490 What is one factorial? 401 00:25:43,490 --> 00:25:43,990 It's 402 00:25:43,990 --> 00:25:45,070 one again. 403 00:25:45,070 --> 00:25:48,890 And delta t to the one-- that is delta t. 404 00:25:48,890 --> 00:25:54,919 Anything above that has a delta t to the at least second order, 405 00:25:54,919 --> 00:25:55,460 right? right? 406 00:25:55,460 --> 00:25:58,200 At least delta t squared. square. 407 00:25:58,200 --> 00:26:02,500 So I am going to write all these terms a a big O times big O 408 00:26:02,500 --> 00:26:03,740 delta t squared. 409 00:26:03,740 --> 00:26:06,072 Has anybody seen this big O [INAUDIBLE]? 410 00:26:08,750 --> 00:26:09,933 You did, OK. 411 00:26:09,933 --> 00:26:12,771 What this means is that this [INAUDIBLE] 412 00:26:12,771 --> 00:26:17,896 compares [INAUDIBLE] as long as all these terms 413 00:26:17,896 --> 00:26:22,012 have a delta t squared or delta t cube or delta t [INAUDIBLE]. 414 00:26:22,012 --> 00:26:27,446 [INAUDIBLE] more of the [INAUDIBLE] square. 415 00:26:27,446 --> 00:26:32,220 OK, which is true for all the other terms [INAUDIBLE]. 416 00:26:35,040 --> 00:26:38,660 Or maybe green is a little bit too-- 417 00:26:38,660 --> 00:26:40,900 doesn't show really well on this. 418 00:26:40,900 --> 00:26:46,040 So let me see if I can-- let me change to this. 419 00:26:46,040 --> 00:26:48,440 OK, yeah, that's better. 420 00:26:48,440 --> 00:26:51,350 All right, OK. 421 00:26:51,350 --> 00:26:55,560 So, once we do that, what does it change? 422 00:26:55,560 --> 00:26:57,560 [INAUDIBLE] action [INAUDIBLE]. 423 00:27:05,907 --> 00:27:07,490 Yeah, actually don't know [INAUDIBLE]. 424 00:27:11,690 --> 00:27:15,850 OK, once we do this, we can plot this back 425 00:27:15,850 --> 00:27:20,570 into the truncation error we call tau. 426 00:27:20,570 --> 00:27:27,000 Tau is going to be df dt at t minus something 427 00:27:27,000 --> 00:27:28,040 divided by delta t. 428 00:27:28,040 --> 00:27:30,560 And that something is-- first of all, 429 00:27:30,560 --> 00:27:42,770 it's a Taylor expansion of ft plus delta t minus f of t, 430 00:27:42,770 --> 00:27:45,140 right? 431 00:27:45,140 --> 00:27:48,920 And now it's time to cancel the terms. 432 00:27:48,920 --> 00:27:53,030 So I'm going to write this as it is and, first of all, 433 00:27:53,030 --> 00:27:54,430 try to cancel the terms here. 434 00:27:54,430 --> 00:27:56,130 So delta t is [INAUDIBLE] here. 435 00:27:56,130 --> 00:28:01,106 This ft cancels with this ft, right? 436 00:28:01,106 --> 00:28:12,650 So we have a df dt times delta t plus O delta t square, OK? 437 00:28:12,650 --> 00:28:18,360 And this delta t cancels with this delta t, which 438 00:28:18,360 --> 00:28:21,280 makes this cancel with this. 439 00:28:21,280 --> 00:28:25,560 So the only thing we get is, oh, delta t square divides 440 00:28:25,560 --> 00:28:26,720 by delta t. 441 00:28:30,180 --> 00:28:35,760 [INAUDIBLE] square, delta t square [INAUDIBLE] 442 00:28:35,760 --> 00:28:39,470 all the terms that has delta t square or higher. 443 00:28:39,470 --> 00:28:41,762 Then [INAUDIBLE] divided by delta t. 444 00:28:41,762 --> 00:28:43,145 What do we get? 445 00:28:43,145 --> 00:28:44,070 STUDENT: [INAUDIBLE] 446 00:28:44,070 --> 00:28:45,486 PROFESSOR: Order delta t, exactly. 447 00:28:48,480 --> 00:28:53,630 All right, so what we know is that the truncation 448 00:28:53,630 --> 00:28:58,690 error, whatever it is, is order delta t, which 449 00:28:58,690 --> 00:29:04,950 means it decreases f delta t. 450 00:29:04,950 --> 00:29:09,930 So [INAUDIBLE] to kind of-- to visualize what this means, 451 00:29:09,930 --> 00:29:16,645 if I go back to here, so this is [INAUDIBLE] 0.05, right? 452 00:29:16,645 --> 00:29:21,760 [INAUDIBLE] 0.05. 453 00:29:21,760 --> 00:29:25,190 This for delta t of 0.1. 454 00:29:25,190 --> 00:29:30,430 If I increase delta t to 0.2-- let me exaggerate. 455 00:29:30,430 --> 00:29:34,065 If I increase delta t t 1, what do you 456 00:29:34,065 --> 00:29:35,190 think this is going to get? 457 00:29:38,160 --> 00:29:41,130 Yeah, much bigger of course-- how much bigger? 458 00:29:49,730 --> 00:29:53,230 No, no, the area is O delta t. 459 00:29:53,230 --> 00:29:55,770 Let me say, if I can make this [INAUDIBLE] 460 00:29:55,770 --> 00:30:04,850 if I may [INAUDIBLE] Now the [INAUDIBLE] 0.05 [INAUDIBLE]. 461 00:30:04,850 --> 00:30:05,830 It's 1. 462 00:30:05,830 --> 00:30:08,800 It is going to be o delta t, which means delta t 463 00:30:08,800 --> 00:30:10,250 increase by a factor of two. 464 00:30:10,250 --> 00:30:12,710 This area increases by a factor of two. 465 00:30:12,710 --> 00:30:17,030 Let's just try to do this to see if what I said is true. 466 00:30:17,030 --> 00:30:19,970 0.2-- OK, I'm going to be repeating 467 00:30:19,970 --> 00:30:21,612 what I'm going to be doing. 468 00:30:21,612 --> 00:30:28,281 f is equal to-- no, I need to do t plus t equal to this. 469 00:30:28,281 --> 00:30:36,240 f is equal to this and the df dt is equal to this. 470 00:30:36,240 --> 00:30:40,324 Right, and I'm going to do a hold on and the plot. 471 00:30:43,110 --> 00:30:46,390 I'm going to be plotting t from 1 to n minus 1 df dt. 472 00:30:46,390 --> 00:30:49,010 And this time, I make it red. 473 00:30:49,010 --> 00:30:52,400 All right, so o means I still want to plot in circles. 474 00:30:52,400 --> 00:30:53,632 r means red. 475 00:30:53,632 --> 00:30:57,754 So Let's see what I get. 476 00:30:57,754 --> 00:31:00,690 Is it clear? 477 00:31:00,690 --> 00:31:07,670 The blue is the derivative I get [INAUDIBLE] delta t 0.1. 478 00:31:07,670 --> 00:31:12,740 The red is the derivative [INAUDIBLE] delta t 0.2. 479 00:31:12,740 --> 00:31:14,508 The error [INAUDIBLE] the difference 480 00:31:14,508 --> 00:31:16,320 between the circle and the black line. 481 00:31:16,320 --> 00:31:18,970 The black line is the exact [INAUDIBLE] derivative, 482 00:31:18,970 --> 00:31:23,280 which is only available if we have [INAUDIBLE]. 483 00:31:23,280 --> 00:31:26,120 And where [INAUDIBLE] the difference between the circles 484 00:31:26,120 --> 00:31:28,100 [INAUDIBLE] derivatives and the black line. 485 00:31:28,100 --> 00:31:29,900 This is real derivative. 486 00:31:29,900 --> 00:31:32,990 It grew by a factor of two. 487 00:31:32,990 --> 00:31:38,750 OK, so this is using the easy way, Taylor series analysis. 488 00:31:38,750 --> 00:31:41,280 I'm also going to show you briefly the hard way, which 489 00:31:41,280 --> 00:31:42,430 is kind of pointless here. 490 00:31:42,430 --> 00:31:44,700 But as you are going to see later 491 00:31:44,700 --> 00:31:48,100 on when we get to more complex schemes, 492 00:31:48,100 --> 00:31:50,750 we have to start using the more difficult way 493 00:31:50,750 --> 00:31:54,030 of doing Taylor series. 494 00:31:54,030 --> 00:31:56,870 I'm going to rewrite what is the [INAUDIBLE] error 495 00:31:56,870 --> 00:32:04,030 we're interested in here-- f of t plus delta t minus f of t 496 00:32:04,030 --> 00:32:05,760 divided by delta t, right? 497 00:32:05,760 --> 00:32:07,970 This is at t. 498 00:32:07,970 --> 00:32:11,220 OK, Taylor series-- we're going to do it again, 499 00:32:11,220 --> 00:32:18,380 but we're going to represent f of t as a Taylor series of k 500 00:32:18,380 --> 00:32:24,510 goes from 0 to infinity f to the k-th t 501 00:32:24,510 --> 00:32:28,910 plus delta t divided by k factorial. 502 00:32:28,910 --> 00:32:31,780 Here should be, what? 503 00:32:31,780 --> 00:32:36,330 So I'm extending f of t with a Taylor series that 504 00:32:36,330 --> 00:32:38,424 is based on t plus delta t. 505 00:32:43,394 --> 00:32:46,330 But there is something to the k power. 506 00:32:46,330 --> 00:32:47,871 And what is this something? 507 00:32:57,972 --> 00:33:00,670 OK, I'm just going to write a box here. 508 00:33:00,670 --> 00:33:06,075 f of y is equal to summation of k equal to 0. 509 00:33:06,075 --> 00:33:10,600 Taylor series k is power fx k factorial 510 00:33:10,600 --> 00:33:13,490 what to the k-th power. 511 00:33:13,490 --> 00:33:16,180 Let me explain to you y at x. 512 00:33:19,890 --> 00:33:23,770 Y minus x-- exactly, right? 513 00:33:23,770 --> 00:33:32,740 Previously, we have x being t, y being t plus delta t, OK? 514 00:33:32,740 --> 00:33:34,880 So y minus x is delta t. 515 00:33:37,880 --> 00:33:41,060 How about in this case? 516 00:33:41,060 --> 00:33:42,328 Negative delta t, exactly. 517 00:33:47,000 --> 00:33:48,336 OK, does this make sense? 518 00:33:54,300 --> 00:33:55,330 All right, yeah. 519 00:33:55,330 --> 00:33:57,570 So this is going to be very useful, 520 00:33:57,570 --> 00:34:03,740 like for making sure you know every different view, 521 00:34:03,740 --> 00:34:05,910 every different manipulation of the Taylor series. 522 00:34:05,910 --> 00:34:07,840 It's going to be useful. 523 00:34:07,840 --> 00:34:11,199 I'm going to show you another manipulation of the Taylor 524 00:34:11,199 --> 00:34:13,730 series. 525 00:34:13,730 --> 00:34:19,803 That is, if I take a derivative to both sides of the Taylor 526 00:34:19,803 --> 00:34:27,290 series, take derivative with respect to y, 527 00:34:27,290 --> 00:34:37,630 what I'm going to get-- if I take derivatives 528 00:34:37,630 --> 00:34:41,900 on the left hand side, what I'm going to get? 529 00:34:41,900 --> 00:34:48,550 df d-- yeah, let me just say, yeah, df dy 530 00:34:48,550 --> 00:34:54,230 is equal to summation k equal to 0 to infinity. 531 00:34:54,230 --> 00:34:56,400 What is this term, taking derivative y? 532 00:34:59,890 --> 00:35:00,870 It's a constant. 533 00:35:00,870 --> 00:35:02,050 There is no derivative. 534 00:35:02,050 --> 00:35:04,110 So this term doesn't depend on y. 535 00:35:04,110 --> 00:35:07,660 Only this can depends on y, right? 536 00:35:07,660 --> 00:35:16,140 So what I'm going to get is k, after k-th power [INAUDIBLE], 537 00:35:16,140 --> 00:35:22,680 write x divided by k factorial. 538 00:35:22,680 --> 00:35:27,120 I'm going to have y minus x to the k minus y power times 539 00:35:27,120 --> 00:35:30,630 another k here. 540 00:35:30,630 --> 00:35:34,550 So this is what happens when you type in [INAUDIBLE] derivative 541 00:35:34,550 --> 00:35:37,260 as a Taylor series. 542 00:35:37,260 --> 00:35:44,360 And now, if you expand this term at t plus delta t, 543 00:35:44,360 --> 00:35:46,026 you can write the same conclusion 544 00:35:46,026 --> 00:35:51,080 as we previously arrived, which is our scheme has a truncation 545 00:35:51,080 --> 00:35:53,346 error of order delta t. 546 00:35:53,346 --> 00:35:56,970 All right, let's take a mini break of like five minutes 547 00:35:56,970 --> 00:36:01,795 and then come back to our lecture. 548 00:36:01,795 --> 00:36:09,280 All right, so [INAUDIBLE] to you a small entry 549 00:36:09,280 --> 00:36:12,630 into what we are going to be doing with Taylor series. 550 00:36:12,630 --> 00:36:15,780 It's not going to be obvious in the beginning, but like, 551 00:36:15,780 --> 00:36:18,820 this is going to be getting better and better method 552 00:36:18,820 --> 00:36:20,580 to exercise. 553 00:36:20,580 --> 00:36:23,720 OK, [INAUDIBLE]. 554 00:36:23,720 --> 00:36:26,060 OK, let's get back to [INAUDIBLE] again. 555 00:36:26,060 --> 00:36:31,348 I'm sure I lost all of you when I talk about Taylor series of t 556 00:36:31,348 --> 00:36:33,140 [INAUDIBLE] plus delta t. 557 00:36:33,140 --> 00:36:36,950 But let's not get [INAUDIBLE] onto this. 558 00:36:36,950 --> 00:36:40,740 It just requires you to go back and look at Taylor series 559 00:36:40,740 --> 00:36:45,490 with a little bit more familiarity. 560 00:36:45,490 --> 00:36:52,150 OK, so here are-- I'm going to say a little bit on why we want 561 00:36:52,150 --> 00:36:55,630 to approximate the derivative and how 562 00:36:55,630 --> 00:37:04,630 is that going to give us a way of solve [INAUDIBLE]. 563 00:37:04,630 --> 00:37:08,780 OK, so remember, we are approximating the derivative df 564 00:37:08,780 --> 00:37:16,420 dt at time equal to t at f of t plus delta t minus f of t, 565 00:37:16,420 --> 00:37:18,810 right, over delta t. 566 00:37:18,810 --> 00:37:22,560 And that's not an idea I proposed. 567 00:37:22,560 --> 00:37:26,006 It's proposed by-- sorry, what was your name again? 568 00:37:26,006 --> 00:37:26,878 STUDENT: Ariya. 569 00:37:26,878 --> 00:37:29,980 PROFESSOR: Ariya, OK. 570 00:37:29,980 --> 00:37:34,430 OK, so yeah, if we stick to this scheme, 571 00:37:34,430 --> 00:37:40,140 we can actually start to integrate ODEs. 572 00:37:40,140 --> 00:37:44,820 OK, let's call this 0 equal to t0. 573 00:37:44,820 --> 00:37:47,970 So that's actually how each time step 574 00:37:47,970 --> 00:37:52,250 has a name-- so, t1 equal to delta t, 575 00:37:52,250 --> 00:37:56,160 p2 equal to 2 delta t, et cetera. 576 00:37:56,160 --> 00:38:00,990 And the function values-- f of t at t equal to 0. 577 00:38:00,990 --> 00:38:04,170 I'm going to call it f0. 578 00:38:04,170 --> 00:38:06,340 The function value at f1, I'm going 579 00:38:06,340 --> 00:38:09,700 to call it t1 equal to f1. 580 00:38:09,700 --> 00:38:13,690 The function value at t2, I'm going to call it f2. 581 00:38:16,460 --> 00:38:20,520 Now let's say I have an ODE and I only 582 00:38:20,520 --> 00:38:25,150 have the solution at t0, t1, t2. 583 00:38:25,150 --> 00:38:28,242 I want to know what is the solution at the next time 584 00:38:28,242 --> 00:38:30,010 stamp. 585 00:38:30,010 --> 00:38:32,170 What is the value of f3? 586 00:38:35,410 --> 00:38:38,110 So that is what happens when we solve ODEs, right? 587 00:38:38,110 --> 00:38:40,070 We start with the initial condition. 588 00:38:40,070 --> 00:38:44,680 We start with f0 that is given. 589 00:38:44,680 --> 00:38:48,110 The test case will compute what f1 si. 590 00:38:48,110 --> 00:38:53,560 And now, once I computed f1, the task is to compute what f2 is. 591 00:38:53,560 --> 00:38:58,870 Once I compute f2, now the task is to compute what f3. 592 00:38:58,870 --> 00:38:59,720 How do I compute f3? 593 00:39:05,900 --> 00:39:09,390 Yeah, how do I compute f3 using Taylor data points. 594 00:39:09,390 --> 00:39:10,860 So here's what is given. 595 00:39:10,860 --> 00:39:12,750 I have the ODE. 596 00:39:12,750 --> 00:39:21,635 I have df df equal to a function of f. 597 00:39:25,710 --> 00:39:28,886 Let's say-- I'm going to say minus lambda times f. 598 00:39:31,740 --> 00:39:37,930 So here's my single ODE I need to integrate. 599 00:39:37,930 --> 00:39:41,670 And I can approximate-- I have an approximation 600 00:39:41,670 --> 00:39:42,420 to the derivative. 601 00:39:45,300 --> 00:39:48,185 And I also have f0, f1, f2. 602 00:39:48,185 --> 00:39:49,460 How do I compute f3? 603 00:39:54,350 --> 00:39:56,190 So this is given. 604 00:39:56,190 --> 00:39:58,280 This is given. 605 00:39:58,280 --> 00:39:59,010 This is given. 606 00:39:59,010 --> 00:39:59,670 This is given. 607 00:39:59,670 --> 00:40:00,303 This is given. 608 00:40:05,620 --> 00:40:08,765 How do I put them together to compute [INAUDIBLE]? 609 00:40:08,765 --> 00:40:09,598 STUDENT: [INAUDIBLE] 610 00:40:21,310 --> 00:40:27,810 PROFESSOR: Right, we have our function value at f2. 611 00:40:27,810 --> 00:40:34,030 We also have an estimate of the derivative at f2, which 612 00:40:34,030 --> 00:40:36,530 actually involved the unknown. 613 00:40:36,530 --> 00:40:40,160 So let me write down-- let me write down-- this is important. 614 00:40:40,160 --> 00:40:45,090 Let me write down what is the derivative estimate at f2-- 615 00:40:45,090 --> 00:40:47,100 at t2, sorry. 616 00:40:47,100 --> 00:40:51,370 It is equal to f of t plus delta t, which is t3, right? 617 00:40:51,370 --> 00:41:01,760 This is t3 minus f at t2 divided by delta t. 618 00:41:01,760 --> 00:41:06,340 This actually involves an unknown in the derivative. 619 00:41:10,940 --> 00:41:16,070 And this is df dt by the differential equation 620 00:41:16,070 --> 00:41:20,800 is equal to minus lambda times f at, what? 621 00:41:20,800 --> 00:41:22,260 Is t2. 622 00:41:27,710 --> 00:41:33,320 Now, through this, by plotting both the approximation 623 00:41:33,320 --> 00:41:36,800 of the derivative and-- by basically putting 624 00:41:36,800 --> 00:41:39,620 both the approximation of the derivative and the function 625 00:41:39,620 --> 00:41:43,670 together, we converted the differential equation 626 00:41:43,670 --> 00:41:47,082 into a what equation? 627 00:41:47,082 --> 00:41:48,070 STUDENT: [INAUDIBLE] 628 00:41:48,070 --> 00:41:49,460 PROFESSOR: Yeah, into a difference equation, 629 00:41:49,460 --> 00:41:50,830 into a [INAUDIBLE] equation. 630 00:41:50,830 --> 00:41:52,345 We can just compute. 631 00:41:54,940 --> 00:41:58,240 So let me color this. 632 00:41:58,240 --> 00:42:03,510 This is unknown, this is known, and this is known. 633 00:42:06,090 --> 00:42:09,710 We can just move all the unknowns to one side. 634 00:42:09,710 --> 00:42:16,410 So f of t3 is my f3 is equal to all the known 635 00:42:16,410 --> 00:42:17,910 on the other side. 636 00:42:17,910 --> 00:42:26,270 f of t2 is f2 minus delta t times lambda times f of t 637 00:42:26,270 --> 00:42:29,170 to [INAUDIBLE] 2. 638 00:42:29,170 --> 00:42:35,801 Right, by doing this, I compute F3 out of f2. 639 00:42:38,390 --> 00:42:41,410 Now, what do I do when I-- now I have f3. 640 00:42:41,410 --> 00:42:45,880 What do I do when I want to compute f4? 641 00:42:45,880 --> 00:42:46,810 Same thing, right? 642 00:42:46,810 --> 00:42:51,200 It's kind of recursive because my f4 is now 643 00:42:51,200 --> 00:42:56,560 equal to f3 minus delta t lambda f3, right? 644 00:42:56,560 --> 00:42:58,500 And I just could go on. 645 00:42:58,500 --> 00:43:05,710 The only thing I need is to plug in the derivative approximation 646 00:43:05,710 --> 00:43:07,220 here into the differential equation. 647 00:43:14,050 --> 00:43:20,738 Let me do it again using another different scheme. 648 00:43:25,498 --> 00:43:28,370 [INAUDIBLE] me do this [INAUDIBLE]. 649 00:43:28,370 --> 00:43:31,130 OK, different scheme. 650 00:43:37,300 --> 00:43:40,994 OK, another way to approximate the function-- 651 00:43:40,994 --> 00:43:42,660 I mean, I have been calling the function 652 00:43:42,660 --> 00:43:48,520 f, but like, because we started by discretizing a function. 653 00:43:48,520 --> 00:43:50,950 But, like, in [INAUDIBLE] ODEs, it 654 00:43:50,950 --> 00:43:55,130 is more convention to call the solution u. 655 00:43:55,130 --> 00:43:57,374 So from now on, I'm just going to call my function 656 00:43:57,374 --> 00:44:00,020 as u of t instead of f of t. 657 00:44:00,020 --> 00:44:05,606 This is just a-- but, like, everything else is the same. 658 00:44:05,606 --> 00:44:10,170 [INAUDIBLE] with this, we'll just call it u of t. 659 00:44:10,170 --> 00:44:21,850 OK, u of t, I have du dt equal to minus lambda times u of t. 660 00:44:21,850 --> 00:44:26,830 I'm going to devise another scheme of approximating 661 00:44:26,830 --> 00:44:28,450 the derivative. 662 00:44:28,450 --> 00:44:37,190 I have du dt at a certain time t equal to u at t plus delta 663 00:44:37,190 --> 00:44:45,340 t minus u at t minus delta t divided by 2 delta t. 664 00:44:49,780 --> 00:44:52,190 OK, so let's do two things. 665 00:44:52,190 --> 00:44:56,110 One is, why is this a [INAUDIBLE] 666 00:44:56,110 --> 00:44:59,420 approximation to the derivative? 667 00:44:59,420 --> 00:45:02,600 Two-- now, if this is a valid approximation 668 00:45:02,600 --> 00:45:06,090 of the derivative, how do I make this a [INAUDIBLE] 669 00:45:06,090 --> 00:45:07,196 of [INAUDIBLE] ODE? 670 00:45:10,510 --> 00:45:13,590 So, anybody have an idea to how to answer 671 00:45:13,590 --> 00:45:15,116 either of these [INAUDIBLE]? 672 00:45:15,116 --> 00:45:15,616 Yes? 673 00:45:15,616 --> 00:45:16,449 STUDENT: [INAUDIBLE] 674 00:45:19,619 --> 00:45:21,660 PROFESSOR: It's the definition of the derivative, 675 00:45:21,660 --> 00:45:23,159 but the definition of the derivative 676 00:45:23,159 --> 00:45:24,264 is also [INAUDIBLE], yes? 677 00:45:24,264 --> 00:45:25,097 STUDENT: [INAUDIBLE] 678 00:45:47,976 --> 00:45:49,970 PROFESSOR: Good. 679 00:45:49,970 --> 00:45:52,200 After the [INAUDIBLE] problems, it 680 00:45:52,200 --> 00:45:55,950 can be solved using Taylor series [INAUDIBLE]. 681 00:45:55,950 --> 00:45:57,310 OK, it's good. 682 00:45:57,310 --> 00:46:01,140 So, answer to the first question-- y 683 00:46:01,140 --> 00:46:04,271 is a good approximation. 684 00:46:08,990 --> 00:46:13,152 OK, to answer that, again we use Taylor series. 685 00:46:18,080 --> 00:46:21,340 u at t plus delta t-- as usual, we 686 00:46:21,340 --> 00:46:27,690 are going to be expanding it using u and t plus du 687 00:46:27,690 --> 00:46:32,880 dt at t times delta t plus o delta t square, right? 688 00:46:32,880 --> 00:46:36,826 This is the same thing as we did of the other scheme. 689 00:46:36,826 --> 00:46:41,010 The other scheme is [INAUDIBLE], right? 690 00:46:41,010 --> 00:46:44,570 Remember your reading. 691 00:46:44,570 --> 00:46:49,169 And ut minus delta t-- how do I expand that? 692 00:46:53,270 --> 00:46:53,770 Yes. 693 00:46:53,770 --> 00:46:54,603 STUDENT: [INAUDIBLE] 694 00:46:58,380 --> 00:46:58,880 Good. 695 00:46:58,880 --> 00:47:01,430 It's the same thing except for the distance 696 00:47:01,430 --> 00:47:08,330 between this t minus delta t and t is minus delta t, right? 697 00:47:08,330 --> 00:47:12,500 So in here, the distance between this variable and this variable 698 00:47:12,500 --> 00:47:13,570 is delta t. 699 00:47:13,570 --> 00:47:16,010 Here, the distance between this variable and this variable 700 00:47:16,010 --> 00:47:17,680 is minus delta t. 701 00:47:17,680 --> 00:47:20,570 Therefore, all the values and derivative 702 00:47:20,570 --> 00:47:24,720 is the same except for here, I put minus delta t. 703 00:47:24,720 --> 00:47:28,445 And o, it should be minus delta t to the q. 704 00:47:28,445 --> 00:47:31,580 But does it matter? 705 00:47:31,580 --> 00:47:36,480 No, in the big O notation, the constant coefficients, 706 00:47:36,480 --> 00:47:39,920 [INAUDIBLE] the terms doesn't matter, right? 707 00:47:39,920 --> 00:47:44,550 So minus O delta t square is the same as o delta t square, 708 00:47:44,550 --> 00:47:48,970 is the same as five times o delta t square. 709 00:47:48,970 --> 00:47:52,040 It's the same as 1 million times over delta t square. 710 00:47:52,040 --> 00:47:56,790 As long as the terms have delta t square in front of it, 711 00:47:56,790 --> 00:47:59,550 no matter if it's multiplied by 1 million 712 00:47:59,550 --> 00:48:01,970 or 1 million or 1 trillion, it doesn't matter. 713 00:48:01,970 --> 00:48:04,220 It's o delta t squared. 714 00:48:04,220 --> 00:48:06,170 If it's multiplied by minus 1, it's 715 00:48:06,170 --> 00:48:10,770 still o delta t squared, right? 716 00:48:10,770 --> 00:48:17,910 OK, so now, when I plug in both approximations 717 00:48:17,910 --> 00:48:22,130 into this formula, t plus delta t 718 00:48:22,130 --> 00:48:26,880 minus u t minus delta t over 2 delta t, 719 00:48:26,880 --> 00:48:31,020 is equal to-- these two terms cancel out. 720 00:48:31,020 --> 00:48:33,970 These two terms-- they actually have different signs. 721 00:48:33,970 --> 00:48:37,340 So they become [INAUDIBLE] 2 times delta t. 722 00:48:37,340 --> 00:48:42,780 Du dt plus-- I'm just going to write this down. 723 00:48:42,780 --> 00:48:43,730 What is this plus? 724 00:48:43,730 --> 00:48:49,080 What is the difference between these 2 o delta t's? 725 00:48:49,080 --> 00:48:51,910 Do they cancel out? 726 00:48:51,910 --> 00:48:52,678 No? 727 00:48:52,678 --> 00:48:54,430 AUDIENCE: [INAUDIBLE] 728 00:48:54,430 --> 00:48:57,020 PROFESSOR: It's still o delta t square. 729 00:48:57,020 --> 00:48:58,702 Why? 730 00:48:58,702 --> 00:49:00,377 AUDIENCE: [INAUDIBLE] 731 00:49:00,377 --> 00:49:01,960 PROFESSOR: Exactly, because they don't 732 00:49:01,960 --> 00:49:03,251 know what the coefficients are. 733 00:49:03,251 --> 00:49:06,710 Maybe one of these [INAUDIBLE] has 1 million in front of it. 734 00:49:06,710 --> 00:49:11,060 The other o del t has a 0.001 in front of it. 735 00:49:11,060 --> 00:49:13,290 So no matter the summation of them 736 00:49:13,290 --> 00:49:17,980 or the difference between them, they are still o delta t. 737 00:49:17,980 --> 00:49:22,290 So this is going to be-- these two cancel out. 738 00:49:22,290 --> 00:49:27,880 du dt, this is at t, plus-- again, 739 00:49:27,880 --> 00:49:30,380 this o delta t squared divided by delta t, 740 00:49:30,380 --> 00:49:34,180 it becomes o delta t, right? 741 00:49:37,940 --> 00:49:42,450 OK, so this is still a good approximation, 742 00:49:42,450 --> 00:49:47,290 because the difference between them is o delta t. 743 00:49:47,290 --> 00:49:50,480 And it is actually stronger than o delta t 744 00:49:50,480 --> 00:49:54,140 because in these two Taylor series expansions, 745 00:49:54,140 --> 00:49:56,540 you can expend more terms. 746 00:49:56,540 --> 00:49:58,490 And you're going to find out that coefficients 747 00:49:58,490 --> 00:50:00,240 before [INAUDIBLE] these o delta t squares 748 00:50:00,240 --> 00:50:04,910 before the delta t squares still are going to cancel out. 749 00:50:04,910 --> 00:50:09,320 So you're going to get o delta t cubed out of these Taylor 750 00:50:09,320 --> 00:50:10,200 series [INAUDIBLE]. 751 00:50:10,200 --> 00:50:11,880 And over here, you can actually prove 752 00:50:11,880 --> 00:50:14,380 that-- it's in the reading. 753 00:50:14,380 --> 00:50:17,970 You can prove that this is not only o delta t 754 00:50:17,970 --> 00:50:19,710 but also o delta t square. 755 00:50:23,020 --> 00:50:25,860 It's a confusing [INAUDIBLE] conflict itself. 756 00:50:25,860 --> 00:50:29,020 We're saying that this is both o delta t and and o delta t 757 00:50:29,020 --> 00:50:30,600 square. 758 00:50:30,600 --> 00:50:32,190 Do I contradict myself? 759 00:50:35,546 --> 00:50:36,046 No? 760 00:50:36,046 --> 00:50:36,546 Hm? 761 00:50:36,546 --> 00:50:38,480 AUDIENCE: [INAUDIBLE] 762 00:50:38,480 --> 00:50:40,730 PROFESSOR: Yeah, how does it go? 763 00:50:40,730 --> 00:50:45,036 How can this term be both o delta t and o delta t squared? 764 00:50:47,850 --> 00:50:51,978 Again [INAUDIBLE] I want-- somebody else, yeah. 765 00:50:51,978 --> 00:50:56,758 AUDIENCE: Because o delta t is the [INAUDIBLE] delta t squared 766 00:50:56,758 --> 00:50:59,119 and [INAUDIBLE] 767 00:50:59,119 --> 00:51:00,910 PROFESSOR: Yeah, because o delta t actually 768 00:51:00,910 --> 00:51:03,700 includes o delta t squared. 769 00:51:03,700 --> 00:51:07,735 o delta t means it can contain delta t terms, 770 00:51:07,735 --> 00:51:11,250 delta t squared terms, and delta t [INAUDIBLE]. 771 00:51:11,250 --> 00:51:13,990 But any or all of these terms can 772 00:51:13,990 --> 00:51:15,670 have zero as their coefficient. 773 00:51:18,370 --> 00:51:22,260 If I have an o delta t term and it 774 00:51:22,260 --> 00:51:25,560 happens that the coefficient before the delta t term 775 00:51:25,560 --> 00:51:28,170 is zero, then it is automatically 776 00:51:28,170 --> 00:51:33,390 going to be o delta t squared, right? 777 00:51:33,390 --> 00:51:40,820 So I can say that o 1 is a superset of o delta t, which 778 00:51:40,820 --> 00:51:43,950 is a superset of o delta t square, which 779 00:51:43,950 --> 00:51:47,370 is a superset of o delta t cube, et cetera. 780 00:51:55,240 --> 00:51:56,060 Any questions? 781 00:52:00,060 --> 00:52:00,560 Questions? 782 00:52:06,350 --> 00:52:06,970 All right. 783 00:52:06,970 --> 00:52:11,070 OK, and so now, the second question 784 00:52:11,070 --> 00:52:16,150 is how to make a scheme out of it. 785 00:52:23,190 --> 00:52:25,830 We already have an approximation. 786 00:52:25,830 --> 00:52:33,596 That is du dt at t is equal to u of t plus delta t minus u 787 00:52:33,596 --> 00:52:36,950 of t minus delta t divided by t delta t. 788 00:52:36,950 --> 00:52:38,706 We have a differential equation-- 789 00:52:38,706 --> 00:52:41,940 du dt equal to minus lambda u. 790 00:52:41,940 --> 00:52:43,460 Again, the only thing you need to do 791 00:52:43,460 --> 00:52:46,350 is to plug this into this. 792 00:52:46,350 --> 00:52:50,960 So we have u of t plus delta t minus u of t 793 00:52:50,960 --> 00:52:55,340 minus delta t divided by 2 delta t is 794 00:52:55,340 --> 00:52:57,761 equal to minus lambda u at t. 795 00:53:00,990 --> 00:53:06,600 And when you look at these terms, when you are at time t, 796 00:53:06,600 --> 00:53:08,760 when the solution at time t is already 797 00:53:08,760 --> 00:53:12,810 known but anything beyond t is unknown, 798 00:53:12,810 --> 00:53:16,470 then this is known because this is the before t. 799 00:53:16,470 --> 00:53:18,750 This is known because this at t. 800 00:53:18,750 --> 00:53:24,970 The only unknown is this. 801 00:53:24,970 --> 00:53:27,730 So again, we are going to rearrange the terms 802 00:53:27,730 --> 00:53:33,130 and say u t plus delta t is equal to u 803 00:53:33,130 --> 00:53:39,042 t minus delta t minus 2 delta t times lambda times ut. 804 00:53:41,990 --> 00:53:44,580 If t is going to be exactly on a time step, 805 00:53:44,580 --> 00:53:50,190 what I'm going to say is that u of i plus 1 806 00:53:50,190 --> 00:53:56,060 is equal to ui minus 1 minus 2 delta t lambda times ui. 807 00:53:59,080 --> 00:54:06,810 OK, this notation is assuming I have discretized u 808 00:54:06,810 --> 00:54:11,966 into a uniform grid of space in delta t. 809 00:54:11,966 --> 00:54:13,924 AUDIENCE: [INAUDIBLE] 810 00:54:13,924 --> 00:54:14,590 PROFESSOR: Yeah. 811 00:54:14,590 --> 00:54:15,465 AUDIENCE: [INAUDIBLE] 812 00:54:21,700 --> 00:54:24,710 PROFESSOR: The question is, am I using a scheme that 813 00:54:24,710 --> 00:54:25,985 has a mathematical definition? 814 00:54:25,985 --> 00:54:26,860 AUDIENCE: [INAUDIBLE] 815 00:54:31,521 --> 00:54:32,270 PROFESSOR: Oh, OK. 816 00:54:32,270 --> 00:54:33,756 So what does a scheme mean? 817 00:54:33,756 --> 00:54:36,830 A scheme is a numerical method, a method 818 00:54:36,830 --> 00:54:41,650 that you can implement into the computer to solve 819 00:54:41,650 --> 00:54:43,490 a differential equation. 820 00:54:43,490 --> 00:54:46,180 It just means if I have an initial condition, 821 00:54:46,180 --> 00:54:48,880 a scheme must be able to tell me where 822 00:54:48,880 --> 00:54:51,676 is the solution at the next time step and then tell me again, 823 00:54:51,676 --> 00:54:53,467 what is the solution at the next time step, 824 00:54:53,467 --> 00:54:54,633 et cetera, et cetera, right? 825 00:54:54,633 --> 00:54:57,921 A scheme is basically, you can think of it as an algorithm. 826 00:54:57,921 --> 00:54:58,796 AUDIENCE: [INAUDIBLE] 827 00:55:02,764 --> 00:55:03,873 PROFESSOR: Right. 828 00:55:03,873 --> 00:55:04,748 AUDIENCE: [INAUDIBLE] 829 00:55:07,724 --> 00:55:09,088 PROFESSOR: We're making what? 830 00:55:09,088 --> 00:55:09,963 AUDIENCE: [INAUDIBLE] 831 00:55:16,260 --> 00:55:18,652 PROFESSOR: Exactly, exactly, yeah. 832 00:55:21,610 --> 00:55:22,480 Good question. 833 00:55:22,480 --> 00:55:27,010 I was just so familiar with what scheme is, I didn't explain it. 834 00:55:27,010 --> 00:55:29,230 So it's a good catch. 835 00:55:29,230 --> 00:55:32,500 If you find something like this, please to raise a question. 836 00:55:32,500 --> 00:55:35,970 Because if you have a question, your classmates probably 837 00:55:35,970 --> 00:55:37,636 also have the same question. 838 00:55:41,640 --> 00:55:51,560 OK, so here, we basically derived two schemes. 839 00:55:51,560 --> 00:55:54,640 By the way, this scheme is the midpoint scheme. 840 00:55:58,860 --> 00:56:03,340 We have tow rite two schemes-- the [INAUDIBLE] scheme, 841 00:56:03,340 --> 00:56:12,980 which is the scheme that we have-- 842 00:56:12,980 --> 00:56:15,850 yeah, the scheme we have here. 843 00:56:15,850 --> 00:56:19,360 We can run it in general as f of i plus 1 844 00:56:19,360 --> 00:56:23,390 equal to f of i minus delta t lambda f i. 845 00:56:23,390 --> 00:56:24,765 So this is the Forward Euler. 846 00:56:27,740 --> 00:56:32,430 This is called a forward Euler scheme in your reading. 847 00:56:32,430 --> 00:56:34,700 And we have also derived the midpoint scheme 848 00:56:34,700 --> 00:56:38,380 both from-- they are different only 849 00:56:38,380 --> 00:56:42,670 by that they're different in how to approximate 850 00:56:42,670 --> 00:56:44,770 the derivative in time. 851 00:56:44,770 --> 00:56:47,414 Once you have an approximation of the derivative in time, 852 00:56:47,414 --> 00:56:49,080 you plug into the differential equation. 853 00:56:49,080 --> 00:56:53,510 You can [INAUDIBLE], OK? 854 00:56:53,510 --> 00:56:55,270 Now what I want to talk about next 855 00:56:55,270 --> 00:56:59,090 is what is the local order of accuracy. 856 00:56:59,090 --> 00:57:02,010 And I'm going to say that the local order of accuracy 857 00:57:02,010 --> 00:57:07,650 is how accurate the scheme approximates the time 858 00:57:07,650 --> 00:57:08,150 derivative. 859 00:57:11,690 --> 00:57:16,040 It is related to what tau is. 860 00:57:16,040 --> 00:57:23,140 So for example, in forward Euler, how is o delta t, right? 861 00:57:23,140 --> 00:57:25,980 This is what we derived right before we take the break. 862 00:57:28,630 --> 00:57:39,520 So tau is-- tau in forward Euler is the df dt at t minus-- 863 00:57:39,520 --> 00:57:44,200 let me call it u because it's a small-- it's 864 00:57:44,200 --> 00:57:49,030 more consistent to the notes-- minus u at t 865 00:57:49,030 --> 00:57:53,790 plus delta t minus ut divided by delta t. 866 00:57:53,790 --> 00:58:00,730 This is o delta t for forward Euler. 867 00:58:00,730 --> 00:58:05,430 And the tau is the same derivative 868 00:58:05,430 --> 00:58:09,400 minus a different approximation for the derivative, ut 869 00:58:09,400 --> 00:58:12,680 minus delta t divided by 2 delta t. 870 00:58:12,680 --> 00:58:15,930 This is actually o delta t square 871 00:58:15,930 --> 00:58:20,370 for the midpoint and through Taylor series analysis. 872 00:58:23,580 --> 00:58:27,550 OK, the local order of accuracy is 873 00:58:27,550 --> 00:58:35,160 the exponent on top of delta t of this truncation error. 874 00:58:35,160 --> 00:58:38,590 So forward Euler is first order accurate because it's o delta 875 00:58:38,590 --> 00:58:39,460 t. 876 00:58:39,460 --> 00:58:42,411 Midpoint is second order accurate because it's o delta t 877 00:58:42,411 --> 00:58:42,910 square. 878 00:58:47,730 --> 00:58:52,440 So the local order of accuracy is 1 for forward Euler. 879 00:58:52,440 --> 00:58:55,166 The local one of accuracy is 2 for midpoint. 880 00:58:59,560 --> 00:59:06,640 Usually, the higher the order is, the better scheme is. 881 00:59:06,640 --> 00:59:09,430 Why? 882 00:59:09,430 --> 00:59:11,790 Because you can make the scheme more accurate by only 883 00:59:11,790 --> 00:59:17,760 increasing or decreasing delta t a little bit. 884 00:59:17,760 --> 00:59:20,350 We just need an analysis of forward Euler. 885 00:59:20,350 --> 00:59:27,150 If I make delta t half as small, how much smaller the truncation 886 00:59:27,150 --> 00:59:29,314 error is going to be? 887 00:59:29,314 --> 00:59:30,600 Half. 888 00:59:30,600 --> 00:59:36,330 Now, if I have a midpoint, if I decrease the-- 889 00:59:36,330 --> 00:59:41,770 if I decrease the delta t by half, how much more accurate 890 00:59:41,770 --> 00:59:44,470 is the midpoint going to be? 891 00:59:44,470 --> 00:59:46,500 A quarter-- exactly. 892 00:59:46,500 --> 00:59:55,130 So-- yeah, so this is how we usually kind of visualize 893 00:59:55,130 --> 00:59:57,120 the order of accuracy. 894 00:59:57,120 --> 01:00:02,216 OK, so let's say the [INAUDIBLE] is delta t. 895 01:00:02,216 --> 01:00:03,840 OK, so let's say this is forward Euler. 896 01:00:06,350 --> 01:00:09,740 So let's say this is first order accurate. 897 01:00:09,740 --> 01:00:14,560 This is delta t and delta t, let's say, is 1 here, 1 to 1 898 01:00:14,560 --> 01:00:21,550 here, 1 to o1 here, 1 to oo1 here. 899 01:00:21,550 --> 01:00:24,140 So let's say when you have 1 I get 900 01:00:24,140 --> 01:00:27,000 a pretty big error [INAUDIBLE]. 901 01:00:27,000 --> 01:00:29,449 When I decrease delta t to 0.1, what 902 01:00:29,449 --> 01:00:31,198 do you think the error is going to become? 903 01:00:34,410 --> 01:00:35,920 [INAUDIBLE], right. 904 01:00:35,920 --> 01:00:38,240 So I should be right here, right? 905 01:00:38,240 --> 01:00:42,970 I should be right here because it's o delta t. 906 01:00:42,970 --> 01:00:45,300 Now, if I decrease it to 0.01, [INAUDIBLE] 907 01:00:45,300 --> 01:00:48,370 should decrease by another 10 and by another 10. 908 01:00:48,370 --> 01:00:54,380 So if I link it, it will be a line with a slope of 1 909 01:00:54,380 --> 01:01:00,580 in a [INAUDIBLE] All right? 910 01:01:00,580 --> 01:01:03,020 Now-- so this is forward Euler. 911 01:01:03,020 --> 01:01:05,480 This is first order accurate. 912 01:01:05,480 --> 01:01:07,680 How about a second order accurate scheme? 913 01:01:07,680 --> 01:01:14,400 So again, [INAUDIBLE] delta t is 1, 0.1, 0.01, 0.001 here. 914 01:01:14,400 --> 01:01:17,690 And again, if I am [INAUDIBLE] large error 915 01:01:17,690 --> 01:01:20,550 at delta t equal to 1, what do you think 916 01:01:20,550 --> 01:01:24,230 is the error going to be at delta t equal to 0.1? 917 01:01:29,208 --> 01:01:29,708 [INAUDIBLE] 918 01:01:32,319 --> 01:01:33,194 AUDIENCE: [INAUDIBLE] 919 01:01:38,680 --> 01:01:41,980 PROFESSOR: Why should it be here? 920 01:01:41,980 --> 01:01:46,340 It's delta t square [INAUDIBLE] smaller. 921 01:01:46,340 --> 01:01:50,640 Delta t square is 100 times smaller. 922 01:01:50,640 --> 01:01:55,720 So I should be here when delta t decreased by a factor of 10. 923 01:01:55,720 --> 01:01:58,310 I should be here when delta t is decreased 924 01:01:58,310 --> 01:01:59,620 by another factor of 10. 925 01:01:59,620 --> 01:02:03,070 If I link it, it will be a slope like this 926 01:02:03,070 --> 01:02:07,590 and I'm kind of out of touch when I'm 0.001. 927 01:02:07,590 --> 01:02:11,120 So you can see that second order scheme is something much better 928 01:02:11,120 --> 01:02:13,370 than the first order scheme. 929 01:02:13,370 --> 01:02:18,950 Essentially, I have the luxury of making delta t very small-- 930 01:02:18,950 --> 01:02:27,210 OK, so going back to MATLAB, if I can say df dt equal to-- now 931 01:02:27,210 --> 01:02:29,830 I cannot no longer do this, right? 932 01:02:29,830 --> 01:02:37,640 I have to do f of 3 to n [INAUDIBLE] 3 to n OK, 933 01:02:37,640 --> 01:02:43,964 let me clear the workspace so that you can see better. 934 01:02:43,964 --> 01:02:46,270 [INAUDIBLE] window [INAUDIBLE]. 935 01:02:46,270 --> 01:02:54,550 OK, so df dt-- let me say midpoint is equal to f of 3 936 01:02:54,550 --> 01:02:59,877 to n minus f of 1 to n minus 2. 937 01:02:59,877 --> 01:03:00,710 What does this mean? 938 01:03:08,300 --> 01:03:12,370 I'm picking from the third value to the last value-- 939 01:03:12,370 --> 01:03:16,030 minus the first value to the third last value. 940 01:03:19,521 --> 01:03:20,021 OK. 941 01:03:20,021 --> 01:03:20,896 AUDIENCE: [INAUDIBLE] 942 01:03:23,710 --> 01:03:26,990 PROFESSOR: I'm taking the different space by two. 943 01:03:26,990 --> 01:03:32,170 OK, so that is like-- there is how I view f at t 944 01:03:32,170 --> 01:03:34,790 plus delta t minus f of t minus delta t. 945 01:03:37,510 --> 01:03:41,370 So I should divide this by how much? 946 01:03:41,370 --> 01:03:43,800 2 times delta t-- exactly. 947 01:03:43,800 --> 01:03:46,620 And here, I think I'm actually doing a really big delta t. 948 01:03:46,620 --> 01:03:51,690 It doesn't matter. [INAUDIBLE] OK, so when I plot it 949 01:03:51,690 --> 01:03:55,200 I should be plotting it against the t going 950 01:03:55,200 --> 01:03:57,190 from 2 to n minus 1, right? 951 01:03:57,190 --> 01:04:00,570 Because this is now my t. 952 01:04:00,570 --> 01:04:02,860 2 to n minus 1 is my t. 953 01:04:02,860 --> 01:04:05,630 3 to n is my t plus delta t. 954 01:04:05,630 --> 01:04:09,250 1 to n minus 2 is t minus delta t. 955 01:04:09,250 --> 01:04:10,480 So this is my t. 956 01:04:10,480 --> 01:04:14,990 I'm going to [INAUDIBLE] this against df dt midpoint. 957 01:04:14,990 --> 01:04:18,020 I'm going to be square and what color do you want? 958 01:04:20,950 --> 01:04:21,754 AUDIENCE: Pink. 959 01:04:21,754 --> 01:04:22,420 PROFESSOR: Pink? 960 01:04:25,940 --> 01:04:26,440 Magenta? 961 01:04:26,440 --> 01:04:30,200 OK, [INAUDIBLE] square, OK. 962 01:04:30,200 --> 01:04:31,075 AUDIENCE: [INAUDIBLE] 963 01:04:34,710 --> 01:04:36,980 PROFESSOR: Yes, so [INAUDIBLE] even 964 01:04:36,980 --> 01:04:41,388 though [INAUDIBLE] delta t [INAUDIBLE] 0.2 [INAUDIBLE] 965 01:04:41,388 --> 01:04:46,380 kind of goes right through the exact derivative. 966 01:04:46,380 --> 01:04:50,950 OK, so this is how a second order scheme is better 967 01:04:50,950 --> 01:04:53,140 than a first order scheme. 968 01:04:53,140 --> 01:04:55,890 And how to assess that? 969 01:04:55,890 --> 01:05:00,810 Taylor analysis, right? 970 01:05:00,810 --> 01:05:05,540 OK, maybe I will just show you how 971 01:05:05,540 --> 01:05:07,670 did I get the certain order. 972 01:05:07,670 --> 01:05:11,020 So if I further extend this, [INAUDIBLE] what I get 973 01:05:11,020 --> 01:05:18,832 is the d square u dt times delta t squared over 2, right? 974 01:05:18,832 --> 01:05:25,250 [INAUDIBLE] squared over 2 and then plus the cube. 975 01:05:25,250 --> 01:05:31,870 Here, what I get is plus d square u dt times 976 01:05:31,870 --> 01:05:34,310 minus delta t square, which is the same as delta t 977 01:05:34,310 --> 01:05:38,080 square, over two plus this to the cube. 978 01:05:38,080 --> 01:05:40,880 And you can see when I subtract the u of t 979 01:05:40,880 --> 01:05:46,070 plus delta t by u [INAUDIBLE] delta t, the [INAUDIBLE] order 980 01:05:46,070 --> 01:05:47,690 term cancel. 981 01:05:47,690 --> 01:05:50,750 The first order term, because they are the same, 982 01:05:50,750 --> 01:05:53,280 so they add together. 983 01:05:53,280 --> 01:05:57,390 And the second order term also cancel. 984 01:05:57,390 --> 01:06:00,690 The third order term again is going to have different signs 985 01:06:00,690 --> 01:06:05,250 and subtracting them actually makes them bigger. 986 01:06:05,250 --> 01:06:06,990 So it is order two. 987 01:06:06,990 --> 01:06:11,390 So here, I can modify this to delta t cube 988 01:06:11,390 --> 01:06:14,550 because the square term actually cancel each other. 989 01:06:14,550 --> 01:06:18,740 And here is going to be square. 990 01:06:18,740 --> 01:06:23,410 All right, and we see that by actually observing 991 01:06:23,410 --> 01:06:25,520 the increased accuracy. 992 01:06:28,740 --> 01:06:35,310 OK, so let's-- we have a little bit of time. 993 01:06:35,310 --> 01:06:38,260 Let's actually start the contest. 994 01:06:38,260 --> 01:06:41,710 And I would actually not end it today. 995 01:06:41,710 --> 01:06:45,780 I would have you start it today and maybe we'll 996 01:06:45,780 --> 01:06:50,000 come back and report your findings in the beginning 997 01:06:50,000 --> 01:06:52,980 of the next lecture. 998 01:06:52,980 --> 01:06:58,260 All right, so the concept is like this. 999 01:06:58,260 --> 01:07:03,420 I want the best X scheme. 1000 01:07:03,420 --> 01:07:06,470 How do I [INAUDIBLE] my best? 1001 01:07:06,470 --> 01:07:11,160 The highest local order of accuracy-- OK, 1002 01:07:11,160 --> 01:07:12,220 what does that mean? 1003 01:07:12,220 --> 01:07:20,110 I want to o delta t to as high power as possible, right? 1004 01:07:20,110 --> 01:07:23,160 OK, and the X-- what does X mean? 1005 01:07:23,160 --> 01:07:26,690 X means one of these-- one of these four. 1006 01:07:26,690 --> 01:07:31,180 And I'd like you to form a eteam with one person or two 1007 01:07:31,180 --> 01:07:34,500 other persons and commit to either one, two, 1008 01:07:34,500 --> 01:07:43,620 or three or four and figure out how do you 1009 01:07:43,620 --> 01:07:49,319 design a scheme to make it as accurate as possible. 1010 01:07:49,319 --> 01:07:50,194 AUDIENCE: [INAUDIBLE] 1011 01:07:57,530 --> 01:08:02,310 PROFESSOR: OK, so I'm going to give you the formula now. 1012 01:08:02,310 --> 01:08:06,040 Best implicit one step scheme means 1013 01:08:06,040 --> 01:08:13,280 I want u at [INAUDIBLE] so u as i plus 1. 1014 01:08:13,280 --> 01:08:17,670 Or let me actually use u [INAUDIBLE] 1015 01:08:17,670 --> 01:08:29,517 t plus delta t equal to something times du dt at t 1016 01:08:29,517 --> 01:08:32,960 plus delta t plus something times 1017 01:08:32,960 --> 01:08:39,080 u at t plus something times du dt at t. 1018 01:08:39,080 --> 01:08:42,729 All right, this is the best implicit one step 1019 01:08:42,729 --> 01:08:44,479 scheme and your task is to figure out 1020 01:08:44,479 --> 01:08:45,800 what teh questions are. 1021 01:08:49,140 --> 01:08:54,109 OK, best explicit two step scheme-- it means this. 1022 01:08:58,729 --> 01:09:03,130 It means you add t plus delta t has 1023 01:09:03,130 --> 01:09:07,430 to equal to-- because it is explicit, 1024 01:09:07,430 --> 01:09:11,590 it does not allow a derivative [INAUDIBLE] order t. 1025 01:09:11,590 --> 01:09:15,270 So you have to do a question mark of ut 1026 01:09:15,270 --> 01:09:20,250 plus a question mark at du dt at t. 1027 01:09:20,250 --> 01:09:24,120 And now, because it's two step, two step 1028 01:09:24,120 --> 01:09:27,740 means I allow one more step to be 1029 01:09:27,740 --> 01:09:32,910 used in determining the solution t plus delta t, which 1030 01:09:32,910 --> 01:09:38,370 means I can use u at t minus delta t 1031 01:09:38,370 --> 01:09:44,689 and du dt at t minus delta t. 1032 01:09:44,689 --> 01:09:48,260 All right, so this is the degrees of freedom 1033 01:09:48,260 --> 01:09:53,740 you have in your best explicit two step scheme. 1034 01:09:53,740 --> 01:09:56,880 And what is the difference between explicit two step 1035 01:09:56,880 --> 01:09:59,315 scheme and an implicit two step scheme? 1036 01:10:11,510 --> 01:10:18,280 Yes, the answer is you can use du dt at t plus delta t. 1037 01:10:18,280 --> 01:10:20,510 So I'm going to circle the term that 1038 01:10:20,510 --> 01:10:24,895 makes a scheme implicit-- right, so implicit. 1039 01:10:28,630 --> 01:10:31,130 So with the implicit scheme, you are 1040 01:10:31,130 --> 01:10:37,645 allowed to use u plus delta t equal to-- the increased term 1041 01:10:37,645 --> 01:10:42,900 is a question mark times du dt at t plus delta t. 1042 01:10:42,900 --> 01:10:48,050 If I don't have this term, it will be explicit. 1043 01:10:48,050 --> 01:10:50,520 All the other terms are the same-- question mark times 1044 01:10:50,520 --> 01:10:56,828 ut times question mark times du dt at t plus question mark 1045 01:10:56,828 --> 01:11:01,863 u at t minus delta t plus question mark times 1046 01:11:01,863 --> 01:11:05,780 du dt at t minus delta t. 1047 01:11:05,780 --> 01:11:11,550 So let's just choose between the three-- the first three 1048 01:11:11,550 --> 01:11:14,090 options. 1049 01:11:14,090 --> 01:11:21,080 OK, and time is over, but I'd like you to find a team mate. 1050 01:11:21,080 --> 01:11:28,238 Commit to one of these axes and come up with an answer. 1051 01:11:28,238 --> 01:11:32,920 And we'll star to discuss this in the next lecture.