1 00:00:03,904 --> 00:00:06,780 PROFESSOR: A Very important property of a numerical method 2 00:00:06,780 --> 00:00:08,730 is its order. 3 00:00:08,730 --> 00:00:13,550 The accuracy of the method is proportional to a power 4 00:00:13,550 --> 00:00:15,230 of the step size. 5 00:00:15,230 --> 00:00:19,160 And that power is called the order. 6 00:00:19,160 --> 00:00:22,540 If h is the step size and p is the order, 7 00:00:22,540 --> 00:00:27,300 then the error made in one step is 8 00:00:27,300 --> 00:00:31,450 proportional to h to the p plus 1. 9 00:00:31,450 --> 00:00:37,160 And the error made in traversing an entire interval is 10 00:00:37,160 --> 00:00:41,680 proportional to H to the p. 11 00:00:41,680 --> 00:00:45,350 So this means, if you're using a method of order p, 12 00:00:45,350 --> 00:00:48,390 and cut the step size in half, you 13 00:00:48,390 --> 00:00:53,000 can expect the overall error to be reduced by a factor of 2 14 00:00:53,000 --> 00:00:53,670 to the p. 15 00:00:57,750 --> 00:01:03,610 The order of a numerical method is determined by analysis 16 00:01:03,610 --> 00:01:08,160 involving Taylor series during the derivation of the method. 17 00:01:08,160 --> 00:01:13,820 But we can also do an experiment to determine the order. 18 00:01:13,820 --> 00:01:15,870 That's what this program does. 19 00:01:15,870 --> 00:01:20,050 The input is the name of an ODE solver. 20 00:01:20,050 --> 00:01:24,970 And then it's going to do a numerical integration 21 00:01:24,970 --> 00:01:28,940 of an ordinary differential equation, just involving t. 22 00:01:28,940 --> 00:01:32,760 So the result is the value of an integral. 23 00:01:32,760 --> 00:01:38,700 The integral of 1 over 1 plus t squared, from 0 to 1. 24 00:01:38,700 --> 00:01:41,890 We know the exact answer is 1/2. 25 00:01:41,890 --> 00:01:47,470 So we integrate that differential equation twice, 26 00:01:47,470 --> 00:01:51,350 once with a step size of 0.1, and then with a step 27 00:01:51,350 --> 00:01:55,100 size of one half that. 28 00:01:55,100 --> 00:01:57,410 We integrate the differential equation, 29 00:01:57,410 --> 00:02:02,690 take the final value of y for each of those two integrations, 30 00:02:02,690 --> 00:02:06,120 compare those values with the exact answer, 31 00:02:06,120 --> 00:02:08,770 take the ratio of those two values. 32 00:02:08,770 --> 00:02:12,980 That shows how much the error is decreased when 33 00:02:12,980 --> 00:02:16,040 we cut the step size in half. 34 00:02:16,040 --> 00:02:20,100 The log base 2 of that ratio is the order. 35 00:02:20,100 --> 00:02:23,340 It should be an integer so we can round it to the nearest 36 00:02:23,340 --> 00:02:27,575 integer, and return that value as the value in this function. 37 00:02:32,000 --> 00:02:35,095 Let's run our experiment first on ODE1. 38 00:02:37,910 --> 00:02:45,010 We step size of 0.1, this method gets the integral as 0.5389, 39 00:02:45,010 --> 00:02:46,420 not very accurate. 40 00:02:46,420 --> 00:02:51,280 Cut the step size in half, it gets 0.5191. 41 00:02:51,280 --> 00:02:53,750 The ratio of those is two. 42 00:02:53,750 --> 00:02:56,250 Logarithm base 2 is 1. 43 00:02:56,250 --> 00:03:00,340 So ODE1 has order 1. 44 00:03:04,600 --> 00:03:09,620 Now ODE2-- step size 0.1. 45 00:03:09,620 --> 00:03:11,210 0.499. 46 00:03:11,210 --> 00:03:14,930 cut it in half, 0.4998. 47 00:03:14,930 --> 00:03:18,590 The ratio of those is close to 4. 48 00:03:18,590 --> 00:03:24,655 And so ODE2, we find with this experiment, is getting order 2. 49 00:03:29,970 --> 00:03:32,270 Now let's try classical Runge-Kutta. 50 00:03:34,880 --> 00:03:36,740 This is why it's so popular. 51 00:03:36,740 --> 00:03:38,600 It's very accurate. 52 00:03:38,600 --> 00:03:43,120 We step size of 0.1, we get close to 1/2. 53 00:03:43,120 --> 00:03:48,310 Cut the step size in half, we get even closer. 54 00:03:48,310 --> 00:03:52,760 The ratio of these two is close to 16. 55 00:03:52,760 --> 00:03:55,570 To the log base 2 is 4. 56 00:03:55,570 --> 00:04:01,300 So ODE4 has, experimentally, order 4. 57 00:04:01,300 --> 00:04:05,680 So we found that, at least with this single experiment, 58 00:04:05,680 --> 00:04:13,340 the ODE solvers 1, 2, and 4, have orders 1, 2, and 4. 59 00:04:13,340 --> 00:04:16,160 So as you probably realized, this 60 00:04:16,160 --> 00:04:19,750 is why we named them ODE 1, 2, and 4. 61 00:04:24,440 --> 00:04:29,130 This brings us to the naming conventions in the functions 62 00:04:29,130 --> 00:04:31,550 in the MATLAB ODE suite. 63 00:04:31,550 --> 00:04:34,380 All the functions have names that are 64 00:04:34,380 --> 00:04:36,190 variations on the theme ODEpq. 65 00:04:39,090 --> 00:04:47,520 That means that the method ODEpq uses methods of order p and q 66 00:04:47,520 --> 00:04:54,180 So we've been getting a glimpse of that with our names, ODE 1, 67 00:04:54,180 --> 00:04:55,005 2, and 4. 68 00:05:00,620 --> 00:05:02,830 Here's an exercise. 69 00:05:02,830 --> 00:05:06,540 Modify order x to do further experiments involving 70 00:05:06,540 --> 00:05:09,990 the order of our ODE solvers. 71 00:05:09,990 --> 00:05:13,530 Change it to do other integrals. 72 00:05:13,530 --> 00:05:19,710 And check out the order of ODE 1, 2, and 4.