Why does ode45 generate different sized vectors depending on how output is defined?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Andres Morfin
le 16 Sep 2019
Commenté : Andres Morfin
le 16 Sep 2019
Here is the function I am trying to solve along with the domain and initial condition:
tspan=[0 10];
x0=0;
func=@(t,x) -2*x+t;
If I try to solve the ode with the following format, the vectors are of size 57x1:
[t,x] = ode45(func, tspan, x0);
However, if I try to solve the ode with another format, the vectors are of size 1x15:
sol = ode45(func, tspan, x0);
t=sol.x;
x=sol.y;
The reason I want to know this is because I want the length and number of time steps during the integration. If I had to guess, I would say that it is given with the second format because if I write it like this:
options = odeset('Stats','on');
[t,x] = ode45(func, tspan, x0, options);
the following appears in the command window :
14 successful steps
2 failed attempts
97 function evaluations
This tells me that there are 14 time steps so the size of sol.t is the correct one. Am I missing something?
0 commentaires
Réponse acceptée
Walter Roberson
le 16 Sep 2019
sol = ode45(___) returns a structure that you can use with deval to evaluate the solution at any point on the interval [t0 tf].
Effectively, when you use that syntax, ode45() simplifies the output down to something with typically fewer points that deval() would evaluate to give values within your error tolerance to the outputs of the other form of the sequence.
To get statistics when you have no event function, use
[t, y, stats] = ode45(....)
If you have an event function, then stats will be the 6th output.
The number of timesteps will be the first element of the numeric vector returned. The number of function evaluations will be the third element.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!