In this segment, we'll talk about the Runge-Kutta second-order method of solving
ordinary differential equations; we'll look at the theory behind it.
So, the kind of differential equations which we solve are of this form,
which is the same as the Euler's method, so nothing has changed so far as the format or the
form of the differential equation we solve. They're still first order with this format
and what we are doing in the Runge-Kutta second order method is to find a better approximation
than Euler's method. So, in order to be able to do that, what we do need to do is talk about the
application of Taylor series to derive the Runge-Kutta second-order method.
So, if you look at a general form of the Taylor series, it is given by this form here. That,
although this may not be familiar with you, to you, but it is just another form. Same form that,
hey, if I know the value of the function at a single point and I know all its values at all
its derivatives at that particular point, I can find the value of the function at any other point.
So, what we are doing here is that we are finding these values,
and if I’m at the point x sub i, and I need to go to the point x sub i plus 1,
I just need the value of the derivative of the function at different, at just one point x sub i.
So, if you look at this way, we can also say this is y sub i, but what is dy by dx? dy dx is
nothing but the value of the function f, so I can rewrite it as f of x sub i comma y sub i. We also
know that this is nothing but the step size so I can substitute h here, then I get 1 by factorial 2
f prime of x sub i comma y sub i and then it'll be h squared there, then we have 1 by 3 factorial,
second derivative of the function f because if this is the second, the first derivative
of function f this will be the second derivative of the function f with respect to x of course,
and so on and so forth. So, those are the infinite terms of the Taylor series which we have.
So, one of the challenges which you are facing here
is that although you can see that the first two terms are basically Euler's method
being derived from Taylor series that if we want more accuracy, and that is what why we call it a
second order method, that we need to take one more term of the Taylor series. We need to include the
third term of the Taylor series but the challenge there is that, hey, we have to calculate f prime
and that, we have to do symbolically. So, for example, if somebody said hey,
you are, so this is an example. Your differential equation given to you is like this one,
then in this case what will happen is, hey, yeah that is the function
f, which we call it. We call the function f. Then if we have to find f prime of x comma y,
then we'll have to use some of our chain rule that'll be del f by del x plus del f
by del y times dy by dx, and del f by del x in this case is minus 5 e to the power minus x,
and del by del y is minus 3 and dy by d x is already here, so it’ll be 5 e to the power
minus x, minus 3 y. So, you can very well see that this can create an issue in a numerical method,
where in order to be able to apply it, you have to use, you have to find something symbolically,
and this is where Runge and Kutta stepped in. They said we can give you;
we can give you a second order accuracy without having to calculate the first
derivative of the function f, and that's what we're going to do in the next slide.
So, this is what Runge and Kutta did; they wrote the formula like this.
So, since they wrote the formula like this, one would say that hey,
they have introduced four unknowns: a1 k1 a2 and k2 right here. So, I somehow
need to know what those are, and they said hey, k1 is nothing but the value of the function at,
function f at this point and k2 is nothing but the value of the function at this point.
So, what this quickly tells you is that hey, this is no longer unknown. k1 is
no longer unknown because the value of the function at that particular point.
k2 is not an unknown till the time we know p1 and q11, so basically you have four unknowns:
a1 a2 p1 and q11. And if you recall the first three terms,
which we had of the Taylor series, they look like this.
And then of course we have the order of the h cubed terms which are left over,
so this is what was suggested by Runge and Kutta, that we're going to take this
and we're going to equate it to this. You see the left-hand side is the same,
the right-hand side is the same so far as this part is concerned and what they want to do was
that hey, if I equate this with this, and somehow I’m able to find the values of a1 a2 p1 and q11,
then when I am using this particular formula there is no mention of the first derivative
of the function f hence making it a numerically strong technique to use.
So, when they equated these two expressions, and I’m not going to give you the proof for it-the
proof is in the textbook, that they found out that hey you get three equations. You get a1 plus a2
equal to 1. You get a2 p1 equal to one half, and you get a2 q11 equal to one half. Those
are the three equations which you get. And now, you might wonder that if I get three equations,
and I have four unknowns what have I solved? You have solved the four for,
the four unknowns by saying that hey, I will take one of the unknowns to be something which I know.
So, for example if you choose a2 equal to one half then you get the values of a1 equal to one-half
b1 equal to 1 and q11 equal to 1, and you can use those and then you know all the four unknowns. So,
that's why if you look at a textbook or look at the internet about the Runge-Kutta second order
method, you will see various forms of it, and the three most popular ones are Heun’s method,
midpoint method and also Ralston’s method, which are basically taking different values of a2. So,
I’m going to show you Heun’s method you can do Ralston’s methods and midpoint
method formulas yourself. So let me show you what is involved in the Heun’s method.
Method, what we have is that a2 is chosen as one-half. And if you look at the
three equations which we had,
which need to be satisfied to get the second order accuracy, we had these three equations. So, if I
choose a2 equal to one-half, from here I’ll get a1 equal to one-half. From here I’ll get p1 equal to
one and from here, I’ll get q11 equal to 1. So that means that a1 is one-half, a2 is one-half,
p1 is one and q11 is one. So, if I substitute it back into the general form, which
they have for the Runge-Kutta second order method, I'll get y sub i plus 1 is equal to y sub i
plus a1, which is half, times k1 plus a2, which is half,
times k2 times h. But k1 is nothing but the value of the function at x sub i, y sub i,
and k2 is nothing but the value of the function of x sub i plus h, because it's
p1 times h. p1 is 1 y sub i plus q11, which is 1, k1 times h, and that's your Heun’s method
That's your Heun’s method saying that hey, if you want to find an approximate value of y at
a point ahead, if you are at x sub i and you want to go to x sub i plus h or x of i plus 1,
then what you have to do, is you have to find the slope k1 of y respect to x and that's
given by the function f. You refine the other slope k2, you give it equal weightage of half,
and you multiply by step size, add the value of y which was the value of y at x sub i,
and you get an approximate value of the y value at the point ahead. Now, look at this. This one is a
slope at the current point, or at the point where you are, x sub i, and this one’s the slope at x
sub i plus h, which is the point where you want to be. And in order to find the value of the slope
f, you also need the value of y and how is that approximate value of y calculated?
That y is calculated by using the Euler's method formula, as you can see here,
is y sub i plus k1, which is nothing but this times h. So, what you're basically seeing is
that Runge-Kutta second order method is simply giving some, finding slopes at two points,
giving it some weightage to each of the slopes, and still getting second order
accuracy and that is the beauty which we need to appreciate as numerical methods students.
The other two methods, which are very popular one is called the Ralston's method, and you can do it
yourself or you can look at the textbook. And in that case the value of a2 is chosen as two thirds.
The other one is called the midpoint method, and in the midpoint method one chooses
a2 equal to one. And based on that, whatever formula, the resulting formulas you get
you are able to. They look pretty similar to what we did for the Heun’s method, but
they are simply functions being calculated at different points;
different weights being given to the slopes, and that is the end of this segment.