CHAPTER 08.03: RUNGE-KUTTA 2ND ORDER METHOD: Formulas
In this segment, we're going to talk about the formulas for the Runge-Kutta second-order method. So these are three different methods which are used under the Runge-Kutta second-order method to solve ordinary differential equations of the first-order. So we're going to talk about just the formulas in this segment here. So again, let me refresh the memory that we are trying to solve the differential equation which is of this form. So it is a first-order ordinary differential equation of this particular form, and the general formula for the Runge-Kutta second-order method is given as this, that you want to calculate the value of y at a step ahead, will be given by the value of y at the point where you are, plus a1 times k1, plus a2 times k2, times h, where k1 is equal to the value of the function at the point where you are, and k2 is the value of the function at some point ahead, which is given by xi plus p1 times h, yi plus q11 k1 times h. So the beauty of using the Runge-Kutta second-order method as follows is that we don't have to find out the derivative of this function f anymore. So we can still get the second-order accuracy is our Runge-Kutta second-order method by simply calculating the value of the function at these points. However, the question arises that we do need to know what a1 is, what a2 is, what p1 is, and what q11 is, because if we don't know what those values are, then we won't be able to use this formula properly. Now, what Runge did was they took this particular expression and equated it to the second-order . . . the first three terms of the Taylor series expansion for y, and that's in a separate segment, and what they found out is that they got three equations, they got a1 plus a2 equal to 1, a2 p1 is equal to 1/2, and a2 q11 is equal to 1/2, so that's what they obtained, they obtained three equations, but we have four unknowns, keep in mind we have a1, a2, p1, and q11, which are the four unknowns, but if you are able to meet the conditions of these three equations, then you have achieved your second-order accuracy as per Runge-Kutta second-order method. So that's the reason why we have several different methods of Runge-Kutta second-order method, because you have three equations and four unknowns, that means that one of the choices can be made by you. So there are some three popular choices which people use, and the first popular choice comes under the Heun's method. In the Heun's method, what you are doing is you are choosing a2 equal to 1/2. So if you choose a2 equal to 1/2, then a1 plus a2 equal to 1 will give you a1 is equal to 1/2. The second equation, a2 p1 is equal to 1, will give you . . . 1/2, will give you p1 is equal to . . . it will give you p1 is equal to 1. And then the last equation, which is a2 q11 equal to 1/2, and that will give you q11 is equal to 1 also. So if you are just looking at that, then the equations which you are writing for the Heun's method, which is part of the Runge-Kutta second-order method, will look like this, since a1 is 1/2, k1, plus 1/2 k2, times h, because a1 is 1/2, and a2 is 1/2, and then your values for k1 will turn out to be the value of the function at xi, comma, yi, and what is the value of k2 now? It will be xi plus p1 times h, because since p1 is 1, so it will be just h, yi plus q11, q11 is 1, that's 1, plus k1 times h. So that's what you get as the Heun's method, so that's what you are doing in the Heun's method. Now, you can very well see that, from a physical point of view, what you are basically doing in the Heun's method is that you are calculating the value of the slope at the point where you are, and then you are calculating the value of the slope where you want to go, which is xi plus h, which is the same as xi-plus-1, and then what you are doing in the Heun's method is that you're taking the average of the two slopes, because you're giving half the weightage to the slope at this point, and half the weightage for the slope at this particular point, and then you are multiplying by h. So that's the difference between Heun's method and your Euler's method, that you are giving some value to the slope at xi, and the slope at xi plus h, you give equal weightage to it, half and half, and that's what you are using the calculate the new value of y. Let's look at the other methods which are there. So you've got midpoint method. In the midpoint method, a different value of a2 is chosen, a2 is chosen as 1. So if a2 is chosen as 1, we go back to our two equations which we had, we had a1 plus a2 equal to 1, that will simply give you a1 is equal to 0. The next equation is a2 p1 is equal to 1, and that'll give you p1 is equal to 1. And then . . . sorry, 1/2, so that'll give p1 is equal to 1/2. And then we have a2 q11 equal to 1/2, and since a2 is equal to 1, q11 will be also 1/2. So if we substitute these values back into the general formula for the Runge-Kutta second-order method, this is what we're going to get, we're going to get y-sub-i-plus-1 is equal to yi, plus, since a1 is 0 and a2 is 1, I'm going to simply get k2 times h, and where, again, k1 is nothing but the value of the function at the point where you are, and k2 is the value of the function now at xi plus p1, p1 is 1/2 times h, and yi plus q11 is 1/2, times k1 times h. So again, what you are finding out here is that it is some way of finding the slope of the function, of the dependent variable, which is being used in the midpoint method. Now, you are using k2, and k2 is simply the value of the slope, some approximate value of the slope, at the point which is somewhere in between xi and x-sub-i-plus-1, because it's exactly 1/2 h away from the point where you are, so it is, that's why it's called the midpoint rule, because the slope which you are calculating is at the middle of xi and x-sub-i-plus-1. So you want an xi here, this is x-sub-i-plus-1, and you're calculating the slope right in the middle right there, so that's why it's called the midpoint method. Now, some people might say that, hey, if you look at this particular formula here, it has only k2 in it, k1 is not there, so why do I have to calculate k1? The reason why you have to calculate k1 is because it is used here to be able to calculate the corresponding approximate value of y at this midpoint between xi and x-sub-i-plus-1. So let's look at the last . . . last popular method which is used, which is called the Ralston's method. In the Ralston's method, what you are doing is that you're choosing a2 equal to 2/3. So when you choose a2 equal to 2/3, from your a1 plus a2 is equal to 1, you'll get a1 equal to 1/3, and a2 p1 is equal to 1/2, and from there you'll p1 is equal to 3/4, and a2 q11 is also 1/2, and since a2 is 2/3, you'll get q11 also equal to 3/4. So from here, if I substitute it back into the general Runge-Kutta second-order method, I'm going to get y-sub-i-plus-1 is equal to yi, plus a1, which is 1/3, k1, plus a2, which is 2/3, k2, times h, where k1 is equal to the value of the function at xi, comma, yi, and k2 is the value of the function at xi, plus p1 times h, p1 is 3/4, 3 by 4 h, yi plus q11, which is 3/4 k1 times h. So again, the same argument goes here, that what you are doing is that you are giving 1/3 of the weightage of the slope to the . . . to the value of f at the point where you are, and you're giving 2/3 weightage to the value of this slope, or the value of the slope of y, or f at 3/4 away from the point where you are. So again, all these methods which you are talking about, they're all based on giving some weightage to the slopes at different points, but you have to calculate what those slopes are, and that's why you need some approximate values of y to calculate this slope. So here, for example, you are trying to calculate the value of the function, or the slope of y with respect to x at this point, so you do need an approximate value of y, which is given by this particular quantity here, and then you are giving 1/3 weightage to k1 and 2/3 weightage to k2, and that's how you are able to calculate the value of the function at some point ahead. So these are the three most popular formulas for the Runge-Kutta second-order method, and in the next segment, we'll use them to do an example. And that's the end of this segment. |