Output a variable each time step using ODE45
Mostrar comentarios más antiguos
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)
2 comentarios
For ODE45, there does not exist something you call "previous time step" because the solver adaptively changes its time step size.
Maybe you could explain what you ultimatively try to do and why you need variables from the previous time step.
Steven Taggart
el 2 de Mayo de 2018
Respuesta aceptada
Más respuestas (1)
Torsten
el 2 de Mayo de 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 comentarios
Steven Taggart
el 2 de Mayo de 2018
Jan
el 2 de Mayo de 2018
+1. This is the only valid approach to handle discontinuities. I've elaborated this only a bit.
Categorías
Más información sobre General Applications en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!