1 00:00:20,000 --> 00:00:33,665 The topic for today is -- Today we're going to talk, 2 00:00:33,665 --> 00:00:36,200 I'm postponing the linear equations to next time. 3 00:00:36,200 --> 00:00:40,220 Instead, I think it's a good idea, since in real life, 4 00:00:40,220 --> 00:00:42,375 most of the differential equations 5 00:00:42,375 --> 00:00:46,315 are solved by numerical methods to introduce you to those right 6 00:00:46,315 --> 00:00:46,815 away. 7 00:00:46,815 --> 00:00:49,444 Even when you see the compute where 8 00:00:49,444 --> 00:00:53,333 you saw the computer screen, the solutions being drawn. 9 00:00:53,333 --> 00:00:55,444 Of course, what really was happening 10 00:00:55,444 --> 00:00:59,000 was that the computer was calculating the solutions 11 00:00:59,000 --> 00:01:03,000 numerically, and plotting the points. 12 00:01:03,000 --> 00:01:05,000 So, this is the main way, numerically, 13 00:01:05,000 --> 00:01:09,000 it is the main way differential equations are actually solved, 14 00:01:09,000 --> 00:01:12,000 if they are of any complexity at all. 15 00:01:12,000 --> 00:01:15,000 So, the problem is, that initial value problem, 16 00:01:15,000 --> 00:01:18,744 let's write up the first order problem the way 17 00:01:18,744 --> 00:01:21,125 we talked about it on Wednesday. 18 00:01:21,125 --> 00:01:24,665 And now, I'll specifically add to that, the starting point 19 00:01:24,665 --> 00:01:28,428 that you used when you did the computer experiments. 20 00:01:28,428 --> 00:01:32,900 And, I'll write the starting point this way. 21 00:01:32,900 --> 00:01:35,000 So, y of x0 should be y0. 22 00:01:35,000 --> 00:01:38,500 So, this is the initial condition, 23 00:01:38,500 --> 00:01:42,400 and this is the first order differential equation. 24 00:01:42,400 --> 00:01:45,776 And, as you know, the two of them 25 00:01:45,776 --> 00:01:49,500 together are called an IVP, an initial value problem, 26 00:01:49,500 --> 00:01:52,000 which means two things, the differential 27 00:01:52,000 --> 00:01:55,500 equation and the initial value that you 28 00:01:55,500 --> 00:01:59,180 want to start the solution at. 29 00:01:59,180 --> 00:02:05,000 Okay, now, the method we are going to talk about, 30 00:02:05,000 --> 00:02:08,666 the basic method of which many others 31 00:02:08,666 --> 00:02:14,000 are merely refinements in one way or another, 32 00:02:14,000 --> 00:02:16,856 is called Euler's method. 33 00:02:16,856 --> 00:02:22,000 Euler, who did, of course, everything in analysis, 34 00:02:22,000 --> 00:02:26,250 as far as I know, didn't actually 35 00:02:26,250 --> 00:02:32,000 use it to compute solutions of differential equations. 36 00:02:32,000 --> 00:02:36,000 His interest was theoretical. 37 00:02:36,000 --> 00:02:40,000 He used it as a method of proving the existence theorem, 38 00:02:40,000 --> 00:02:42,664 proving that solutions existed. 39 00:02:42,664 --> 00:02:46,500 But, nowadays, it's used to calculate the solutions 40 00:02:46,500 --> 00:02:47,000 numerically. 41 00:02:47,000 --> 00:02:51,000 And, the method is very simple to describe. 42 00:02:51,000 --> 00:02:53,331 It's so naive that you probably think 43 00:02:53,331 --> 00:02:56,500 that if you that living 300 years ago, 44 00:02:56,500 --> 00:03:00,875 you would have discovered it and covered yourself 45 00:03:00,875 --> 00:03:04,000 with glory for all eternity. 46 00:03:04,000 --> 00:03:07,000 So, here is our starting point, (x0, y0). 47 00:03:07,000 --> 00:03:10,000 Now, what information do we have? 48 00:03:10,000 --> 00:03:14,444 At that point all we have is the little line element, whose 49 00:03:14,444 --> 00:03:18,000 slope is given by f of (x, y). 50 00:03:18,000 --> 00:03:22,248 So, if I start the solution, the only way 51 00:03:22,248 --> 00:03:24,744 the solution could possibly go would 52 00:03:24,744 --> 00:03:28,664 be to start off in that direction, since I 53 00:03:28,664 --> 00:03:30,714 have no other information. 54 00:03:30,714 --> 00:03:36,000 At least it has the correct direction at (x0, y0). 55 00:03:36,000 --> 00:03:40,750 But, of course, it's not likely to have the correct direction 56 00:03:40,750 --> 00:03:41,500 anywhere else. 57 00:03:41,500 --> 00:03:45,304 Now, what you do, then, is choose a step size. 58 00:03:45,304 --> 00:03:48,500 I'll try just two steps of the method. 59 00:03:48,500 --> 00:03:50,856 That's, I think, good enough. 60 00:03:50,856 --> 00:03:55,000 Choose a uniform step size, which is usually called h. 61 00:03:55,000 --> 00:03:57,768 And, you continue that solution until you 62 00:03:57,768 --> 00:04:03,142 get to the next point, which will be x0 + h, as I've 63 00:04:03,142 --> 00:04:06,000 drawn it on the picture. 64 00:04:06,000 --> 00:04:07,500 So, we get to here. 65 00:04:07,500 --> 00:04:09,900 We stop at that point, and now you 66 00:04:09,900 --> 00:04:12,000 recalculate what the line element is here. 67 00:04:12,000 --> 00:04:16,712 Suppose, here, the line element, now, through this point 68 00:04:16,712 --> 00:04:18,000 goes like that. 69 00:04:18,000 --> 00:04:20,400 Well, then, that's the new direction 70 00:04:20,400 --> 00:04:23,665 that you should start out with going from here. 71 00:04:23,665 --> 00:04:28,178 And so, the next step of the process will carry you to here. 72 00:04:28,178 --> 00:04:30,500 That's two steps of Euler's method. 73 00:04:30,500 --> 00:04:36,000 Notice it produces a broken line approximation to the solution. 74 00:04:36,000 --> 00:04:39,000 But, in fact, you only see that broken line 75 00:04:39,000 --> 00:04:43,000 if you are at a computer if you are looking at the computer 76 00:04:43,000 --> 00:04:47,000 visual, for example, whose purpose is to illustrate 77 00:04:47,000 --> 00:04:48,712 for you Euler's method. 78 00:04:48,712 --> 00:04:51,500 In actual practice, what you see is, 79 00:04:51,500 --> 00:04:53,500 the computer is simply calculating 80 00:04:53,500 --> 00:04:57,570 this point, that point, and the succession of points. 81 00:04:57,570 --> 00:04:59,555 And, many programs will just automatically 82 00:04:59,555 --> 00:05:04,000 connect those points by a smooth looking curve 83 00:05:04,000 --> 00:05:08,000 if that's what you prefer to see. 84 00:05:08,000 --> 00:05:11,000 Well, that's all there is to the method. 85 00:05:11,000 --> 00:05:15,375 What we have to do now is derive the equations for the method. 86 00:05:15,375 --> 00:05:18,375 Now, how are we going to do that? 87 00:05:18,375 --> 00:05:23,724 Well, the essence of it is how to get from the nth step 88 00:05:23,724 --> 00:05:26,375 to the n plus first step? 89 00:05:26,375 --> 00:05:30,816 So, I'm going to draw a picture just to illustrate that. 90 00:05:30,816 --> 00:05:34,000 So, now we are not at x0. 91 00:05:34,000 --> 00:05:37,375 But let's say we've already gotten to (xn, yn). 92 00:05:37,375 --> 00:05:40,000 How do I take the next step? 93 00:05:40,000 --> 00:05:43,330 Well, I take the line element, and it goes up 94 00:05:43,330 --> 00:05:47,000 like that, let's say, because the slope is this. 95 00:05:47,000 --> 00:05:51,000 I'm going to call that slope A sub n. 96 00:05:51,000 --> 00:05:55,329 Of course, A sub n is the value of the right hand side 97 00:05:55,329 --> 00:05:59,400 at the point (xn, yn), and we will need that in the equation, 98 00:05:59,400 --> 00:06:05,304 -- -- but I think it will be a little bit clearer if I just 99 00:06:05,304 --> 00:06:08,285 give it a capital letter at this point. 100 00:06:08,285 --> 00:06:12,178 Now, this is the new point, and all I want to know 101 00:06:12,178 --> 00:06:14,000 is what are its coordinates? 102 00:06:14,000 --> 00:06:17,000 Well, the x n plus one is there. 103 00:06:17,000 --> 00:06:19,000 The y n plus one is here. 104 00:06:19,000 --> 00:06:21,664 Clearly I should draw this triangle, 105 00:06:21,664 --> 00:06:23,000 complete the triangle. 106 00:06:23,000 --> 00:06:27,000 This side of the triangle, the hypotenuse has slope An. 107 00:06:27,000 --> 00:06:30,000 This side of the triangle has length h. 108 00:06:30,000 --> 00:06:31,665 h is the step size. 109 00:06:31,665 --> 00:06:33,500 Perhaps I'd better indicate that, 110 00:06:33,500 --> 00:06:39,000 actually put that up so that you know the word step. 111 00:06:39,000 --> 00:06:41,856 It's the step size on the x axis, 112 00:06:41,856 --> 00:06:47,000 how far you have to go to get from each x to the next one. 113 00:06:47,000 --> 00:06:48,000 What's this? 114 00:06:48,000 --> 00:06:53,000 Well, if that slope has this, the slope An, this is h. 115 00:06:53,000 --> 00:06:58,000 Then this must be h times An, the length of that side, 116 00:06:58,000 --> 00:07:02,224 in order that the ratio of the height to this width 117 00:07:02,224 --> 00:07:03,571 should be An. 118 00:07:03,571 --> 00:07:07,000 And, that gives us the method. 119 00:07:07,000 --> 00:07:13,332 How do I get from, clearly, to get from xn to x n plus one, 120 00:07:13,332 --> 00:07:16,000 I simply add h. 121 00:07:16,000 --> 00:07:19,000 So, that's the trivial part of it. 122 00:07:19,000 --> 00:07:25,452 The interesting thing is, how do I get the new y n plus one? 123 00:07:25,452 --> 00:07:30,331 And so, the best way to write it as, that y n plus one 124 00:07:30,331 --> 00:07:32,800 minus yn divided by h, well, sorry, 125 00:07:32,800 --> 00:07:40,662 y n plus one minus yn is this line, the same as the line 126 00:07:40,662 --> 00:07:43,000 h times An. 127 00:07:43,000 --> 00:07:45,331 So, that's the way to write it. 128 00:07:45,331 --> 00:07:48,875 Or, since the computer is interested in calculating 129 00:07:48,875 --> 00:07:54,178 y n plus one itself, put this on the other side. 130 00:07:54,178 --> 00:07:57,089 You take the old yn, the previous one, 131 00:07:57,089 --> 00:08:00,000 and to it, you add h times An. 132 00:08:00,000 --> 00:08:04,000 And, what, pray tell, is An? 133 00:08:04,000 --> 00:08:09,664 Well, the computer has to be told that An is the value of f. 134 00:08:09,664 --> 00:08:11,888 So, now, with that, let's actually 135 00:08:11,888 --> 00:08:15,000 write the Euler program, not the program, 136 00:08:15,000 --> 00:08:19,000 but the Euler-- the Euler method equations, 137 00:08:19,000 --> 00:08:22,000 let's just call it the Euler equations. 138 00:08:22,000 --> 00:08:23,140 What will they be? 139 00:08:23,140 --> 00:08:28,000 First of all, the new x is the old x plus h. 140 00:08:28,000 --> 00:08:31,000 The new y is just what I've written there, 141 00:08:31,000 --> 00:08:38,000 the old y plus h times a certain number, An, and finally, 142 00:08:38,000 --> 00:08:44,332 An has the value-- It's the slope of the line element here, 143 00:08:44,332 --> 00:08:50,000 and therefore by definition, that's f of (xn,yn). 144 00:08:50,000 --> 00:08:55,000 So, if these three equations which define Euler's method. 145 00:08:55,000 --> 00:09:00,000 I assume in 1.00 you must be asked to, at some point, 146 00:09:00,000 --> 00:09:04,576 as an exercise in the term at one point to program 147 00:09:04,576 --> 00:09:09,500 the computer in C or whatever they're using, Java, now, 148 00:09:09,500 --> 00:09:14,000 I guess, to do Euler's method. 149 00:09:14,000 --> 00:09:18,662 And, these would be the recursive equations 150 00:09:18,662 --> 00:09:23,816 that you would put in to do that. 151 00:09:23,816 --> 00:09:27,625 Okay, let's try an example, then. 152 00:09:27,625 --> 00:09:33,200 So, what would be a good color for Euler? 153 00:09:33,200 --> 00:09:35,000 Well, a purple. 154 00:09:35,000 --> 00:09:38,330 I assume nobody can see purple. 155 00:09:38,330 --> 00:09:40,000 Is that correct? 156 00:09:40,000 --> 00:09:46,000 Can anyone in the back of the room see that that's purple? 157 00:09:46,000 --> 00:09:46,666 Okay. 158 00:09:46,666 --> 00:09:48,000 Sit closer. 159 00:09:48,000 --> 00:09:50,400 So, let's calculate. 160 00:09:50,400 --> 00:09:56,000 The example, I'll use a simple example, 161 00:09:56,000 --> 00:10:00,000 but it's not entirely trivial. 162 00:10:00,000 --> 00:10:02,000 My example is going to be the equation, 163 00:10:02,000 --> 00:10:07,000 x squared minus y squared on the right hand side. 164 00:10:07,000 --> 00:10:10,750 And, let's start with y of zero equals one, let's say. 165 00:10:10,750 --> 00:10:14,000 And so, this is my initial value problem, 166 00:10:14,000 --> 00:10:16,000 that pair of equations. 167 00:10:16,000 --> 00:10:18,000 And, I have to specify a step size. 168 00:10:18,000 --> 00:10:20,000 So, let's take the step size to 0.1. 169 00:10:20,000 --> 00:10:24,000 You choose the step size, or the computer does. 170 00:10:24,000 --> 00:10:27,000 We'll have to talk about that in a few minutes. 171 00:10:27,000 --> 00:10:28,815 Now, what do you do? 172 00:10:28,815 --> 00:10:33,500 Well, I say this is a nontrivial equation because this equation, 173 00:10:33,500 --> 00:10:38,500 as far as I know, cannot be solved in terms of elementary 174 00:10:38,500 --> 00:10:39,000 functions. 175 00:10:39,000 --> 00:10:41,541 So, this equation would be, in fact, 176 00:10:41,541 --> 00:10:46,000 a very good candidate for a numerical method like Euler's. 177 00:10:46,000 --> 00:10:50,428 And, you had to use it, or maybe it was the other way around, 178 00:10:50,428 --> 00:10:51,284 I forget. 179 00:10:51,284 --> 00:10:56,200 On your problem set, you drew a picture of the direction field 180 00:10:56,200 --> 00:10:59,500 and answered some questions about the isoclines, 181 00:10:59,500 --> 00:11:01,375 how the solutions behave. 182 00:11:01,375 --> 00:11:04,726 Now, the main thing I want you to get, 183 00:11:04,726 --> 00:11:07,267 this is not just for Euler's, talking 184 00:11:07,267 --> 00:11:08,500 about Euler's equations. 185 00:11:08,500 --> 00:11:10,900 But in general, for the calculations 186 00:11:10,900 --> 00:11:14,200 you have to do in this course, it's extremely important 187 00:11:14,200 --> 00:11:17,750 to be systematic because if you are not systematic, 188 00:11:17,750 --> 00:11:21,500 you know, if you just scribble, scribble, scribble, scribble, 189 00:11:21,500 --> 00:11:24,400 scribble, you can do the work, but it becomes 190 00:11:24,400 --> 00:11:25,600 impossible to find mistakes. 191 00:11:25,600 --> 00:11:28,921 You must do the work in a form in which it 192 00:11:28,921 --> 00:11:32,333 can be checked, which you can look over it and find, 193 00:11:32,333 --> 00:11:37,220 and try to see where mistakes are if, in fact, there are any. 194 00:11:37,220 --> 00:11:41,220 So, I strongly suggest, this is not a suggestion, 195 00:11:41,220 --> 00:11:46,744 this is a command, that you make a little table to do Euler's 196 00:11:46,744 --> 00:11:51,213 method by hand, I'd only ask you for a step or two, 197 00:11:51,213 --> 00:11:53,832 but since I'm just trying to make 198 00:11:53,832 --> 00:11:57,160 sure you have some idea of these equations 199 00:11:57,160 --> 00:11:59,332 and where they come from. 200 00:11:59,332 --> 00:12:03,815 So, first, the value of n, then the value of xn, 201 00:12:03,815 --> 00:12:06,768 then the value of the yn, and then, 202 00:12:06,768 --> 00:12:09,840 a couple of more columns which tell you 203 00:12:09,840 --> 00:12:11,888 how to do the calculation. 204 00:12:11,888 --> 00:12:15,999 You are going to need the value of the slope, 205 00:12:15,999 --> 00:12:18,454 and it's probably a good idea, also, 206 00:12:18,454 --> 00:12:23,000 because otherwise you'll forget it, to put in h An 207 00:12:23,000 --> 00:12:26,000 because that occurs in the formula. 208 00:12:26,000 --> 00:12:30,000 All right, let's start doing it. 209 00:12:30,000 --> 00:12:32,541 The first value of n is zero. 210 00:12:32,541 --> 00:12:34,000 That's the starting point. 211 00:12:34,000 --> 00:12:38,000 At the starting point, (x0, y0), x has the value zero, 212 00:12:38,000 --> 00:12:42,000 and y has the value one, so, zero and one. 213 00:12:42,000 --> 00:12:45,000 In other words, starting, I'm carrying out 214 00:12:45,000 --> 00:12:47,800 exactly what I drew pictorially only now 215 00:12:47,800 --> 00:12:51,664 I'm doing it arithmetically using a table 216 00:12:51,664 --> 00:12:55,000 and substituting into the formulas. 217 00:12:55,000 --> 00:13:00,000 Okay, the next thing we have to calculate is An. 218 00:13:00,000 --> 00:13:03,000 Well, since An is the value of the right hand side, 219 00:13:03,000 --> 00:13:07,000 at the point zero one, you have to plug that in. 220 00:13:07,000 --> 00:13:11,000 The right hand side is x squared minus y squared. 221 00:13:11,000 --> 00:13:14,000 So, it's 0 squared minus 1 squared. 222 00:13:14,000 --> 00:13:20,000 The value of the slope, there, is minus one, negative one. 223 00:13:20,000 --> 00:13:22,000 Now, I have to multiply that by H. 224 00:13:22,000 --> 00:13:22,999 h is 0.1. 225 00:13:22,999 --> 00:13:25,452 So, it's negative, I'll never learn that. 226 00:13:25,452 --> 00:13:28,333 The way you learn to talk in kindergarten 227 00:13:28,333 --> 00:13:33,250 is the way you learn to talk the rest of your life, 228 00:13:33,250 --> 00:13:34,500 unfortunately. 229 00:13:34,500 --> 00:13:38,800 In kindergarten, we said minus. 230 00:13:38,800 --> 00:13:40,000 Negative 0.1. 231 00:13:40,000 --> 00:13:42,220 n is one now. 232 00:13:42,220 --> 00:13:45,000 What's the value of xn? 233 00:13:45,000 --> 00:13:48,000 Well, to the old value I add 1/10. 234 00:13:48,000 --> 00:13:50,775 What's the value of y? 235 00:13:50,775 --> 00:13:56,000 Well, at this point, you have to do the calculation. 236 00:13:56,000 --> 00:13:59,000 It's the old value of y. 237 00:13:59,000 --> 00:14:06,000 To get this new value, it's the old value plus this number. 238 00:14:06,000 --> 00:14:12,816 Well, that's this plus that number is nine tenths. 239 00:14:12,816 --> 00:14:19,180 An, now I have to calculate the new slope at this point. 240 00:14:19,180 --> 00:14:25,500 Okay, that is one tenth squared minus nine tenths squared. 241 00:14:25,500 --> 00:14:38,000 That's 0.01 minus 0.81, which makes minus 0.80, I hope. 242 00:14:38,000 --> 00:14:40,270 Check it on your calculators. 243 00:14:40,270 --> 00:14:43,428 Whip them out and press the buttons. 244 00:14:43,428 --> 00:14:46,832 I now multiply that by h, which means 245 00:14:46,832 --> 00:14:51,428 it's going to be minus 0.08, perhaps with a zero after. 246 00:14:51,428 --> 00:14:55,000 I didn't tell you how many decimal places. 247 00:14:55,000 --> 00:14:59,000 Let's carry it out to two decimal places. 248 00:14:59,000 --> 00:15:03,000 I think that will be good enough. 249 00:15:03,000 --> 00:15:10,000 And finally, the last step, 2, here, add another one tenth, 250 00:15:10,000 --> 00:15:15,000 so the value of x is now two tenths. 251 00:15:15,000 --> 00:15:18,000 And finally, what's the value of y? 252 00:15:18,000 --> 00:15:22,000 Well, I didn't tell you where to stop. 253 00:15:22,000 --> 00:15:27,328 Let's stop at y of 0.2 because there's 254 00:15:27,328 --> 00:15:31,000 no more room on the blackboard. 255 00:15:31,000 --> 00:15:34,500 About approximately how big is that? 256 00:15:34,500 --> 00:15:37,816 In other words, this is, then, this 257 00:15:37,816 --> 00:15:43,800 is going to be the old y plus this number, which 258 00:15:43,800 --> 00:15:48,000 seems to be 0.82 to me. 259 00:15:48,000 --> 00:15:51,000 So, the answer is, the new value is 0.82. 260 00:15:51,000 --> 00:15:52,665 Okay, we got a number. 261 00:15:52,665 --> 00:15:55,200 We did what we are supposed to do. 262 00:15:55,200 --> 00:15:56,000 We got a number. 263 00:15:56,000 --> 00:15:57,000 Next question? 264 00:15:57,000 --> 00:16:00,000 Now, let's ask a few questions. 265 00:16:00,000 --> 00:16:02,625 One of the first, most basic things 266 00:16:02,625 --> 00:16:04,998 is, you know, how right is this? 267 00:16:04,998 --> 00:16:09,800 How can I answer such a question if I have no explicit formula 268 00:16:09,800 --> 00:16:11,000 for that solution? 269 00:16:11,000 --> 00:16:15,000 That's the basic problem with numerical calculation. 270 00:16:15,000 --> 00:16:17,400 In other words, I have to wander around 271 00:16:17,400 --> 00:16:19,800 in the dark to some extent, and yet 272 00:16:19,800 --> 00:16:24,000 have some idea when I've arrived at the place that I want to go. 273 00:16:24,000 --> 00:16:28,000 Well, the first question I'd like to answer, 274 00:16:28,000 --> 00:16:30,800 is this too high or too low? 275 00:16:30,800 --> 00:16:36,000 Is Euler, sorry, he'll forgive me in heaven, I will use him. 276 00:16:36,000 --> 00:16:38,500 By this, I mean, is the result, let 277 00:16:38,500 --> 00:16:43,375 me just say something first, and that I'll criticize it. 278 00:16:43,375 --> 00:16:46,000 Is Euler too high or too low? 279 00:16:46,000 --> 00:16:50,333 In other words, is the result of using Euler's method, 280 00:16:50,333 --> 00:16:53,428 i.e. is this number too high or too low? 281 00:16:53,428 --> 00:16:58,500 Is it higher than the right answer, what it should be? 282 00:16:58,500 --> 00:17:02,750 Or, is it lower than the right answer? 283 00:17:02,750 --> 00:17:06,776 Or, God forbid, is it exactly right? 284 00:17:06,776 --> 00:17:09,600 Well, it's almost never exactly right. 285 00:17:09,600 --> 00:17:12,000 That's not an option. 286 00:17:12,000 --> 00:17:16,000 Now, how will we answer that question? 287 00:17:16,000 --> 00:17:19,000 Well, let's answer it geometrically. 288 00:17:19,000 --> 00:17:24,454 Basically, if the solution were a straight line, then 289 00:17:24,454 --> 00:17:29,000 the Euler method would be exactly right all the time. 290 00:17:29,000 --> 00:17:31,775 But, it's not a line. 291 00:17:31,775 --> 00:17:34,000 Then it's a curve. 292 00:17:34,000 --> 00:17:38,000 Well, the critical question is, is it curved? 293 00:17:38,000 --> 00:17:39,284 Is the solution? 294 00:17:39,284 --> 00:17:41,000 So, here's a solution. 295 00:17:41,000 --> 00:17:44,600 Let's call it y1 of x, and let's say 296 00:17:44,600 --> 00:17:46,776 here was the starting point. 297 00:17:46,776 --> 00:17:49,000 Here, the solution is convex. 298 00:17:49,000 --> 00:17:52,000 And, here the solution is concave, right? 299 00:17:52,000 --> 00:17:57,000 Concave up or concave down, if you learn those words, 300 00:17:57,000 --> 00:18:01,000 but I think those have, by now, I hope pretty well 301 00:18:01,000 --> 00:18:03,000 disappeared from the curriculum. 302 00:18:03,000 --> 00:18:06,888 Call it, if you haven't up until now, 303 00:18:06,888 --> 00:18:10,000 what mathematicians call it, convex is that, 304 00:18:10,000 --> 00:18:11,632 and the other one is concave. 305 00:18:11,632 --> 00:18:13,400 Well, how do Euler's solutions look? 306 00:18:13,400 --> 00:18:15,000 Well, I'll just sketch. 307 00:18:15,000 --> 00:18:18,684 I think from this you can see already, when you start out 308 00:18:18,684 --> 00:18:22,000 on the Euler's solution, it's going to go like that. 309 00:18:22,000 --> 00:18:23,500 Now you are too low. 310 00:18:23,500 --> 00:18:25,900 Well, let's suppose after that, the line element 311 00:18:25,900 --> 00:18:29,998 here is approximately the same as what it is there, 312 00:18:29,998 --> 00:18:32,000 or roughly parallel. 313 00:18:32,000 --> 00:18:34,000 After all, they are not too far apart. 314 00:18:34,000 --> 00:18:37,000 And, the direction field is continuous. 315 00:18:37,000 --> 00:18:39,331 That is, the directions don't change drastically 316 00:18:39,331 --> 00:18:40,900 from one point to another. 317 00:18:40,900 --> 00:18:43,333 But now, you see it's still too low. 318 00:18:43,333 --> 00:18:47,284 It's even lower as it pathetically tries to follow. 319 00:18:47,284 --> 00:18:50,125 It's losing territory, and that's basically 320 00:18:50,125 --> 00:18:52,000 because the curve is convex. 321 00:18:52,000 --> 00:18:53,800 Exactly the opposite what would happen 322 00:18:53,800 --> 00:18:59,284 if the curve were concave, if the solution curve were 323 00:18:59,284 --> 00:19:00,000 concave. 324 00:19:00,000 --> 00:19:02,904 Now it's too high, and it's not going 325 00:19:02,904 --> 00:19:07,632 to be able to correct that as long as the solution 326 00:19:07,632 --> 00:19:09,000 curve stays concave. 327 00:19:09,000 --> 00:19:13,000 Well, that's probably too optimistic. 328 00:19:13,000 --> 00:19:15,220 It's probably more like this. 329 00:19:15,220 --> 00:19:21,000 So, in other words, in this case, if the curve is convex, 330 00:19:21,000 --> 00:19:25,000 Euler is going to be too high, sorry, too low. 331 00:19:25,000 --> 00:19:28,125 Let's put E for Euler. 332 00:19:28,125 --> 00:19:30,000 How about that? 333 00:19:30,000 --> 00:19:31,140 Euler is too low. 334 00:19:31,140 --> 00:19:34,500 If it's concave, then Euler is too high. 335 00:19:34,500 --> 00:19:36,000 Okay, that's great. 336 00:19:36,000 --> 00:19:40,000 There's just one little problem left, namely, 337 00:19:40,000 --> 00:19:44,000 if we don't have a formula for the solution, 338 00:19:44,000 --> 00:19:47,178 and we don't have a computer that's 339 00:19:47,178 --> 00:19:51,270 busy drawing the picture for us, in which case 340 00:19:51,270 --> 00:19:54,583 we wouldn't need any of this anyway, 341 00:19:54,583 --> 00:20:01,000 how are we supposed to tell if it's convex or concave? 342 00:20:01,000 --> 00:20:02,284 Back to calculus. 343 00:20:02,284 --> 00:20:04,000 Calculus to the rescue! 344 00:20:04,000 --> 00:20:05,665 When is a curve convex? 345 00:20:05,665 --> 00:20:09,089 A curve is convex if its second derivative is positive 346 00:20:09,089 --> 00:20:13,713 because the first to be convex means the first derivative is 347 00:20:13,713 --> 00:20:16,000 increasing all the time. 348 00:20:16,000 --> 00:20:18,000 And therefore, the second derivative, 349 00:20:18,000 --> 00:20:22,000 which is the derivative of the first derivative, 350 00:20:22,000 --> 00:20:23,284 should be positive. 351 00:20:23,284 --> 00:20:26,000 Just the opposite here; the curve, 352 00:20:26,000 --> 00:20:29,000 the slope is, the first derivative, 353 00:20:29,000 --> 00:20:33,000 is decreasing all the time and therefore the second derivative 354 00:20:33,000 --> 00:20:34,000 is negative. 355 00:20:34,000 --> 00:20:39,500 So, all we have to do is decide what the second derivative 356 00:20:39,500 --> 00:20:41,000 of the solution is. 357 00:20:41,000 --> 00:20:43,000 We should probably call it a solution. 358 00:20:43,000 --> 00:20:46,000 y of x is a little too vague. 359 00:20:46,000 --> 00:20:49,000 y1 means the solution started at this point. 360 00:20:49,000 --> 00:20:51,625 So, in fact, probably it would have 361 00:20:51,625 --> 00:20:54,856 been better from the beginning to call that y1, except there's 362 00:20:54,856 --> 00:20:57,000 no room, y1, let's say. 363 00:20:57,000 --> 00:20:59,800 That means the solution which started out 364 00:20:59,800 --> 00:21:01,750 at the point, (0, 1). 365 00:21:01,750 --> 00:21:05,332 So, I'm still talking about at a solution like that. 366 00:21:05,332 --> 00:21:08,855 All right, so I want to know if this is positive, 367 00:21:08,855 --> 00:21:12,220 the second derivative is positive at the starting point, 368 00:21:12,220 --> 00:21:14,000 zero, or it's negative. 369 00:21:14,000 --> 00:21:17,000 Now, again, how you can regulate the second derivative, 370 00:21:17,000 --> 00:21:20,000 if you don't know what the solution is explicitly, 371 00:21:20,000 --> 00:21:24,070 then the answer is you can do it from the differential equation 372 00:21:24,070 --> 00:21:24,570 itself. 373 00:21:24,570 --> 00:21:26,000 How do I do that? 374 00:21:26,000 --> 00:21:30,250 Well: easy. y prime equals x squared minus y squared. 375 00:21:30,250 --> 00:21:34,416 Okay, that tells me how to calculate 376 00:21:34,416 --> 00:21:39,000 y prime if I know the value of x and y, 377 00:21:39,000 --> 00:21:41,000 in other words, the 0.01. 378 00:21:41,000 --> 00:21:45,000 What would be the value of y double prime? 379 00:21:45,000 --> 00:21:48,000 Well, differentiate the equation. 380 00:21:48,000 --> 00:21:52,000 It's two x minus two y y prime. 381 00:21:52,000 --> 00:21:55,000 Don't forget to use the chain rule. 382 00:21:55,000 --> 00:22:00,000 So, if I want to calculate at (0, 1), in other words, 383 00:22:00,000 --> 00:22:04,000 if my starting point is that curve convex or concave, 384 00:22:04,000 --> 00:22:10,000 well, let's calculate. y of zero equals one. 385 00:22:10,000 --> 00:22:12,000 Okay, what's y prime of zero? 386 00:22:12,000 --> 00:22:16,000 Well, I don't have to repeat that calculation. 387 00:22:16,000 --> 00:22:18,333 Using this, I've already calculated 388 00:22:18,333 --> 00:22:20,000 that it was negative one. 389 00:22:20,000 --> 00:22:24,000 And now, the new thing, what's y double prime of zero? 390 00:22:24,000 --> 00:22:26,000 Well, it is this. 391 00:22:26,000 --> 00:22:27,200 I'll write it out. 392 00:22:27,200 --> 00:22:31,000 It's two times zero minus two times negative y, which is one, 393 00:22:31,000 --> 00:22:36,000 two times one times y prime, which is negative one. 394 00:22:36,000 --> 00:22:43,400 You want to see we are pulling ourselves up by our own boot 395 00:22:43,400 --> 00:22:45,000 straps, which is impossible. 396 00:22:45,000 --> 00:22:49,000 But, it is not impossible because we are doing it. 397 00:22:49,000 --> 00:22:50,712 So, what's the answer? 398 00:22:50,712 --> 00:22:54,000 Zero here, two, I've calculated without having 399 00:22:54,000 --> 00:23:00,270 the foggiest idea of what the solution is or how it looks. 400 00:23:00,270 --> 00:23:03,571 I've calculated that its second derivative 401 00:23:03,571 --> 00:23:07,000 at the starting point is two. 402 00:23:07,000 --> 00:23:13,000 Therefore, my solution is convex at the starting point. 403 00:23:13,000 --> 00:23:17,000 And therefore, this Euler approximation, 404 00:23:17,000 --> 00:23:22,000 if I don't carry it out too far, will be too low. 405 00:23:22,000 --> 00:23:25,000 So, it's convex Euler, too low. 406 00:23:25,000 --> 00:23:32,000 Now, you could argue, yeah, well, what about this? 407 00:23:32,000 --> 00:23:36,000 [LAUGHTER] So, you could go like this, 408 00:23:36,000 --> 00:23:39,000 and then you can see it catches up. 409 00:23:39,000 --> 00:23:45,875 Well, of course, if the curve changes from convex to concave, 410 00:23:45,875 --> 00:23:52,125 then it's really impossible to make any prediction at all. 411 00:23:52,125 --> 00:23:54,000 That's a difficulty. 412 00:23:54,000 --> 00:24:02,000 So, all this analysis is only if you stay very nearby. 413 00:24:02,000 --> 00:24:04,763 However, I wanted to show you, the main purpose 414 00:24:04,763 --> 00:24:08,496 of it in my mind was to show you how 415 00:24:08,496 --> 00:24:11,000 do you use, it's these equations, 416 00:24:11,000 --> 00:24:14,000 how to use the differential equation itself to get 417 00:24:14,000 --> 00:24:17,885 information about the solutions, without actually being 418 00:24:17,885 --> 00:24:20,500 able to calculate the solutions? 419 00:24:20,500 --> 00:24:23,888 Now, so that's the method, and that's 420 00:24:23,888 --> 00:24:27,000 how to find out something about it. 421 00:24:27,000 --> 00:24:32,000 And now, what I'd like to talk about is errors. 422 00:24:32,000 --> 00:24:34,000 How do I handle, right? 423 00:24:34,000 --> 00:24:38,500 So, in a sense, I've started the error analysis. 424 00:24:38,500 --> 00:24:43,600 In other words, the error, by definition, the error 425 00:24:43,600 --> 00:24:46,000 is this difference, e. 426 00:24:46,000 --> 00:24:50,000 So, in other words, what I'm asking here, 427 00:24:50,000 --> 00:24:52,000 is the error positive? 428 00:24:52,000 --> 00:24:55,816 It depends which we measure it. 429 00:24:55,816 --> 00:24:59,571 Usually, you take this minus that. 430 00:24:59,571 --> 00:25:04,000 So, here, the error would be considered positive, 431 00:25:04,000 --> 00:25:07,600 and here it would be considered negative, 432 00:25:07,600 --> 00:25:13,908 although I'm sure there's a book somewhere in the world, which 433 00:25:13,908 --> 00:25:15,270 does the opposite. 434 00:25:15,270 --> 00:25:20,080 Most hedge by just using the absolute value of the error 435 00:25:20,080 --> 00:25:23,888 plus a statement that the method is producing answers 436 00:25:23,888 --> 00:25:27,000 which are too low or too high. 437 00:25:27,000 --> 00:25:30,714 The question, then, is, naturally, this 438 00:25:30,714 --> 00:25:35,000 is not the world's best method. 439 00:25:35,000 --> 00:25:36,750 It's not as bad as it seems. 440 00:25:36,750 --> 00:25:39,600 It's not the world's best method because that convexity 441 00:25:39,600 --> 00:25:42,600 and concavity means that you are automatically 442 00:25:42,600 --> 00:25:45,000 introducing a systematic error. 443 00:25:45,000 --> 00:25:47,565 If you can predict which way the error is 444 00:25:47,565 --> 00:25:50,250 going to be by just knowing whether the curve is 445 00:25:50,250 --> 00:25:52,665 convex or concave, it's not what you want. 446 00:25:52,665 --> 00:25:55,250 I mean, you want to at least have 447 00:25:55,250 --> 00:25:57,000 a chance of getting the right answer, 448 00:25:57,000 --> 00:25:59,800 whereas this is telling you you're definitely 449 00:25:59,800 --> 00:26:01,750 going to get the wrong answer. 450 00:26:01,750 --> 00:26:04,332 All it tells you is, and it's telling you 451 00:26:04,332 --> 00:26:09,000 whether your answer is going to be too high or too low. 452 00:26:09,000 --> 00:26:14,220 We've like a better chance of getting the right answer. 453 00:26:14,220 --> 00:26:20,227 Now, so the question is, how do you get a better method? 454 00:26:20,227 --> 00:26:23,600 A search is for a better method. 455 00:26:23,600 --> 00:26:26,888 Now, the first method, which will 456 00:26:26,888 --> 00:26:31,665 occur, I'm sure, to anyone who looks at that picture, 457 00:26:31,665 --> 00:26:36,000 is, look, if you want this yellow line 458 00:26:36,000 --> 00:26:40,000 to follow the white one, the white solution, 459 00:26:40,000 --> 00:26:43,000 more accurately, for heaven's sake, 460 00:26:43,000 --> 00:26:47,375 don't take such big steps. 461 00:26:47,375 --> 00:26:54,908 Take small steps, and then it will follow better. 462 00:26:54,908 --> 00:27:00,000 All right, let's draw a picture. 463 00:27:00,000 --> 00:27:02,000 Excuse me. 464 00:27:02,000 --> 00:27:08,000 My little box of treasures, here. 465 00:27:08,000 --> 00:27:13,000 [LAUGHTER] So, use a smaller step size. 466 00:27:13,000 --> 00:27:18,332 And the picture, roughly, which is going to justify that, 467 00:27:18,332 --> 00:27:21,000 will look like this. 468 00:27:21,000 --> 00:27:24,328 If the solution curve looks like this, then 469 00:27:24,328 --> 00:27:29,500 with a big step size, I'm liable to have 470 00:27:29,500 --> 00:27:33,000 something that looks like that. 471 00:27:33,000 --> 00:27:36,072 But, if I take a smaller step size, 472 00:27:36,072 --> 00:27:38,333 suppose I halve the step size. 473 00:27:38,333 --> 00:27:40,428 How's it going to look, then? 474 00:27:40,428 --> 00:27:44,000 Well, I better switch to a different color. 475 00:27:44,000 --> 00:27:50,000 If I halve the step size, I'll get a littler, goes like that. 476 00:27:50,000 --> 00:27:52,500 And now it's following closer. 477 00:27:52,500 --> 00:27:55,714 Of course, I'm stacking the deck, 478 00:27:55,714 --> 00:28:00,000 but see how close it follows? 479 00:28:00,000 --> 00:28:02,000 I'm definitely not to be trusted on this. 480 00:28:02,000 --> 00:28:05,000 Okay, let's do the opposite, make really big steps. 481 00:28:05,000 --> 00:28:06,500 Suppose instead of the yellow ones 482 00:28:06,500 --> 00:28:09,125 I used the green one of double step size. 483 00:28:09,125 --> 00:28:11,400 Well, what would have happened then? 484 00:28:11,400 --> 00:28:15,000 Well, I've started out, but now I've gone all the way to there. 485 00:28:15,000 --> 00:28:17,000 And now, on my way up, of course, 486 00:28:17,000 --> 00:28:19,125 it has a little further to go. 487 00:28:19,125 --> 00:28:22,000 But, if for some reason, I stop there, you could see, 488 00:28:22,000 --> 00:28:23,250 I would be still lower. 489 00:28:23,250 --> 00:28:29,000 In other words, the bigger the steps size, the more the error. 490 00:28:29,000 --> 00:28:33,000 And, where are the errors that we are talking about? 491 00:28:33,000 --> 00:28:36,744 Well, the way to think of the errors, this 492 00:28:36,744 --> 00:28:39,776 is the error, that number the error. 493 00:28:39,776 --> 00:28:42,555 You can make it positive, negative, 494 00:28:42,555 --> 00:28:48,713 or just put it automatically an absolute value sign around it. 495 00:28:48,713 --> 00:28:51,000 That's not so important. 496 00:28:51,000 --> 00:28:53,568 So, in other words, the conclusion 497 00:28:53,568 --> 00:28:57,330 is, that the error e, the difference 498 00:28:57,330 --> 00:29:01,496 between the true value that I should have gotten, 499 00:29:01,496 --> 00:29:05,332 and the Euler value that the calculation produced, 500 00:29:05,332 --> 00:29:10,500 that the error e, depends on the step size. 501 00:29:10,500 --> 00:29:14,856 Now, how does it depend on the step size? 502 00:29:14,856 --> 00:29:18,284 Well, it's impossible to give an exact formula, 503 00:29:18,284 --> 00:29:20,999 but there's an approximate answer, which is, 504 00:29:20,999 --> 00:29:22,400 by and large, true. 505 00:29:22,400 --> 00:29:27,000 So, the answer is, e is going to be a function of h. 506 00:29:27,000 --> 00:29:28,500 What function? 507 00:29:28,500 --> 00:29:31,776 Well, asymptotically, which is another way 508 00:29:31,776 --> 00:29:35,200 of putting quotation marks around, what did I say? 509 00:29:35,200 --> 00:29:40,000 It's going to be a constant, some constant, times H. 510 00:29:40,000 --> 00:30:14,220 [LAUGHTER] It looks like this, and for this reason 511 00:30:14,220 --> 00:30:21,000 it's called a first order, the Euler is a first order method. 512 00:30:21,000 --> 00:30:26,918 And now, first order does not refer to the first order 513 00:30:26,918 --> 00:30:29,714 of the differential equation. 514 00:30:29,714 --> 00:30:35,776 It's not the first order because it's y prime 515 00:30:35,776 --> 00:30:38,000 equals f of (x, y). 516 00:30:38,000 --> 00:30:41,856 The first order means the fact that h 517 00:30:41,856 --> 00:30:44,000 occurs to the first power. 518 00:30:44,000 --> 00:30:46,912 The way people usually say this is 519 00:30:46,912 --> 00:30:50,332 since the normal way of decreasing the step size, 520 00:30:50,332 --> 00:30:54,500 as you'll see as is you try to use a computer 521 00:30:54,500 --> 00:30:58,000 visual that deals with the Euler method, 522 00:30:58,000 --> 00:31:01,108 which I highly recommend, by the way, 523 00:31:01,108 --> 00:31:04,499 so highly recommended that you have to do it, 524 00:31:04,499 --> 00:31:12,000 is that the way to say it, each new step halves the step size. 525 00:31:12,000 --> 00:31:16,305 That's the usual way to do it. 526 00:31:16,305 --> 00:31:23,180 If you halve the step size, since this is a constant, 527 00:31:23,180 --> 00:31:33,000 if I halve the step size, I halve the error, approximately. 528 00:31:33,000 --> 00:31:36,000 Halve the step size, halve the error. 529 00:31:36,000 --> 00:31:40,905 That tells you how the error varies with step 530 00:31:40,905 --> 00:31:44,000 size for Euler's method. 531 00:31:44,000 --> 00:31:47,875 Please understand, that's what people 532 00:31:47,875 --> 00:31:52,428 say, and please understand the grammatical construction. 533 00:31:52,428 --> 00:31:56,636 Since everyone in the math department 534 00:31:56,636 --> 00:32:03,000 has a cold these days except me for the moment, 535 00:32:03,000 --> 00:32:09,000 everyone goes around chanting this mantra. 536 00:32:09,000 --> 00:32:11,284 This is totally irrelevant. 537 00:32:11,284 --> 00:32:15,000 This whole mantra, feed a cold, starve a fever. 538 00:32:15,000 --> 00:32:18,200 And if you asked them what it means, 539 00:32:18,200 --> 00:32:21,999 they say eat a lot if you have a cold. 540 00:32:21,999 --> 00:32:25,815 And if you have a fever, don't eat very much, which 541 00:32:25,815 --> 00:32:29,000 is not what it means at all. 542 00:32:29,000 --> 00:32:33,000 Grammatically, it's exactly the same construction as this. 543 00:32:33,000 --> 00:32:37,000 What this means is if you halve the step size, 544 00:32:37,000 --> 00:32:38,500 you will halve the error. 545 00:32:38,500 --> 00:32:41,600 That's what feed a cold, starve a fever means. 546 00:32:41,600 --> 00:32:44,750 And, remember this for the rest of your life. 547 00:32:44,750 --> 00:32:48,850 If you feed a cold, if you eat too much when you have a cold, 548 00:32:48,850 --> 00:32:53,600 you will get a fever and end up still having to starve yourself 549 00:32:53,600 --> 00:32:57,000 because, of course, nobody, when you have a fever, 550 00:32:57,000 --> 00:33:02,000 nobody feels like eating, so they don't eat anything. 551 00:33:02,000 --> 00:33:05,330 All right, you got that? 552 00:33:05,330 --> 00:33:06,000 Good. 553 00:33:06,000 --> 00:33:14,000 I want all of you to go home and tell that to your mothers. 554 00:33:14,000 --> 00:33:21,000 You know, that's the way we always used to speak. 555 00:33:21,000 --> 00:33:25,666 Grimmer ones: spare the rod, spoil 556 00:33:25,666 --> 00:33:33,750 the child does not mean that you should not hit your kid. 557 00:33:33,750 --> 00:33:40,665 It means that if you fail to hit your kid, 558 00:33:40,665 --> 00:33:45,800 he or she will be spoiled, whatever that means. 559 00:33:45,800 --> 00:33:50,000 So, you don't want to do that. 560 00:33:50,000 --> 00:33:56,000 I guess the mantra today would be, I don't know. 561 00:33:56,000 --> 00:34:00,081 Okay, so the first line of defense 562 00:34:00,081 --> 00:34:05,500 is simply to keep having the step size in Euler. 563 00:34:05,500 --> 00:34:10,100 And, what people do is, if they don't want to use anything 564 00:34:10,100 --> 00:34:13,904 better than Euler's method, is you keep having the step size 565 00:34:13,904 --> 00:34:16,665 until the curve doesn't seem to change anymore. 566 00:34:16,665 --> 00:34:20,000 And then you say, well, that must be the solution. 567 00:34:20,000 --> 00:34:22,921 And, I asked you on the problems set, how much would 568 00:34:22,921 --> 00:34:26,571 you continue to have to halve the step size in order 569 00:34:26,571 --> 00:34:30,000 for that good thing to happen? 570 00:34:30,000 --> 00:34:33,330 However, there are more efficient methods 571 00:34:33,330 --> 00:34:36,000 which get the results faster. 572 00:34:36,000 --> 00:34:39,571 So if that's our good method, let's 573 00:34:39,571 --> 00:34:43,000 call this our still better method. 574 00:34:43,000 --> 00:34:47,000 The better methods aim at being better. 575 00:34:47,000 --> 00:34:51,000 They keep the same idea as Euler's method, 576 00:34:51,000 --> 00:34:56,600 but they say, look, let's try to improve that slope, An. 577 00:34:56,600 --> 00:35:00,776 In other words, since the slope, An, that we start with 578 00:35:00,776 --> 00:35:05,000 is guaranteed to be wrong if the curve is convex or concave, 579 00:35:05,000 --> 00:35:06,875 can we somehow correct it? 580 00:35:06,875 --> 00:35:10,000 So, for example, instead of immediately aiming there, 581 00:35:10,000 --> 00:35:13,632 can't we somehow aim it so that by luck, we just, 582 00:35:13,632 --> 00:35:17,000 at the next step just lands us back on the curve again? 583 00:35:17,000 --> 00:35:20,666 In other words, with sort of looking for the short path, 584 00:35:20,666 --> 00:35:22,997 a shortcut path, which by good luck 585 00:35:22,997 --> 00:35:25,800 will end us up back on the curve again. 586 00:35:25,800 --> 00:35:29,000 And, all the simple improvements on the Euler method, 587 00:35:29,000 --> 00:35:32,284 and they are the most stable in ways 588 00:35:32,284 --> 00:35:34,714 to solve differential equations numerically, 589 00:35:34,714 --> 00:35:39,000 aim at finding a better slope. 590 00:35:39,000 --> 00:35:43,000 So, they find a better value for a better slope, 591 00:35:43,000 --> 00:35:45,496 find a better value than An. 592 00:35:45,496 --> 00:35:49,000 Try to improve that slope that you found. 593 00:35:49,000 --> 00:35:54,625 Now, once you have the idea that you should look for a better 594 00:35:54,625 --> 00:35:59,000 slope, it's not very difficult to see what, in fact, 595 00:35:59,000 --> 00:36:00,332 you should try. 596 00:36:00,332 --> 00:36:04,332 Again, I think most of you would say, hey, 597 00:36:04,332 --> 00:36:07,000 I would have thought of that. 598 00:36:07,000 --> 00:36:09,541 And, you would be closer in time, 599 00:36:09,541 --> 00:36:11,614 since these methods were only found 600 00:36:11,614 --> 00:36:15,625 about around the turn of the last century is when I place 601 00:36:15,625 --> 00:36:19,375 them, mostly by some German mathematicians 602 00:36:19,375 --> 00:36:22,000 interested in solving equations numerically. 603 00:36:22,000 --> 00:36:25,000 All right, so what is the better method? 604 00:36:25,000 --> 00:36:29,666 Our better slope, what should we look for in our better slope? 605 00:36:29,666 --> 00:36:34,500 Well, the simplest procedure is, once again, we 606 00:36:34,500 --> 00:36:38,080 are starting from there, and the Euler slope would 607 00:36:38,080 --> 00:36:41,000 be the same as a line element. 608 00:36:41,000 --> 00:36:44,000 So, the line element looks like this. 609 00:36:44,000 --> 00:36:47,200 And, our yellow slope, A, and I'll still 610 00:36:47,200 --> 00:36:51,000 continue to call it An, goes like that, gets to here. 611 00:36:51,000 --> 00:36:55,000 Okay, now if it were convex, if the curve were convex, 612 00:36:55,000 --> 00:36:57,140 this would be too low. 613 00:36:57,140 --> 00:36:59,815 And therefore, the next step would be, 614 00:36:59,815 --> 00:37:03,875 I'm going to draw this next step in pink. 615 00:37:03,875 --> 00:37:08,800 Well, let's continue in here, would be going up like that. 616 00:37:08,800 --> 00:37:11,332 I'll call this Bn, just because it's 617 00:37:11,332 --> 00:37:14,000 the next step of Euler's method. 618 00:37:14,000 --> 00:37:19,000 It could be called An prime or something like that. 619 00:37:19,000 --> 00:37:20,200 But this will do. 620 00:37:20,200 --> 00:37:24,800 And now what you do is, let me put an arrow on it 621 00:37:24,800 --> 00:37:28,500 to indicate parallelness, go back to the beginning, 622 00:37:28,500 --> 00:37:31,000 draw this parallel to Bn. 623 00:37:31,000 --> 00:37:32,452 So, here is Bn. 624 00:37:32,452 --> 00:37:35,375 Again, just a line of that same slope. 625 00:37:35,375 --> 00:37:39,998 And now, what you should use as the simplest improvement 626 00:37:39,998 --> 00:37:45,815 on Euler's method, is take the average of these two 627 00:37:45,815 --> 00:37:48,800 because that's more likely to hit 628 00:37:48,800 --> 00:37:52,800 the curve than An will, which is sure to be 629 00:37:52,800 --> 00:37:55,712 too low if the curve is convex. 630 00:37:55,712 --> 00:37:58,200 In other words, use this instead. 631 00:37:58,200 --> 00:37:59,000 Use that. 632 00:37:59,000 --> 00:38:02,498 So, this is our better slope. 633 00:38:02,498 --> 00:38:06,285 Okay, what will we call that slope? 634 00:38:06,285 --> 00:38:08,428 We don't have to call it anything. 635 00:38:08,428 --> 00:38:11,856 What were the equations for the method be? 636 00:38:11,856 --> 00:38:17,000 Well, x n plus one is gotten by adding the step size. 637 00:38:17,000 --> 00:38:20,000 So, here's my step size just as it was before. 638 00:38:20,000 --> 00:38:23,072 Just as it was before, the new thing 639 00:38:23,072 --> 00:38:26,332 is how to get the new value of y. 640 00:38:26,332 --> 00:38:31,267 So, y n plus one should be the old yn, plus h times not 641 00:38:31,267 --> 00:38:37,000 this crummy slope, An, but the better, the pink slope. 642 00:38:37,000 --> 00:38:39,000 What's the formula for the pink slope? 643 00:38:39,000 --> 00:38:41,499 Well, let's do it in two steps. 644 00:38:41,499 --> 00:38:44,000 It's the average of An and Bn. 645 00:38:44,000 --> 00:38:48,285 Hey, but you didn't tell me, or I didn't tell you what Bn was. 646 00:38:48,285 --> 00:38:52,664 So, you now must tell the computer, oh yes, by the way, 647 00:38:52,664 --> 00:38:56,400 you remember that An was what it always was. 648 00:38:56,400 --> 00:38:59,284 The interesting thing is, what is Bn? 649 00:38:59,284 --> 00:39:03,331 Well, to get Bn, Bn is the slope of the line 650 00:39:03,331 --> 00:39:05,000 element at this new point. 651 00:39:05,000 --> 00:39:08,000 Now, what am I going to call that new point? 652 00:39:08,000 --> 00:39:12,000 I don't want to call this y value, y n plus one, 653 00:39:12,000 --> 00:39:15,500 because that's, it's this up here that's 654 00:39:15,500 --> 00:39:17,400 going to be the y n plus one. 655 00:39:17,400 --> 00:39:19,776 All this is, is a temporary value 656 00:39:19,776 --> 00:39:23,665 used to make another calculation, which will then 657 00:39:23,665 --> 00:39:27,000 be combined with the previous calculations 658 00:39:27,000 --> 00:39:29,000 to get the right value. 659 00:39:29,000 --> 00:39:31,500 Therefore, give it a temporary name. 660 00:39:31,500 --> 00:39:34,614 That point, we'll call it, it's not 661 00:39:34,614 --> 00:39:38,000 going to be the final, the real y n plus one. 662 00:39:38,000 --> 00:39:41,499 We'll call it y n plus one twiddle, y n plus one 663 00:39:41,499 --> 00:39:41,998 temporary. 664 00:39:41,998 --> 00:39:44,000 And, what's the formula for it? 665 00:39:44,000 --> 00:39:47,630 Well, it's just going to be what the original Euler 666 00:39:47,630 --> 00:39:51,192 formula; it's going to be y n plus what you would have gotten 667 00:39:51,192 --> 00:39:53,600 if you had calculated, in other words, 668 00:39:53,600 --> 00:39:56,400 it's the point that the Euler method produced, 669 00:39:56,400 --> 00:40:01,000 but it's not, finally, the point that we want. 670 00:40:01,000 --> 00:40:04,000 Now, do I have to say anything else? 671 00:40:04,000 --> 00:40:08,000 Yeah, I didn't tell the computer what Bn was. 672 00:40:08,000 --> 00:40:11,688 Okay, Bn is the slope of the direction 673 00:40:11,688 --> 00:40:15,428 field at the point n plus one. 674 00:40:15,428 --> 00:40:19,800 And the computer knows what that is. 675 00:40:19,800 --> 00:40:24,000 And, this point, y n plus one temporary. 676 00:40:24,000 --> 00:40:31,000 So, you make a temporary choice of this, calculate that number, 677 00:40:31,000 --> 00:40:34,000 and then go back, and as it were, 678 00:40:34,000 --> 00:40:39,625 correct that value to this value by using this better slope. 679 00:40:39,625 --> 00:40:44,500 Now, that's all there is to the method, 680 00:40:44,500 --> 00:40:48,000 except I didn't give you its name. 681 00:40:48,000 --> 00:40:52,000 Well, it has three names, four names in fact. 682 00:40:52,000 --> 00:40:54,664 Which one shall I give you? 683 00:40:54,664 --> 00:40:56,000 I don't care. 684 00:40:56,000 --> 00:41:00,000 Okay, the shortest name is Heun's method. 685 00:41:00,000 --> 00:41:05,000 But nobody pronounces that correctly. 686 00:41:05,000 --> 00:41:07,664 So, it's Heun's method. 687 00:41:07,664 --> 00:41:13,000 It's called, also, the Improved Euler method. 688 00:41:13,000 --> 00:41:19,000 It's called Modified Euler, very expressive word, 689 00:41:19,000 --> 00:41:21,250 Modified Euler's method. 690 00:41:21,250 --> 00:41:25,000 And, it's also called RK2. 691 00:41:25,000 --> 00:41:31,000 I'm sure you'll like that name best. 692 00:41:31,000 --> 00:41:33,000 It has a Star Wars sort of sound. 693 00:41:33,000 --> 00:41:37,576 RK stands for Runge Kutta, and the reason for the two 694 00:41:37,576 --> 00:41:42,307 is not that it uses, well, it is that it uses two slopes, 695 00:41:42,307 --> 00:41:47,000 but the real reason for the two is that it is a second order 696 00:41:47,000 --> 00:41:47,500 method. 697 00:41:47,500 --> 00:41:52,724 So, that's the most important thing to put down about it. 698 00:41:52,724 --> 00:41:57,500 It's a second order method, whereas Euler's was only 699 00:41:57,500 --> 00:42:00,000 a first order method. 700 00:42:00,000 --> 00:42:03,000 So, Heun's method, or RK2, let's write it, 701 00:42:03,000 --> 00:42:08,000 is the shortest thing to write, is a second order method, 702 00:42:08,000 --> 00:42:11,632 meaning that the error varies with the step 703 00:42:11,632 --> 00:42:15,000 size like some constant, it will not 704 00:42:15,000 --> 00:42:20,500 be the same as the constant for Euler's method, times 705 00:42:20,500 --> 00:42:22,000 h squared. 706 00:42:22,000 --> 00:42:25,227 That's a big saving because it now 707 00:42:25,227 --> 00:42:28,908 means that if you halve the step size, 708 00:42:28,908 --> 00:42:34,250 you're going to decrease the error by a factor of one 709 00:42:34,250 --> 00:42:34,875 quarter. 710 00:42:34,875 --> 00:42:38,000 You will quarter the error. 711 00:42:38,000 --> 00:42:41,142 Now, you say, hey, why should anyone use anything else? 712 00:42:41,142 --> 00:42:44,000 Well, think a little second. 713 00:42:44,000 --> 00:42:48,000 The real thing which determines how slowly one of these methods 714 00:42:48,000 --> 00:42:51,927 run is you look at the hardest step of the method 715 00:42:51,927 --> 00:42:54,452 and ask how long does the computer 716 00:42:54,452 --> 00:42:57,666 take, how many of those hardest steps are there? 717 00:42:57,666 --> 00:43:01,500 Now, the answer is, the hardest step is always 718 00:43:01,500 --> 00:43:05,452 the evaluation of the function because the functions that 719 00:43:05,452 --> 00:43:09,800 are common use are not x squared minus y squared. 720 00:43:09,800 --> 00:43:14,856 They take half a page and have, as coefficients, 721 00:43:14,856 --> 00:43:18,250 you know, ten decimal place numbers, whatever 722 00:43:18,250 --> 00:43:22,750 the engineers doing it, whatever their accuracy was. 723 00:43:22,750 --> 00:43:26,600 So, the thing that controls how long a method runs 724 00:43:26,600 --> 00:43:33,000 is how many times the slope, the function, must be evaluated. 725 00:43:33,000 --> 00:43:37,000 For Euler, I only have to evaluate it once. 726 00:43:37,000 --> 00:43:40,000 Here, I have to evaluate it twice. 727 00:43:40,000 --> 00:43:44,571 Now, roughly speaking, the number of function evaluations 728 00:43:44,571 --> 00:43:48,000 will each give you the exponent. 729 00:43:48,000 --> 00:43:52,440 The method that's called Runge Kutta fourth order 730 00:43:52,440 --> 00:43:56,000 will require four evaluations of slope, 731 00:43:56,000 --> 00:44:05,000 but the accuracy will be like h to the fourth: very accurate. 732 00:44:05,000 --> 00:44:09,863 You halve the step size, and it goes down by a factor of 733 00:44:09,863 --> 00:44:10,363 16. 734 00:44:10,363 --> 00:44:10,863 Great. 735 00:44:10,863 --> 00:44:14,000 But you had to evaluate the slope four times. 736 00:44:14,000 --> 00:44:19,000 Suppose, instead, you halve four times this thing. 737 00:44:19,000 --> 00:44:21,496 And, what would you have done? 738 00:44:21,496 --> 00:44:26,500 You would have decreased it to 1/16th to what it was. 739 00:44:26,500 --> 00:44:31,500 You still would increase the number of function evaluations 740 00:44:31,500 --> 00:44:38,200 you needed by four, and you would have decreased the error 741 00:44:38,200 --> 00:44:40,000 by a 16th. 742 00:44:40,000 --> 00:44:42,625 So, in some sense, it really doesn't 743 00:44:42,625 --> 00:44:46,600 matter whether you use a very fancy method, which requires 744 00:44:46,600 --> 00:44:48,500 more function evaluations. 745 00:44:48,500 --> 00:44:50,000 That's true. 746 00:44:50,000 --> 00:44:52,664 The error goes down faster, but you are 747 00:44:52,664 --> 00:44:55,125 having to more work to get it. 748 00:44:55,125 --> 00:44:57,000 So, anyway, nothing is free. 749 00:44:57,000 --> 00:44:59,000 Now, there is an RK4. 750 00:44:59,000 --> 00:45:02,362 I think I'll skip that, since I wouldn't 751 00:45:02,362 --> 00:45:06,000 dare to ask you any questions about it. 752 00:45:06,000 --> 00:45:08,904 But, let me just mention it, at least, 753 00:45:08,904 --> 00:45:10,600 because it's the standard. 754 00:45:10,600 --> 00:45:13,000 It uses four evaluations. 755 00:45:13,000 --> 00:45:15,800 It's the standard method, if you don't 756 00:45:15,800 --> 00:45:18,200 want to do anything fancier. 757 00:45:18,200 --> 00:45:21,000 It's rather inefficient, but it's 758 00:45:21,000 --> 00:45:23,444 very accurate, standard method, accurate, 759 00:45:23,444 --> 00:45:27,000 and you'll see when you use the programs, 760 00:45:27,000 --> 00:45:31,000 it's, in fact, a program which is drawing those curves, 761 00:45:31,000 --> 00:45:34,816 the numerical method which draws all those curves 762 00:45:34,816 --> 00:45:38,625 that you believe in on the computer screen 763 00:45:38,625 --> 00:45:41,125 is the RK4 method. 764 00:45:41,125 --> 00:45:46,000 The Runge Kutta, I should give them their names. 765 00:45:46,000 --> 00:45:49,400 Runge Kutta, fourth order method. 766 00:45:49,400 --> 00:45:53,500 Two mathematicians, I believe both German mathematicians 767 00:45:53,500 --> 00:45:58,330 around the turn of the last century, Runge Kutta 768 00:45:58,330 --> 00:46:01,875 fourth order method requires four slopes, 769 00:46:01,875 --> 00:46:05,571 requires you to calculate four slopes. 770 00:46:05,571 --> 00:46:09,500 I won't bother telling you what you do, 771 00:46:09,500 --> 00:46:11,000 but it's a procedure like that. 772 00:46:11,000 --> 00:46:14,000 It's just a little bit more elaborate. 773 00:46:14,000 --> 00:46:17,000 And you take two of these, you make up a weighted average 774 00:46:17,000 --> 00:46:18,500 for the super slope. 775 00:46:18,500 --> 00:46:20,000 You use weighted average. 776 00:46:20,000 --> 00:46:23,000 What should I divide that by to get the right...? 777 00:46:23,000 --> 00:46:24,000 Six. 778 00:46:24,000 --> 00:46:24,570 Why six? 779 00:46:24,570 --> 00:46:27,000 Well, because if all these numbers were the same, 780 00:46:27,000 --> 00:46:32,330 I'd want it to come out to be whatever that common value was. 781 00:46:32,330 --> 00:46:35,454 Therefore, in a weighted average, 782 00:46:35,454 --> 00:46:40,000 you must always divide by the sum of the coefficients. 783 00:46:40,000 --> 00:46:42,178 So, this is the super slope. 784 00:46:42,178 --> 00:46:45,332 And, if you plug that super slope into here, 785 00:46:45,332 --> 00:46:48,500 you will be using the Runge Kutta method, 786 00:46:48,500 --> 00:46:51,375 and get the best possible results. 787 00:46:51,375 --> 00:46:54,571 Now, I wanted to spend the last three 788 00:46:54,571 --> 00:46:58,600 minutes talking about pitfalls of numerical computation 789 00:46:58,600 --> 00:46:59,800 in general. 790 00:46:59,800 --> 00:47:05,332 One pitfall I am leaving you on the homework 791 00:47:05,332 --> 00:47:08,000 to discover for yourself. 792 00:47:08,000 --> 00:47:12,000 Don't worry, it won't cause you any grief. 793 00:47:12,000 --> 00:47:16,000 It'll just destroy your faith in these things 794 00:47:16,000 --> 00:47:22,000 for the rest of your life, which is probably a good thing. 795 00:47:22,000 --> 00:47:25,800 So, pitfalls, number one, you find, you'll find. 796 00:47:25,800 --> 00:47:29,725 Let me talk, instead, briefly about number two, 797 00:47:29,725 --> 00:47:34,500 which I am not giving you an exercise in. 798 00:47:34,500 --> 00:47:38,284 Number two is illustrated by the following equation. 799 00:47:38,284 --> 00:47:40,000 What could be simpler? 800 00:47:40,000 --> 00:47:44,000 This is a very bad equation to try to solve numerically. 801 00:47:44,000 --> 00:47:44,856 Now, why? 802 00:47:44,856 --> 00:47:47,250 Well, because if I separate variables, 803 00:47:47,250 --> 00:47:49,000 why don't I save a little time? 804 00:47:49,000 --> 00:47:53,000 I'll just tell you what the solution is, okay? 805 00:47:53,000 --> 00:47:55,000 You obviously separate variables. 806 00:47:55,000 --> 00:47:57,000 Maybe you can do it in your head. 807 00:47:57,000 --> 00:47:58,998 The solution will be, the solutions 808 00:47:58,998 --> 00:48:01,332 will have an arbitrary constant in them, 809 00:48:01,332 --> 00:48:03,555 and they won't be very complicated. 810 00:48:03,555 --> 00:48:08,000 They will be one over c minus x. 811 00:48:08,000 --> 00:48:12,250 C is an arbitrary constant, and as you give different values, 812 00:48:12,250 --> 00:48:15,000 you get, now, what do those guys look like? 813 00:48:15,000 --> 00:48:16,360 Okay, so here I am. 814 00:48:16,360 --> 00:48:18,200 I start out at the point, one. 815 00:48:18,200 --> 00:48:20,452 And, I start out, I tell the computer, 816 00:48:20,452 --> 00:48:23,855 compute for me the value of the solution at one 817 00:48:23,855 --> 00:48:25,000 starting out at one. 818 00:48:25,000 --> 00:48:28,000 And, it computes and computes a little while. 819 00:48:28,000 --> 00:48:31,600 But the solution, how does this curve actually look? 820 00:48:31,600 --> 00:48:38,000 So, in other words, suppose I say that y of zero equals one. 821 00:48:38,000 --> 00:48:39,875 Find me y of two. 822 00:48:39,875 --> 00:48:42,800 In other words, take a nice small step size. 823 00:48:42,800 --> 00:48:45,713 Use the Runge Kutta fourth order method. 824 00:48:45,713 --> 00:48:48,816 Calculate a little bit, and tell me, 825 00:48:48,816 --> 00:48:51,500 I just want to know what y of two is. 826 00:48:51,500 --> 00:48:53,000 Well, what is y of two? 827 00:48:53,000 --> 00:48:56,000 Well, unfortunately, how does that curve look? 828 00:48:56,000 --> 00:48:59,125 The curve looks like this. 829 00:48:59,125 --> 00:49:02,332 At that point, it drops to infinity 830 00:49:02,332 --> 00:49:05,800 in a manner of speaking, and then sort of comes back 831 00:49:05,800 --> 00:49:07,000 up again like that. 832 00:49:07,000 --> 00:49:09,400 What is the value of y? 833 00:49:09,400 --> 00:49:11,222 This is the point, one. 834 00:49:11,222 --> 00:49:13,000 What is the value of y of two? 835 00:49:13,000 --> 00:49:15,000 Is it here? 836 00:49:15,000 --> 00:49:15,855 Is it this? 837 00:49:15,855 --> 00:49:19,448 Well, I don't know, but I do know that the computer will not 838 00:49:19,448 --> 00:49:20,000 find it. 839 00:49:20,000 --> 00:49:22,724 The computer will follow this along, 840 00:49:22,724 --> 00:49:25,750 and get lost in eternity, in infinity, 841 00:49:25,750 --> 00:49:30,400 and see no reason whatever why it should start again 842 00:49:30,400 --> 00:49:34,000 on this branch of the curve. 843 00:49:34,000 --> 00:49:36,800 Okay, well, can't we predict that that's 844 00:49:36,800 --> 00:49:40,000 going to happen somehow, avoid what I should have. 845 00:49:40,000 --> 00:49:44,500 The whole difficulty is, this is called a singular point. 846 00:49:44,500 --> 00:49:49,400 The solution has a singularity, in other words, a single place 847 00:49:49,400 --> 00:49:53,726 where it goes to infinity or becomes discontinuous, maybe as 848 00:49:53,726 --> 00:49:54,815 a jump discontinuity. 849 00:49:54,815 --> 00:49:58,200 It has a singularity at x equals c. 850 00:49:58,200 --> 00:50:02,220 This, in particular, at x equals one here, 851 00:50:02,220 --> 00:50:06,725 but from the differential equation, where is that c? 852 00:50:06,725 --> 00:50:10,333 There is no way of predicting it. 853 00:50:10,333 --> 00:50:15,000 Each solution, in other words, to this differential equation, 854 00:50:15,000 --> 00:50:17,000 has its own, private singularity, 855 00:50:17,000 --> 00:50:21,400 which only it knows about, and where it's going to blow up, 856 00:50:21,400 --> 00:50:25,500 and there's no way of telling from the differential equation 857 00:50:25,500 --> 00:50:28,000 where that's going to be. 858 00:50:28,000 --> 00:50:32,000 That's one of the things that makes numerical calculation 859 00:50:32,000 --> 00:50:37,000 difficult, when you cannot predict where things are going 860 00:50:37,000 --> 00:50:39,450 to go bad in advance.