And the previous lecture, we have seen that there exist many methods that are much more accurate compared
to the conventional Euler method for solving differential equations.
And one of those methods was the quotes methods.
And there is actually a whole family of running Qatar methods.
And one of them was the longer cutoff for five methods, which we are going to implement throughout
the following two lectures.
So the reason why you're able to quit our method is used so often throughout physics is because it is
not that time consuming.
It's not that difficult to implement, but still, it gives very accurate results.
And to explain to you why when we put our method is so much better than the Euler method is pretty difficult.
So we can have a look at this link here, and you can see here's a derivation, and I really don't want
to go through this whole derivation with you together because you see it is quite demanding.
And this is not even going to put up four or five methods, but only the a quarter four methods.
So the simple or simplified and a simplified way, you could say that the reason why the woman quit
on method is much better than the Euler method is that it combines several terms so that arrows cancel
each other.
That's a bit similar to the way that we have to find the more accurate versions for the derivatives
in the earlier section of this course.
So what we are going to implement here is the home equity method called Arc four, which will be the
first step, and then we will take it to even further.
And then we will implement the R.K. four five method, which is the same that is implemented previously
in the problem solver that we have compared to here.
So to get started, let me go back and let me copy the codes for the implementation of our oil methods,
because here we will define a function called R.K. four.
And of course, in general, it will be pretty similar to the old method, and we will just change the
way the the way we'll use updated.
So let me scroll up.
Let me search for our Arla methods.
So not the Euler second order method, but the First Order methods.
I think here it should be in a second or the pendulum.
We have solved quite a few examples.
Yeah, here it is.
The Euler.
So you go to the cell, it's should be cell number seven and we copy this and go back to the bottom
of our notebook and paste it here.
And now what we are going to change is, of course, the name.
We're going to name it, R.K. four and four.
The arguments.
We still need the same things and also the beginning will be pretty much the same at first.
We use our starting value for Y and yes, added to Y and the same for T zero.
Then we start with these lists where we will store our values T and Y, and then there will be the loop
over the next steps.
And now this will be what we are going to calculate next.
And to understand what we are going to do, let me open up this Wikipedia link in a new browser.
And there I will explain to you how we update the value for white in the form of code for methods.
So the trick of avoiding a quota method is that we do not simply go from the old y well you to the new
Y value, but we have intermediate positions over which we will average in a certain way.
So let me write down how I mean this.
So first of all, we are going to calculate some intermediate positions.
So these will be K1 and K2, OK, three and four in this case, because it is a fourth order when we
put our methods and then we will calculate the value K, which will be some weighted average.
In this case, it will be one over six times K one plus one over three times K two plus one over three
times K three and then one over six times K4.
And this K value will be the value that we will add to our value y.
So basically, instead of this derivative four, we go straight from the old value to the new value.
We go from the old value to the new one by adding the value K and K consists out of a weighted average
of four different points that we are going to construct next.
So where can you find these values?
You can find them in any mathematical equation collection for numerical mathematics, for example,
or also on Wikipedia.
So here's the classic fourth.
All the methods the of the hungry put our methods.
And this is a bit of a cryptic way of writing it down in such a tableau, and the values for the key
values are always here at the bottom.
So this would mean one of a six times K1, one over three times K2 and so on.
And Cassie, there exist many different methods and there exist many different values for these key
values and also for the other values.
So these are the ones that we are going to use next.
I would say, let's first use this one.
These are the arguments or the coefficients for the H value.
So for the step with or yeah, step size, we called it here.
So this will always be calculated in the following way.
So step size times F and then T come our way, but we will now modify these arguments here.
So we will change the time argument and we will also change to y arguments.
So basically, we are taking positions that are in between the old and the new Y value.
So let me copy this and then we are going to modify it in all four cases.
So in the first case, or I would say, let's first consider the time argument which is described by
these coefficients.
And this means for the first time argument, we will add zero.
Here we will add one half of h or sorry, one half times h.
You're also one half times h and then one times h.
So we right plus major page of a two plus page of a two plus page times one.
So just h and then we also have to modify the Y arguments.
And here we have to add a linear combination of the K one K to three K four values.
And of course, for K one, we cannot add any other K value, but four K two, we can add some multiple
of the K one four K three.
We can add a weighted some of the K1 and K2, and for K four, we can add a weighted sum of K one,
two and three.
And this is described by these coefficients here.
This means for the K2 value, we add one half of K one for K three, we add one half of K two and four
K four.
We add one times K three.
And you see in general, this can be much more complicated.
For example, here we will add for K for a weighted sum of K one, two and three weighted by these coefficients.
And these coefficients are always calculated in the way so that certain arrows cancel out so that the
solution will then be more accurate.
So let's go ahead.
Let's remember one half on half and one.
So we have here plus one half times K1, so we can also write K one over two here.
We had also one half point and a K two column K two of a two.
And here we just had one in the K three column.
So like this and this is actually it.
So we have constructed four new points that are pretty similar to that from the syntax is pretty similar
to the change for the Y value that we have before the Euler method.
So it's h times some value of our function, which was the derivative.
And the only thing that we have to change here is the argument, the time argument and the Y arguments,
and we have constructed four different K points then have calculated the weighted average over these
points.
And then we have updated our value y with the new value of K for the value of each year.
For the time update, we didn't change anything because we still go in steps of h.
So of course, we have seen that in our example previously, there is some time adaptation.
So when I scroll up to here, for example, we have seen that we do not take equidistant time steps.
So here there's also another trick implemented that's intelligently choses to step with parameter so
that the error is still not too large, but so that we need less points.
But this is a whole nother thing, and this is even more difficult to implement.
So I think we should not bother with it because in the end, we are often often interested in these
equidistant lists of points.
And here we are, even asked the solver to create such lists.
So I think it's OK if we just take an equidistant method here.
So we have now implemented the art form methods, and I would say we do not need to test it here right
away.
Let's just run it and see that there is no error.
OK?
This worked fine.
And before we test it, I would say, let's go right to the next step and implement the arc four five
methods, and then we will compare both of these methods with our own Euler methods.