CHAPTER 08.04: RUNGE-KUTTA 4TH ORDER METHOD: Example: Part 2 of 2

 

 

Let's look at the next step, we just calculated x1, which is 1.5, and the corresponding value of y which we calculated at that particular point was 4.365.  So what we do want to do is now we want to use i equal to 1, and of course, x1 is 1.5 and y1 is 4.365, and since our h is 1.5, which is our step size, that if we take one more step, then the value of y which you will be calculating will be y2, will be at x2, which will 1.5 plus 1.5, which will give us 3, and that's what we are looking for.  So let's go ahead and calculate our k1, k2, k3, and k4 values, and then be able to calculate what y2 will be.  So k1 will be the value of the function at x1, comma, y1. x1 is 1.5, y is 4.365, and that will be equal to 3 . . . 3 e to the power minus x, which is 1.5, minus 0.4 times y, which is 4.365, and this value here turns out to be -1.076.  So that's what we get as the value of k1.  Let's go ahead and see what we get for the value of k2.  That's the value of the function at x1 plus 1/2 h, y1 plus 1/2 k1 h.  So again, we are going somewhere between . . . not somewhere, but midpoint between x1 and x2, that's where we want to calculate the value of the function, f.  xi is 1.5, h is 1.5, comma, yi, which is 4.365, calculated from the previous step, plus 1/2 k1, and k1 is -1.076, which we just calculated, times 1.5.  So the arguments of f, where we want to calculate the slope of y with respect to x, are turning out to be 2.25 and 3.557, and that gives me 3 e to the power minus x, which is 2.25, minus 0.4 times the value of y, which is 3.557, and this value here turns out to be -1.107.  So that's what we get as the value of k2.  So we have calculated k1 and k2, so let's go ahead and calculate k3 and k4 now.  k3 turns out to be the value of the function at x1 plus 1/2 h, so we're still calculating the value of the function, f, at the midpoint between x1 and x2, but we're using a refined . . . I shouldn't call it refined, but the value of k2 now for the slope in order to be able to calculate the value of y at that corresponding point.  And so that turns out to be x1 is 1.5, h is 1.5, y1 is 4.365, plus 1/2 k2 is -1.107 times 1.5.  And this turns out to be the value of the function, f, turns out to be calculated at x equal to 2.5 and y equal to 3.535.  So, having said that, the value of k3 will turn out to be 3 e to the power -x, which is 2.25, minus 0.4 times y, which is 3.535 in this case, and that turns out to be -1.098. So that's the value of k3 we are getting.  Let's go ahead and see what do we get for the value of k4, because that's the fourth value which we need to calculate to be able to calculate the value of y at x equal to 3.  k4 is now the slope of y with respect to x, calculated through the function, f, now at the point where we want to be, because it's x1 plus h, y1 plus k3 h, and x1 is 1.5, h is 1.5, y1 is 4.365 plus k3, which is -1.098, times h, which is 1.5. So the value of the function, f, which we are calculating is at the argument x equal to 3 and y equal to 2.718, that's what we are getting.  So if we want to calculate the value of the function, f, which is 3 e to the power minus x, which is 3, minus 0.4 times y, which is 2.718, and that value turns out to be -0.9379.  So we have all the values of k1, k2, k3, and k4 calculated, so that's going to allow us to find out what the value of y2 is.  So y2 is y1, plus 1 by 6, as the average slope calculated through the values of k1, k2, k3, and k4.  So this turns out to be y1, we calculated from the previous step, 4.365, please don't call the step to be an iteration, because this is not an iteration, it's a step, because you're going from one point to another, you're not refining anything.  So it's 4.365 is the value of y1, now the value of the k1, k2, and k3, which we just calculated, was -1.076 for k1, for k2 it is -1.107, then 2 times the value of k3, which turned out to be -1.098, plus the value of k4, which we just calculated as -0.9379 and this whole thing gets multiplied by h, which is 1.5. So if we go ahead and calculate this value, it turns out to be equal to 2.759. So 2.759 is the value of y2, and y2 is nothing but the value of y at x2.  So let's go ahead and write this down here.  So y2, x2 is nothing but x1 plus h, x1 was 1.5, step size was 1.5, so we know the value of x2 is 3.0. So y2 is then the value of y at x2, and x2 is nothing but 3, which we just said, and approximately we get it to be equal to 2.759, that's what we got as the value of y2, so that is the approximate value of y of 3, and that's what we are looking for . . . that's the value which we were seeking in the problem statement itself.  Let's go ahead and see that how good that value is.  The exact value for y of 3, up to four significant digits, is 2.763, and you can find this exact value by using your knowledge of ordinary differential equations course, by using either Laplace transforms, or the classical solution techniques of finding the particular solution and the complementary part, and that's what you will get, you will get y of 3 to be 2.763, up to four significant digits, so that's what's going to let us find out what the absolute relative true error is, which is the exact value, which is 2.763, minus the approximate value, which is 2.759, divided by 2.763, times 100, and this value here turns out to be 0.1507 percent.  So you're getting less than 0.15 percent true error between the exact value, which you can calculate by using your ordinary differential equations course knowledge, and Runge-Kutta fourth-order method which we used, we got 2.759.  And that is the end of this segment.