Order of the Matlab Ode Solutions Appearing at Output?
2 views (last 30 days)
Show older comments
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)?
0 Comments
Accepted Answer
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.
See also this question: https://de.mathworks.com/matlabcentral/answers/287083-problem-with-order-of-substitution-with-odetovectorfield-solving-second-order-ode-with-ode45
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
More Answers (1)
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
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.
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!