Output a variable each time step using ODE45
Afficher commentaires plus anciens
Hello,
I am trying to output a value from an ODE45 function at each time step, filling up an array, following this I need to read the array each time step as well. The idea is to alter a value in the ODE45 function using the condition of the previous time steps.
To write the value to be output I was attempting to use the Persistent variable and write it out to the main work space but not having much luck, is this the right approach I should be taking? I have included the start of the function below showing my so far fruitless attempts!
Thanks in advance for any assistance!
function y = eight_notches(t,P,T,~,~,x,ve,tfinal)
persistent h
i=t*1000;
h(i) = x;
assignin('base', 'h', h)
Réponse acceptée
Plus de réponses (1)
Torsten
le 2 Mai 2018
1 vote
Use the "event" facility of ODE45. It will help you to exactly locate the time when the valve is open.
Take a look at the "ballode" example.
Best wishes
Torsten.
2 commentaires
Steven Taggart
le 2 Mai 2018
Jan
le 2 Mai 2018
+1. This is the only valid approach to handle discontinuities. I've elaborated this only a bit.
Catégories
En savoir plus sur General Applications dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!