A very accurate numerical method
for solving first order initial value problems
in the form of Y prime equals F of X, Y
with initial condition Y of X sub 0 equals Y sub 0
is the 4th Order Runge-Kutta Method,
often referred to as the RK4 Method.
It provides the approximate value of Y at a given point
and is derived using the Taylor Series expansion
of Y of X sub N plus 1,
which equals Y of X sub N plus H,
which is shown below,
where C is a number between X sub N
and X sub N plus H.
The 4th Order Runge-Kutta Method
uses a Taylor polynomial of degree 4,
and the result is shown below,
where Y sub N plus 1 equals Y sub N
plus 1/6 times the sum of K sub 1,
2K sub 2, 2K sub 3 and K sub 4,
where K sub 1 through K sub 4 are shown below.
Analyzing the formulas for K sub 1 through K sub 4,
notice K sub 2 depends on K sub 1,
K sub 3 depends on K sub 2,
and K sub 4 depends on K sub 3.
Also, K sub 2 and K sub 3
involve approximations to the slope
at the midpoint between X sub N and X sub N plus 1,
which is why we see the 1/2s in the formulas.
Let's take a look at an example.
We're asked to use the 4th Order Runge-Kutta Method
to solve Y prime equals Y minus X
with initial condition Y of 0 equals 2
on the closed interval from 0 to 0.5
with H equals 0.1.
And we're told to round all values to 3 decimal places.
To begin, because Y prime equals Y minus X
we have F of X, Y equals Y minus X,
and because we have the interval from 0 to 0.5
and we're making approximations
in increments of 0.1 given by H,
we need to compute the formulas
for N equals 0, 1, 2, 3, and 4.
To begin, because the initial condition
is Y of 0 equals 2,
we know when N equals 0, X sub 0 equals 0
and Y sub 0 equals 2.
Before we start our calculations,
let's record the information in a table,
where the first column is X sub N,
the second column is Y sub N,
the third column is the true solution,
which is Y of X equals E to the X plus X plus 1.
We'll use this third column to see
how accurate our approximations are,
but in reality, if we could find the true solution,
we wouldn't use an approximation method.
But again because we know X sub 0 equals 0
and Y sub 0 equals 2,
the first row is 0, 2, 2.
Notice for the true solution, Y of 0 is also 2.
Our first approximation will be Y sub 1.
Notice when determining Y sub 1,
N is equal to 0.
Before we can determine Y sub 1,
we need to calculate K sub 1 through K sub 4.
Where K sub 1 is equal to H times F of X sub 0, Y sub 0,
where H is 0.1, X sub 0 is 0,
Y sub 0 is 2,
and F of 0, 2 is just 2 minus 0,
simplifying, we have K sub 1 equals 0.2.
For K sub 2,
we have K sub 2 equals H times F of X sub 0 plus 1/2 H,
Y sub 0 plus 1/2 K sub 1,
where H is 0.1, X sub 0 is 0,
Y sub 0 is 2
and K sub 1 is 0.2.
Simplifying,
we have 0.1 times F of 0.05, 2.1,
giving us 0.1 times the difference of 2.1 and 0.05,
which equals 0.205.
Moving to K sub 3,
K sub 3 equals H times F of X sub 0 plus 1/2H,
Y sub 0 plus 1/2K sub 2,
where H is 0.1, X sub 0 is 0,
Y sub 0 is 2 and K sub 2 is 0.205.
Simplifying we have 0.1 times F of 0.05, 2.103
which equals 0.1 times the difference of 2.103 and 0.05,
which is 0.205.
And finally we determine K sub 4,
where K sub 4 is equal to H times F of X sub 0 plus H,
Y sub 0 plus K sub 3,
where H is 0.1, X sub 0 is 0,
Y sub 0 is 2 and K sub 3 is 0.205.
Simplifying, we have 0.1 times F of 0.1,
2.205 which equals 0.1 times a difference of 2.205 and 0.1,
giving us 0.211.
Now that we have K sub 1 through K sub 4,
we can determine Y sub 1.
Y sub 1 equals Y sub 0 plus 1/6 times a sum of K sub 1,
2K sub 2, 2K sub 3 and K sub 4 shown below,
giving us Y sub 1 equals 2.205.
Let's record this in the table.
Comparing to the true solution,
we have a very good approximation.
And now we want you to determine Y sub 2.
Now to determine Y sub 2 we use N equals 1.
We also have to use our previous calculation
that X sub 1 equals 0.1 and Y sub 1 equals 2.205.
Once again,
we begin by determining K sub 1 through K sub 4.
This time we'll go a little bit faster.
Notice all the formulas for K sub 1 through K sub 4
involve X sub 1 and Y sub 1,
because we're determining Y sub 2 and N is equal to 1.
So you may want to pause the video
and verify these calculations
but we have K sub 1 equals 0.211,
K sub 2 equals 0.216,
K sub 3 equals 0.216,
and K sub 4 equals 0.222.
And now we can determine Y sub 2.
Y sub 2 is equal to Y sub 1 plus 1/6 times the sum
of K sub 1, 2K sub 2, 2K sub 3
and K sub 4 which is shown below,
the final result is Y sub 2 equals 2.421.
Let's go ahead and record this in the table
and compare it to the true value.
Next we want to determine Y sub 3.
To determine Y sub 3,
notice N is equal to 2
which means we'll have to use X sub 2 and Y sub 2
to determine Y sub 3.
So here at the top we have X sub 2 and Y sub 2,
and once again we determine K sub 1 through K sub 4.
Notice how the formulas involve X sub 2 and Y sub 2.
We have K sub 1 equals 0.222,
K sub 2 equals 0.228,
K sub 3 equals 0.229,
and K sub 4 equals 0.235.
Now we determine Y sub 3
where Y sub 3 equals Y sub 2 plus 1/6
times the sum of K sub 1, 2K sub 2,
2K sub 3 and K sub 4 shown below,
resulting in Y sub 3 equals 2.650.
Let's go ahead and record this.
We have two more rows to complete in the table.
To complete the table,
we still need to determine Y sub 4 and Y sub 5.
I'm not going to go through all the calculations
for those two Y values,
but I do want to show the formulas.
To determine Y sub 4,
notice we need to use X sub 3
and Y sub 3 because N equals 3.
The final result should be Y sub 4 equals 2.892,
and to determine Y sub 5
we need to use X sub 4 equals 0.4
and Y sub 4 equals 2.892.
The final result should be Y sub 5 equals 3.149.
Let's go ahead and record these values in the table.
Now that we have the table completed,
we can see that our approximations
using the 4th Order Runge-Kutta Method
are very close to the true Y values.
I hope you found this helpful.