In this video I'll describe a method used to solve ordinary differential equations and
this is a better approximation than the Euler Method which is described in another of our videos.
The Runge-Kutta Method is a fourth order approximation. The idea is we have initial
conditions, namely at a certain location, a certain value of x we know the value of y and then
we have an ordinary differential equation that relates how y changes as we change x
and that's a function of x and y. So what we're going to do in the Runge-Kutta Method
is use a recurrence formula and say if I know a value of y, then I can make a small step
and the step is to say x_(n + 1) is equal to x_n + h so we make a small step in h
and calculate the new value of y that corresponds to the x_(n + 1) and we have this term here
that's a function of x_n and y_n and the size of step. Smaller steps will give us more accurate
calculations and of course this is something that in a computer program can very easily be
done to step through. Programs can be more sophisticated than this but this gives you
a good idea of how these programs work. So what I'm going to do is write down the formula
for T4 and then discuss what the terms are in it. The T4 is 1/6 times the summation of
the 6 terms essentially. k_1 is just the function evaluated at x and y so at (x_n, y_n) for a
given condition. k_2 is a function evaluated but now x plus 1/2 the step size and y plus
1/2 the step size multiplied by the function, k_1. k_3 is very similar except it's k_2 here
and then k_4 is evaluated at the full step size and k_3 is here. And so this gives us
a better approximation than, say, the Euler Method, which we just use the function at the
previous point and the forth order approximation means if we were to decrease the step size
so instead if h, we used h over 2 as our step size then we reduce the error by a factor
of 2^5. We can get fairly accurate measurements using this Runge-Kutta. So what I want
to do next is apply this formula to a simple differential equation and look at the first
few steps to make it clear how we're doing these calculations on a computer. So let's
look at this example. I've written a simple differential equation we could certainly solve
this analytically but what we are interested in is the technique. We're going to assume
that at x_0 equals 1, y_0 equals 2. So this is our initial condition. Then we use
a step size to calculate y at a larger value of x. So I've written down the recurrence
formula and then I've substituted in the numbers. y_0 is 2 the step size here is 0.1 and then
k_1 plus 2k_2 plus 2k_3 plus k_4 and so we need to calculate the values. k_1 is just the function
evaluated at x_0 and y_0 which is then 3x_0^2 times y_0. So that's k1 and similarly we calculated
the other values, k 2, 3, and 4. So I've written the recurrence formula term now for k_2 so
it's evaluated x_0 which is 1 plus the step size 0.1 divided by 2 and then again the step size
over here 0.1, and then now the value of k_1 that we just calculated. So we have the value
for k_2 and we do similar things to calculate k_3 and k_4. So here are the values calculated
for k_3 where we're using now k_2 that we calculated in the previous step and we get the value
of k_3, and to calculate k_4, now we use step size h so this is 1.10 and we're using k_3
in this calculation. Once we have these four values we can calculate y_1. So y_1 is y_0 plus
the step size h over 6 k_1 plus 2 k_2 plus 2 k_3 plus k_4. So I'll substitute these values
in. So substituting in the values we calculated for k_1 , k_2, k_3, and k_4 we get y_1
that corresponds to an x_1 value of 1.10. Well this is much more accurate
than the Euler Method calculation. Then we continue the step through we get y_2 as
y_1 plus hT_4 evaluated at x_1 and y_1, and the same idea, we can calculate the function as we move
through where k_1 in this calculation is a function now of x_1 and y_1 the values we just calculated.
This is then the technique that's used in numerical programs like POLYMATH to
solve ordinary differential equations and we can certainly solve simultaneously a number
of ordinary differential equations with this technique.