Order of the Matlab Ode Solutions Appearing at Output?

4 views (last 30 days)
When solving higher order differential equations using an ode solver (for example [t,y]=ode15i...), there are many outputs in y such as v1(t), v2(t), v3(t), Dv2t(t), Dv3t(t), Dv4t(t).
How do these signals appear at output (y) of the ode solver? What is their order?
In other words, what should I expect to get at y(:,1), y(:,2),...,y(:,end)?

Accepted Answer

Stephan
Stephan on 11 Jan 2019
Edited: Stephan on 11 Jan 2019
Hi,
unfortunally Matlab sometimes changes the order of outputs to an order which appears not be logical (at least for me). I dont know why this happens, but it does in some cases. For ODE's it is a good idea to call odeToVectorField with two output arguments like shown here. The order of new_vars is corresponding to the output arguments of y, if you use matlabFunction to create the function handle.
In case of DAE the usage of reduceDAEIndex needs two output arguments which are new_eqs and new_vars. The usage of daeFunction needs both inputs, so that i would expect the order of the input vector for new_vars as the order of the output. But to be honest, for DAE i have no experiences.
Best regards
Stephan
  1 Comment
S H
S H on 13 Jan 2019
I had the same observation that each ode sometimes generate results with different orders. Thank you for clearing my doubts.

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 13 Jan 2019
If you're solving ODEs using ode15i or any of the numeric ODE solvers in MATLAB, the order of the solutions in the y output (or the y field of the sol output) should not change. They should be in the same order as the input y that the ODE solver passes into your ODE function.
If you're solving ODEs using dsolve from Symbolic Math Toolbox, see the "Assign Outputs to Functions or Variables" section of the documentation page for dsolve. In this case I recommend calling dsolve with one output and retrieving the solutions from the appropriate fields of that struct array. This avoids needing to worry about the order in which symvar orders the variables.
  2 Comments
S H
S H on 14 Jan 2019
Hummm...okay I will check my codes again. Thanks.
Steven Lord
Steven Lord on 14 Jan 2019
If you see this type of behavior from the numeric ODE solvers, please either show a small section of code that demonstrates the behavior or send such a section of code to Technical Support using the Contact Us link in the upper-right corner of this page.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!