In this video, we're going to look at how to use psi pi solve IVP solving initial value problem function to solve higher order ordinary differential equations. The reason we need to do this is because out of the box, solve IVP kingdoms of first-order ordinary differential equations. And said, we're going to have to do is take the second-order ordinary differential equation here, make it and two coupled first order ordinary differential equations so that we can solve them, solve IVP. This equation we're going to look at it could be any second-order ordinary differential equation. But we're constantly to find the poles differential equation. And this, you can see that if we, if mu receiver, which remove this tamping Taiwan, we just have a simple harmonic oscillator. But mu introduces when mu is non-zero, sum non-linear damping term in his equations has been used in electrodynamics and biological systems to model various things. But let's not worry about exactly the problems is it deals with. Now the trick is going to wait ten days. Two coupled first-order ordinary differential equations, where you can do that to introduce this new variable v, which equals dx by d t. So you can see this is a first-order ODE that relates X and V together. If we substitute v in here for d x by d t, This equation, instead of T2 x by d t squared, we get dV by d t equals. We're going to take this terms up to the one side. We get plus mu times one minus x squared times V minus X. And you can see that this is also a first-order ordinary differential equation, which is a function of x and v elderly. So here we have two first order order differential equations, which an alternative way to represent the second-order ordinary differential equation. If we had a third order ODE, we could do the same thing, but breaking it down into a set of three coupled equations. So this is what's going to work with. So it starts off with, we're going to need to import the matplotlib numpy library so that we can plot the results and do the math on this. And we're going to import Sai PI solve IVP solving initial value problem function here. We're also going to use this command here to set the aspect ratio of the plots. It hit me twice as wide as the our talks and watchmaker, wide plotting. So this is just imports in the packages. As we've seen in the first videos for looking at how we write, how we solve differential equations, we need to write a function that's going to return the derivatives. So here I've got my vdp vendor polls, derivatives function. And as before, we need to put the thing that we're differentiating by which is time here first, and then the values that we were interested in in the second ID here. And why it's broken down into two things now, because our x's are going to be our first value of y. Over here. And fees which dX by d t is going to be second funny, y. So y is now either NumPy array or list of two values, which are the values of b and x at this time to take. What we want to return is the derivatives at this time. And so the derivatives are just going to be this, the derivative of x with respect to time, which is the first thing. It's going to be v. Due to a V with respect to time is mu times one minus x times x, x squared times V minus X. And so we're giving it the current time and y, which is a value of x and the value of way skipping the derivatives of y, which is the derivative of x first and then the derivative of the second derivative of x is just b. And the derivative of v with this thing. So I've got a function which when we give it some time and some value of the current state, it gives us the derivatives of x in Vietnam at that time. Good clue. All we need to do is solve this. Let us start with the case where mu equals 0. We're going to create some times that print out its output, the sounds recruitment t equals in space for 0 to ten. We can break that down into 500 points. And then our solution is going to be sold. We pay our function. Is this. The T span, the start and end points for the integration are going to be the first value of t. And the final values tends to swamp the initial value. Do you say, well, we're just going to take the initial values to be x sub one. And dx plus t of b is 0, the position is one, the velocity is 0. We're going to evaluate these values of t equals t percentage. Yeah, good. So now we're just going to create a plot of this results. I'm just gonna Coopers and coded plot. Let's have a look at this plot, two graphs. We're going to plot the first values in y, which is the values of x against the second value. The same values in y, which are these, which are velocities in here. And then the second graph is we're just going to be looking at how the first values in y, the positions and evolving as a function of times. And if you remember the case mu equals 0, it's just a simple oscillator. So we can see that in time the position just oscillating. We can see that we're starting with a position of one and a velocity of 0. And we can see the positions dropping. It gets to a low here. So when will behave. So it's just oscillating around risk. If you now look for different case will put mu as being one, can start C 1n, normally a linear damping functions. To see that again, we're starting at this point here, will gets in these oscillations, this periodic function here that slow decay. But it's behaving that's regularly to when we get in a cab and complex behavior. So just to summarize all of this one plus and make a graph where we're plotting how case of mu is mu one and mu is to Michigan to put the time evolution of the position. So you can see I've got this first case where a simple oscillator. In the case with this nonlinear damping passive cosmetics elevations here. Just these relations. We can see how we get these different behaviors for this oscillator for mu as 12. So just to summarize what we've done here, we wanted to solve a higher-order order differential equation. This was a second-order ODE. So to do that, we had to break this down into two coupled equations, which were both first order ODEs. We can then create a function that returns the derivatives. Things on the right-hand side here is a function of x and v, which will go starting value for y here and time here. So we had to return those derivatives. Then we can use solve IVP to integrate this. We give it a function that returns the derivatives. We get T spam, which the starts and then times Y0 is some initial condition. And initial condition on x and initial condition on the velocity. And I chose to output all the values, these time periods here so that we can plot a nice smooth curves how that was evolving in town. Such that shows how to integrate high order ODE's using solver.