Is it possible to extract the time and two output variables from ODE45?
Mostra commenti meno recenti
Hello,
I have written a function which holds state space equations for ODE45 to solve, being in the nature of:
function zdot = odess(t,z)
In my mainscript which calls upon this function and has the initial conditions for the ode, I am recalling the outputs by:
[t,z] = ode45(@odess, t_step, z0, opts);
However, is it possible to get a second variable from the 2nd code listed above? For example:
[t,z,new_output] = ode45(@odess, t_step, z0, opts);
Thanks for your time.
2 Commenti
Jan
il 17 Gen 2017
Where does the "new_output" come from? What do you expect in this variable?
Tyler Bikaun
il 19 Gen 2017
Risposte (2)
Torsten
il 17 Gen 2017
The easiest way is to reculculate new_output from t and z after the call
[t,z] = ode45(@odess, t_step, z0, opts);
Best wishes
Torsten.
8 Commenti
Tyler Bikaun
il 18 Gen 2017
Modificato: Tyler Bikaun
il 18 Gen 2017
Torsten
il 18 Gen 2017
But z(1) is automatically included in the matrix z you get after the call to ode45.
Try
[t,z] = ode45(@odess, t_step, z0, opts);
plot (t,z(:,1));
to get a plot of z(1) over time.
Best wishes
Torsten.
Walter Roberson
il 18 Gen 2017
No, z(1) input to the function is not reliably included in the z output . The ode outputs are not necessarily for the same time points that the inputs were evaluated at: the ode routines make projections of values at time points. Also, if you supplied a list of times to evaluate at (rather than a vector with start and end time) then the outputs are only at the times you indicated but the times evaluated at are whatever is necessary to achieve the precision specified.
z is the solution variable vector - and each solution variable (in this case z(1)) is included in the output at the times t if you call ode45 as
[t,z] = ode45(@odess, t_step, z0, opts);
Best wishes
Torsten.
@Torsten: I agree. The zdot are not written to the output, because they are used internally only for the integration. Then e.g. "zdot(1) = z(2)" does not matter here.
I still do not understand, what "new_output" should be. Therefore I cannot post an own answer and even cannot reconsider, what the otehr answers are talking of.
Tyler Bikaun
il 19 Gen 2017
Modificato: Tyler Bikaun
il 19 Gen 2017
Torsten
il 20 Gen 2017
If you set up your code as above, the variable z(9) is z(1), integrated over time, i.e.
z_9(t)=integral_{0}^{t} z_1(t) dt.
If you want to output z(1), just use your previous code without any changes and use the command
plot (t,z(:,1));
after the call to ode45, as I already suggested.
Your assertion
z(1) isn't included in the output matrix "z" from [t,z] = ode45(@odess,t_step,z0, opts), i think what is included are only zdots.
is simply wrong.
Best wishes
Torsten.
Jan
il 20 Gen 2017
@Tyler: An integrator as ODE45 gets the start position (or "state vector") as input, than calls the function to be integrated, which replies the derivatives and accumulates them. For each successful time step, the new position is replied. Therefore the output of the integrator contains the positions (state varaibales) and the first element is its first component.
You can simply check this manually: Computer your odess(t,z) for the inital time and start vector and check the first row of the output of the integrator.
Walter Roberson
il 17 Gen 2017
Modificato: Walter Roberson
il 17 Gen 2017
0 voti
No, that cannot be done. See though
Categorie
Scopri di più su General Applications in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!