Output a variable each time step using ODE45
Ältere Kommentare anzeigen
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)
Akzeptierte Antwort
Weitere Antworten (1)
Torsten
am 2 Mai 2018
1 Stimme
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 Kommentare
Steven Taggart
am 2 Mai 2018
Jan
am 2 Mai 2018
+1. This is the only valid approach to handle discontinuities. I've elaborated this only a bit.
Kategorien
Mehr zu General Applications finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!