Most of the time in practice we don't have just a single variable. So next we want to look at having n variables with n ODE's. We call the unknown dependent variables u1 to un. And the ODEs are given as d y d t equals a given function f phi of t and all the variables. Each component also needs an initial value A famous example is called the predator prey system or the Lotka Volterra equations. Here Y and Z represent the sizes of a prey species and a predator species. The prey species grows in the absence of predators. By interactions with predators decrease their growth rate. The predator species is in the opposite situation. If we label y and z as U1 and U2. Then these become the functions F1 and F2. We can also gather the solution components into a vector U and write things as a single ODE with a vector valued function f and a vector initial condition. There's really no difference between a system of scalar ODE's and a vector ODE. And we use the terms pretty interchangeably An important aspect of ODE systems is that higher-order derivatives in an ODE are always equivalent to higher dimension. This is easiest to explain by example. Here is the equation of a pendulum where theta is the angle of the pendulum makes with the vertical We're given an initial angle and an initial angular velocity to specify the initial state of the system completely. Now we define a new vector variable by setting U1 equal to theta a U2 equal to theta prime we can replace all the references to the theta in these equations by references to you as follows. By the definition of u1 we have D1 D0 C0 is theta prime And by the definition of theta two we have that the ADT is data double-prime. Looking back at the original ODE we can isolate theta double prime and use it to rewrite the U2 DT in terms of theta and theta prime only. Then we go back once more to the definitions of U1 and U2 and use them to make substitutions that remove all the remaining theta references. Now everything that underline composes a vector ODE that uses only u and not theta. Finally we have to go back to the initial values and replace those as well by references to you online Altogether we have a two-dimensional first-order vector initial value problem in place of our original scalar second-order problem. Here I have a second-order ODE in the variable theta. This is the equation of a pendulum. Many times you'll see this with a theta here instead of sine theta because it is linear. But this is more accurate for large angles. With time derivatives we often use a dot To represent the derivative. So here I'm rewriting the equation where theta double dot is a function of everything else. And that's because to solve this problem I'm going to have to recast it as a first-order system in two variables. So a second-order equation gives me two variables and those variables r theta and theta dot. So the angular position and the angular velocity. Here's the function that implements the ODE. So as always we have a function of t and u two variables. U is a vector valued variable that holds the two components of the solution. So the function is able to get values for you that's theta and theta dot. Given those two values it needs to return the value of the derivative of u with respect to time. Well the first component is theta and by definition d theta d t is equal to the theta not pay. The other equation is the derivative of theta dot. But that's the same as theta double dot. And that's given by the ODE. So we have minus gamma times theta dot minus sine theta. So given a value for you I've computed these two components for DDT. And the last thing to do is to just package them back up so that I return them as a vector So here's how we use it. F is that function which defines the ODE. Initial value is a vector with two components. The first component is theta and the second is theta dot. So we started a large angle of 2.5 radians and a 0 initial angular velocity. And here are the times that I want the output at 2001 different times and finally the fourth line solves the thing. You see it's very fast despite having so many points. The output here you each column represents one of the two variables in the system. So the first column is theta. The second column is theta dot. Each row represents a different value of time. So the rows here match up with the rows here. So that means the first column is all of theta as a function of time. So that's what I pull out here. And then I can plot that plot theta as a function of time. And you see oscillation with an exponential decay. The second column of U has the angular velocity theta dot. So I can use that to make a phase plane plot put theta on the x axis and faded out on the Y axis. And you see this spiraling behavior has the solution decays Here's a larger example can vary higher derivatives to higher dimensions. I'm writing out a system of three variables x y z and equations of second. Third order. This system needs seven initial conditions to specify the solution uniquely. It always happens that the quantities given in the initial values make the correct definitions for the new vector variable. According to these definitions we have D one D t is x prime. Due to D t is x double prime. Is y prime is y double prime d phi d t is y triple prime and so on for z. We look down this whole list for the highest derivative present in each variable. Each one of v is appears in one of the original ODE's. And we can use those to substitute for the high derivatives below. Then we're able to translate each of the OD functions into the u variables At the end of this process will have no more references to the original x y and z variables. And we have a complete system of seven ODEs instead. Here's a look at the books implementation of Euler's Method for systems of equations are for vector equations. As always we're given the function that defines the ODE. The time interval that we're solving over the initial value which in this case will be a vector and the number of steps that we want to take. The outputs are a vector of the times that we're given the solution at. And then in this case it will be an array or a matrix solution values at those times. To begin with we set things up in time. So we find the grid spacing. And then we define the whole vector of times in one shot like this. Then we get the output array setup. So we'll let m be the dimension of the system. That's the length of the solution vector. So you will have m heroes for the different components of the solution and n plus one columns for the different times. So each column of this u corresponds to the solution at one time. And we start things off with the initial value. So I put that in the first column of U this little syntax here is to turn you into a column vector in case it was given as a row. So here's the real iteration. We'll Euler's method part of it. We simply refer to the vector solution at time i. We call time derivative function at t i and my vector UI. Multiply that. So that must be a vector result. We multiply that by h and add it to UI and we get the next value of the solution. That's all quite straightforward. Then this last bit just makes the shape of you correspond to what MATLAB does. So MATLAB puts different time values in different rows. We put them in different columns. So this just takes the transpose so that the output comes out the same
FNC 6.3: IVP systems
From Tobin Driscoll November 04, 2019
41 plays
41
0 comments
0
You unliked the media.