Welcome back to our calls, where we are currently discussing how to solve ordinary differential equations,
and so far we have programmed ourselves a function that solves these equations, according to the Euler
methods.
And we have solved the dysfunction first order and also second order differential equations.
We've seen that this can be really nice to get the results that we weren't able to get when we would
just rely on analytical methods.
Now, of course, this Euler method is just the most simple approach and the most simple way of solving
these equations.
We've also seen that when the step size is too small, it can get slightly wrong results.
And also, you could imagine that when our problem problem becomes more difficult and if we want to
simulate it over a very long time and we want to still get the accurate solution, then we would really
have to decrease the step size and then the solution would take forever.
So it's much better to use a solvent.
It is provided by Python that is optimized and it uses more improved and advanced methods.
And to use them, we have to load a module that we have actually loaded in the very beginning of this
notebook, and this module is called PSI Pi.
And here we are only going to use the integrated part of place.
So I wrote from Typekit import integrate.
But you could also write import side.
So fine, so pi.
And then you would just have to write every time, say Pi Dot, integrate and then the solver that we
are going to use.
And since I wrote it down like this, we just have to write, integrate dots and then the command that
we want to use.
So let me go down to the notebook just where we left after the last lecture, and this was when we have
simulated this driven and attempt pendulum.
So as I said now we will discuss improved methods and there are actually two useful solvers in this
Sci-Fi module.
There is an old one that is called.
Yeah, all the story O and the E ins and I was just confused because it says old.
But it stands, of course, for ordinary linear differential equation and that interface and integration
methods this you can still use, but it's kind of old and not really profitable anymore.
Much better is now the new command, which is sci fi not integrate dot solve underscore IVP for now.
Yeah, and and this is what we're going to use.
And for this, you can even select different methods and different solvers.
So it's a nice tool that we will explore in the following lectures.
And the first thing is we are going to compare our results, for example, to which time and fight decay
with our old results.
So here we have the old methods.
And let me run this.
We've seen it worked.
And now we must, of course, verify that our new solver can also restore these results.
So how does it work?
Well, first, let's create a new cell and then the the command will be integrate dots.
So underscore heap, as I wrote above.
And then we just have to take care of the arguments.
So if you wouldn't know what the arguments are, how would you find out?
Well, you have to Google in the internet.
So here is a link where you can go to or you just Google Python.
Solve IVP and then you will get probably to this side or to another side.
And there they will really list all the arguments that you need to provide and we'll explain what they
mean and what you have to provide.
So here we first have to provide our function like in our own solution.
So we need everybody.
Then we need the time span and this is here given by such a list of two values starting volume and end
value.
Then we have to provide the starting value for the value of why.
And here we use one and we have to give it also as a list.
The reason for this is that once we try to solve higher order differential equations, then we would
have to provide here two or more values, as we have seen for the free fall, where we have to provide
the starting position and the starting velocity.
So here, from a logical point of view, it wouldn't really be necessary to use this as a list, but
that's the syntax.
So we have to provide a list.
And now it would work already, but fortunately, we can provide the method and we will discuss too
soon a bit more detail, but a pretty standard method that's always a good first guess is the only a
quarter four or five methods or short RJ 45.
So we must now stored the solution and I call this solution or AK 45, and I run this.
And now we can have a look.
What is the actual solution?
So solution underscore our K 45 Bob T would be the syntax for the T list, just an area of some dots.
And then we can also access the why list.
Which is, of course, also an array of dots of coordinates, and together they will be dots.
So let's look at those and let's just copy the plot from here and replace these two commands with our
new solutions so we can leave everything as it is and just change this one.
So here we will.
Right solution RJ 45 T and then Dot.
Why?
And if I run this, you will see this is the solution.
And first of all, you see, OK, the most important thing is that the end value is correct.
You see, it is correct.
It's right on the red curve.
And it's also the same as an hour in a miracle approach.
But what you can also see is that this could R45.
The methods used only very, very few points could even see this year only one two three four five 11
points.
And therefore, it's very, very fast compared to our 100 points or even 300 that we used here.
So it's enormous, I think, how comical to solve this differential equation with only such a few points.
And also what's remarkable is that we never told the wrong a quota algorithm how many points to choose.
And this is really a nice thing because we have seen previously that once we choose the step with too
large into all the methods that our solution will become in an inaccurate.
And so there's always this danger that you don't get the correct solution, but you don't really know
if that's correct or not.
However, for the human quota 45, you will not have these problems as the algorithm determines these
values automatically.
So the next thing that we are going to do is we, of course, wants to reproduce this graph here.
So we want to get two more points on the curve.
So for this, what we can do is we can provide an additional optional argument here.
So let me copy this.
And let me also copy the plot.
And to do this, we just have to provide an additional argument here, which is called to evaluate,
to evaluate, and then we have to provide here some.
And for example, we could provide a very similar array to be we right and peddled within space.
And then we go from, I don't really remember from zero to let's see zero to 30 and the step number
would be three hundreds.
Yes.
So this would be age times and max, cola and max that I run this around this.
And then it tells R.K. 45 explicitly to use these points.
And so at least these points as the T points for which it will evaluate the solution.
So I think in general, it's really much better to have only a few points here because then the calculations
will be faster and in the end, you will only be interested in the end value.
But since for some reason you want to have a dense list of points here, and then you can use this by
using such an optional argument, and then you will get such a nice solution, which is exactly what
we got before with our Euler methods.