In this segment, we'll talk about the Runge-Kutta second-order method of solving
ordinary differential equations. We'll take an example to do so.
So, here's the problem statement. We are given a differential equation which is like this, it's a
first order ordinary differential equation. We are given the initial condition, we're asked to find
the value of y at 3 by using the Heun’s method, and the step size is 1.5. So, if you look at that
the initial condition is at 0, and we are supposed to find the value at 3, we know that the initial
value of y is 5, and since we're taking the step size of 1.5, that means that it will take us 2
steps to get to 3, because we'll get the value of y here, and then we'll get the value of y here.
So, our differential equation is given in a form
which we have to change in order to be able to use our Runge-Kutta second-order method.
So, I got to change, put this on the right-hand side so we'll get dy
by dx is equal 3 e to the power minus x minus 0.4y and that that gives me the function of x comma y.
So, if I recall my equations for the Heun's method, those are given by this formula right
here. I have to find k1 and k2; k1 is nothing but the value of the function at these values of
x and y, and k2 is the value of the function at x i plus h and y i plus k1 times h. So,
if I use these formulas now on this particular differential equation form, I should be able to
find the values of y1 and y2. Y1 will give me the value at 1.5 and y2 will give me the value at 3.
So, I choose I equal to 0, so the corresponding values of x,
x naught will be 0. Correspondingly y which is y naught would be 5, this is from the initial
condition. So, now, what I have to do is find k1. k1 is the value of the function at x naught comma
y naught, which is the value of the function at 0 comma 5, put it back into the function f
which is 3 e to the power minus x in this case is 0 minus 0.4 times y, in this case being 5,
and that gives you 1. The value of k2 is at this particular point.
So, if I now substitute the corresponding values x naught is 0, h is 1.5, y naught is 5,
k1 we just found out to be 1, h is 1.5 so that means that the f has to be calculated at the
value of x equal to 1.5 and y at 6.5. So, that means that is 3 e to the power minus 1.5, because
that’s the value of x minus 0.4 times y, which is 6.5. And this value here turns out to be -1.93061.
So, since I have values of k1 and k2, I can find the value of y1 now because y1 is nothing but
applying the Heun’s method formula here. So, y naught is 5, k1 is 1 k2 is -1.93061, and h is 1.5,
and if I calculate this, I’ll get 4.30204. So, this is the approximate value of y at x1,
which is the value of x at 1.5. So, now I found y1, I will conduct one more step to go to y2.
So, in order to find the y at x equal to 3, we now say i is equal to 1, x1 is 1.5
and y1, we just found out to be, how much, 4.30204,
and the question now is how to find y2? So, again we'll find k1 which is given by this,
so we substitute the values of x1 and y1 here that gives us,
and this value here turns out to be -1.05143. Now where to find k2? So, k2 will be the value
of the function at x1 plus h and y1 plus k1h. We already have these available to us, x is 1.5,
h is 1.5. y1 we have found out from the previous step, k1 we just found out,
and we already know the value of h. And if we do that, the arguments
of, for k2 for f turn out to be 3 because that's where we want to go, and the approximate value
of y needed to find the value of k2 is 2.7249. And this value here turns out to be -0.9406.
Having said that what we’re going to do is, of course this -0.9406 basically comes from
3 e to the power -3 minus 0.4 times 2.7249, that's how we get this value here. So, now we have
the values of k1 and k2 so we can find y2 as y1 plus one-half k one plus one-half k two times h.
So, we substitute these values and let's see what we get. So, we substitute the values of y1,
k1, k2, and this value here turns out to be 2.80802, and that is the approximate value at y at
x equal to 3, because that's y at x2 and x2 is what? x2 is 3, right from here and that gives us
the approximate value of y at x equal to 3. And that is, in fact, is the end of this segment.