So we have just defined our new functions for the higher order differential equation, which is here
of second order and now we will test if this code is correct and we will solve the example of the free
fall.
So I told you already that I considered here a mass for one and then we can write second.
All the derivative of Y is equal to minus G.
And we can, of course, also write this down as f of T and first derivative of Y and Y is equal to
minus G.
So our function F will just be a constant minus D, and it will not actually depend on T first derivative
of Y and also not on Y.
So analytically does is solvable pretty easily.
You just have to integrate twice with respect to time.
So you get minus G half times square and then these v zero times T and y zero terms.
But if we say we don't want to think and we just want to numerically calculate, then previously we
wouldn't have been able so.
But now with our new routine, we can see if we can restore this result.
So I will just right.
First of all, I have to define the function, of course.
So G is equal to nine point eight one, and the function we will define by writing F below is pretty
similar to previously, but we aren't here.
T call my wife, but now we must provide, of course, both of these arguments.
And maybe I should use the same nomenclature as here.
And since we have used the same nomenclature for the functions of first comes the actual value and then
comes the derivative.
So maybe it's better to change this year so that there is no confusion.
And so I start with the actual value and then with the first derivative and the function itself is just
a constant.
But it could also just depend on all of these values.
It would work.
But here we will only have the constant minus g.
Now we will need some starting values, so we will have to provide all of these values here basically.
So let me copy this.
So we have our f who d e already.
And though we need to starting time to zero, which I choose to be zero, we need to starting alternate,
which should be 10 could.
So these are really just arbitrary values that I selected doesn't really matter so much what you choose,
the velocity, which will be the first derivative at the time, zero is 50.
And then we only need and max and h the step size and then we have to store to resolve once again in
the solution.
This is very similar to what we did previously.
And then we need two plots so I can run this and that this doesn't give an error, which is good enough
now I want to plot.
So I will just copy our code from before and modify it.
So here we will compare this to the analytical solution.
So for this, I will the right here.
The analytical solution, which is minus g half times Test T squared plus two, is zero, which is this
times T.
Plus, y0, OK, and here we will plot the coordinates, which I think should be OK as it is.
Let's see.
Yes, looks pretty good.
So we have our typical parabola.
This is, of course, describing here.
A free fall were where we have a starting value of 10 notes already starting value of the afternoon.
So it starts here at 10.
Yes.
And then we have a starting velocity of positive 50.
So in the beginning, it will move 50 units in one seconds.
So at one second it should approximately be at 60.
OK, this works.
And then we have the gravity which pushes the objects down to Earth after some time because the acceleration
is acting along the opposite direction.
And so the velocity will decrease and the rate at which to coordinate increases will slow down.
And at some point it will reach to maximum and then it will be pushed back to Earth.
So to further analyze this, we could also plot here the velocity.
And for this, we just have to access the second or the last list here, which is the Y1 values.
So like this?
And then you see we plot the position and the velocity in the same diagram.
So I write why and we and you see the velocity starts at 50 and it decreases.
And when the coordinate has its maximum here and the velocity is zero because it's the first order derivative
and then the velocity gets negative, which is why the coordinate decreases.
So you see, we really are able to solve also second order differential equations with our new method,
which is based on the Euler method, and we can use it because we have reduced to second or the differential
equation to to first order differential equations where we can solve both of them with the oil method.