CHAPTER 08.04: RUNGE-KUTTA 4TH ORDER METHOD: Formulas

 

 

In this segment, we'll look at the formulas for the Runge-Kutta fourth-order method of solving ordinary differential equations. Runge-Kutta fourth-order method is based on the first five terms of the Taylor series.  So actually let's go ahead and see that what we are trying to solve in the first place.  So we're trying to solve a first-order ordinary differential equation which is of this particular form, with the initial condition given at 0, and what we want to do is we want to be able to find the dependent variable, y, as a function of x, numerically to do so.  What Runge-Kutta fourth-order method does is that it takes the first five terms of the Taylor series.  So if you look at the first five terms of the Taylor series, they will look like this, y-sub-i-plus-1 is equal to yi, that means that if you want to find the value at y at some point, then you need to know the value at some other point, plus you need to know the value of the derivative at that particular point, times the difference between the point where you are and where you are trying to go, plus the second derivative of y with respect to x, 1 by 2 factorial, then multiplied by the square of the difference between the two points, where you are and where you want to go, plus two more terms, you will have the third derivative term of y with respect to x, and it'll be cube of the difference between the point where you are and where you want to go, and 1 by 4 factorial, d4y by . . . fourth derivative of y with respect to x calculated at the point xi, yi, and x-sub-i-plus-1 minus xi, whole to the power 4, plus order of the xi-plus-1 minus xi, raised to the power 5 terms which you'll have.  So what Runge-Kutta fourth-order method does, as opposed to second-order method, in second-order method, you take the first three terms of  the Taylor series expansion, and you equate it to what Runge-Kutta assumed to be the formula for numerically solving a differential equation of this particular form. Now, in Runge-Kutta fourth-order method, all we are doing is, since it is going from second- to fourth-order, we're adding two more terms of the Taylor series to be able to see what we get. So if, since dy by dx is the value of . . . is same as the function of x, comma, y, this f of x, comma, y, then I can substitute for dy by dx, I can substitute the value of f in here.  So let's see what do I get from there. I get y-sub-i-plus-1 is equal to yi, plus the value of the function at xi, yi, times the distance between the point where I am to the point where I'm going, so I'll call x-sub-i-plus-1 minus xi to be h, and the next term will be 1 by factorial 2, f prime calculated at xi, comma, yi, times h, keep in mind that y is a dependent function of x, so when you calculate the f prime, you will have to use some kind of a chain rule to do that, 1 by factorial 3, f double-prime at the point where you are, times h squared, so I'll get h squared here, h cubed here, and then the last term which we . . . fifth term which we had talked about is f triple-prime calculated at xi, comma, yi, h to the power 4.  So you can very well see that if I want to take the first five terms of the Taylor series to develop the fourth-order method for solving a differential equation, I do need to take the first derivative of f, the second derivative of f, and the third derivative of f, which means that I'll have to do those symbolically.  What Runge and Kutta did was that they assumed the formula to be of this form, y-sub-i-plus-1 is equal to yi, plus a1 k1 plus a2 k2 plus a3 k3 plus a4 k4, times h, that's what they assumed it to be, and what they did was they equated this form to this form here, and I'm not showing you the proof for that, and they can up with a formula which is based on . . . which is this formula here, but where you are not required to calculate the first derivative of f, or the second derivative of f, or the third derivative of f, you are just calculating the values of the function at certain . . . function, f, at just certain points.  What I mean by that is that, let's look at one of the versions of the Runge-Kutta fourth-order method, which is called the RK4 method.  This one was developed by Runge himself. I'll show you another formula which was developed by Kutta in a little bit.  So we've got RK4 method, in this case, what are the values of a1, a2, and so on and so forth?  This is what they came up with, y-sub-i-plus-1 is equal to yi, plus k1 plus 2 k2 plus 2 k3 plus k4, times h, that's what they came up with.  So they came up with this particular formula for the value of the y-sub-i-plus-1 in terms of yi and these values of k1, k2, k3, and k4.  You can see that these are simply going to be slopes, k1, k2, k3, k4, you are giving weightage of 1, 2, 2, 1 here, and dividing by 6. So what are the values of k1, k2, k3, and k4?  They are nothing but k1 is given as the value of the function, f, at xi, comma, yi. k2 is given as the value of the function at xi plus 1/2 h, yi plus 1/2 k1 h.  k3 is given as the value of the function at xi plus 1/2 h, so it's halfway between the point where you are and the point where you are going, and yi plus 1/2 k2 h.  And k4, which is the last value in the formula, is calculated as xi plus h, which is the value of the function, now, at the point where we want to be, yi plus k3 h.  So you can see that, in this particular RK4 formula method which you are seeing here, we don't need to calculate the first derivative, second derivative, or third derivative, or any derivative of the function, f, we just have to calculate the value of the function, f, at certain specific points, and then simply substitute those slopes of the . . . of y as a function of x, because f is simply your dy by dx into this particular formula, and get the value of the y at a point ahead.  Now, just like in second-order method, there are several versions of Runge-Kutta fourth-order as well. This is a method which Kutta came up with, which is the second author of the Runge-Kutta method.  Kutta came up with a similar formula, which is as follows, y-sub-i-plus-1 is equal to yi, plus 1/8, k1 plus 3 k2 plus 3 k3 plus k4, times h.  So it looks like a very similar formula, just like you had for the RK4 method, but you have slopes here for k1, k2, k3, and k4, this gets 3 times the weightage, and that's why it's 1 plus 3 plus 3 plus 1 is 8, and gets divided by 8, but what are the individual values of k1?  They're as follows, k1 is the value of the function at the point where we are. k2 is the value of the function 1/3 away from where we are, so we have to have the corresponding value of y at that particular point.  k3 is the value of the function at xi plus now 2/3 away, so 1/3 away, 2/3 away, so we've got to have a corresponding value of . . . corresponding value of y at that particular point, which is yi minus 1/3 h k1 plus h k2.  And then k4 is equal to the value of the function at the point where you want to be, which is xi plus h, and the value of y is calculated by using this formula. So it's a very similar formula to what we had for the RK4 method, the only difference is that the values of the function, f, for k1, k2, k3, and k4 are simply calculated at different points, and the values, corresponding values of ys are calculated differently, and you are giving the weightage of 3 to this value of k2, weightage of 3 to this value of k3, 1 to this k4, and 1 to this k1, and hence you are able to obtain the value of the y at the point ahead.  So very similar to the RK4 method, this was the one which was established by Kutta.  And that's the end of this segment.