The throughout the section, we have already solved several ordinary differential equations, but to
be honest, all of them, we could have also solved analytically.
So so far, our new routine didn't serve any purpose, but now we will finally come to an example which
we cannot solve analytically.
So here we can really use our new routine, which we have to find and called Euler to to solve second
order ordinary differential equations.
And the example will be the harmonic oscillator or more precisely, a pendulum.
So you probably know this example.
There's a pendulum swinging and it's described by the angle, so you could also write that down in terms
of the coordinates.
But I will write it down here in terms of the angle and the differential equation looks like this.
So you have the first term, which is basically characterizing the force acting on the angle or, you
know, the the force acting on the pendulum, which is characterized by a second or the derivative of
the angle.
Then we have here a damping term, which is friction basically.
So loss of energy.
And then we have a third term which describes the gravity force.
So the force will always point straight down and it's not perpendicular to the pendulum, so not along
the radial direction, and therefore it will not be linear and theto as you sometimes see this.
But this is in general not correct because in general, the correct differential equation is characterized
by a sign of theta, which is just due to the fact that the force is not always radial, but it is pointing,
always straight down.
So you have these three terms.
B is the damping parameter, and C is basically determined by the pendulum length it's given by the
gravity constant, divided by the length of the pendulum.
So before we really solve this equation, which cannot be solved analytically, that has come to the
case that you probably know already.
This is called the small angle of a small angle approximation.
So if theta is really, really small, then you can approximate the sign of theta to be equal to the
theater.
And if you then consider a case without damping, then you have the differential equation.
Theta second derivative is a is equal to minus C times sign of theta.
So this becomes this one here.
And so this is an equation that is linear in the terms of theta.
And also, it's very easy to solve because a function that solves this is, of course, the sign or
the cosine function.
So a possible solution would be this one here where you have a course in function square root of g over
all times T.
So let's see if our routine is able to restore this result.
So this differential equation is just a tiny bit more difficult into to freefall.
So the freefall we had theta.
So basically we had here why?
Second, derivative is given by minus g.
And here we have A. Another term with the function itself.
So what this means is we have to modify our code.
So here these are the two cells from the free fall, which I've copied.
So let's go back down and let's modify them.
So here I will write.
Blink for L is equal to two.
And so over a constant C, which is this one is given by
nine point eight one divided by the length and then the damping I will also consider to be zero damping
B is equal to zero.
So this one would appear to be pendulum geometry and then we can define our function f only e.
So the f only function would in this case, be if we take this on the left and this on the right, it
would be minus B times y one and then another term, which is minus C times y zero.
So bring these two terms on the right, and we have this approximation that the sine is equal to the
theater itself.
And here Cetus called Y is zero and the first derivative is called y one.
Now we must define the starting values.
And here we will once again use T zero as equal to zero.
And then maybe that it's not so.
Using Let me go right here, Theta Zero and Theta one, but it would not be necessary, actually.
And then we can also right here, six zero zero and to one zero.
And I've tested this before and while used to work quite well, our 0.2 and zero.
So you have to remember that three to zero must be small since we are here in the small angle approximation.
So, yeah, make sure that this value is pretty small.
Otherwise, it will just be unreasonable.
And then we can increase the number of and max.
And I think there's one, of course, we have to have to change now.
So as I said, this would not have been necessary to change.
We could have just wrote here why and also why.
But I think it's a bit more reasonable and you can understand it better since I changed it.
So now we can run the cell, calculate the solution and plot it.
So here, right, Peter.
And this time I only want to plot thetr.
I don't care about the first derivative.
So the analytical solution will be test, test, beta test thetr and it will be co-signed.
So will be theta zero times and P dots cosine and P dot, square root and G over.
So nine point eight one over A and then times T times test T, and I hope that this will now get give
the correct result.
And it looks pretty good.
It looks like, yeah, it looks like a perfect cosine function.
And really, there is no wonder because the analytical solution is in fact the cosine function and our
step size was small enough to be able to recreate this result.
So that was pretty good.
We have used our second order method that we have to find here to solve now the pendulum, the harmonic
oscillator in small angle approximation.
However, this small angle approximation is, of course, only an approximation, and this approximation
is only done so that we are able to solve it analytically.
But since we have a nice cold, we don't need it.
We could actually use here the sign of theta and solve the actual equation, and this is what we are
going to do in the next lecture.