How to output matlab ode dependent variable at same time step as T and Y?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using ode15s to solve a coupled ode functions, like
[T Y]=ode15s(@ydot, [1:100],y0,options)
function ydot=odefunction(t,y)
dept1=f(y(1),y(2));
ydot(1)=dept1*y(1)*y(2)
ydot(2)=a*y(1)+c*y(2)
end
Now I have output file with T and Y from t=1 to t=100 with interval of 1. Right now I am using global variable and output "dept1" at every time step odesolver called, like t=[...7.7241 7.8241 8.6241 9.6854 10.524...]. Question is how could I output dependent variable like "dept1" from t=1 to t=100 with interval of 1?
0 commentaires
Réponses (2)
Richard Brown
le 2 Juil 2012
Modifié(e) : Richard Brown
le 2 Juil 2012
By far the best way is to compute your dependent variable afterwards with the y matrix that was computed by the ODE solver. No messy code (or globals / persistents) required, and it probably won't add a huge amount (proportionally) to your computational cost.
0 commentaires
Walter Roberson
le 2 Juil 2012
Modifié(e) : Walter Roberson
le 2 Juil 2012
You might still need to use a global variable, but you can get it to output only at the locations you specify in tspan.
Use odeset() to construct an options structure that includes an OutputFcn property. See http://www.mathworks.com/help/techdoc/ref/odeset.html#f92-1016858 for the parameters of the function that will be called.
I'm thinking: use the init flag to initialize a persistent variable to []; use the calls with no flags to append to the persistent; use the done flag to transfer data out of the persistent (possibly by setting a global.)
2 commentaires
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!