Output a variable each time step using ODE45
Mostra commenti meno recenti
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)
Risposta accettata
Più risposte (1)
Torsten
il 2 Mag 2018
1 voto
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 Commenti
Steven Taggart
il 2 Mag 2018
Jan
il 2 Mag 2018
+1. This is the only valid approach to handle discontinuities. I've elaborated this only a bit.
Categorie
Scopri di più su General Applications in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!