I am marking my naive approach commented above as the answer for now.
ODE event: Is there a counter ?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Siddhartha Harsha Ommi
el 19 de Mzo. de 2021
Respondida: Siddhartha Harsha Ommi
el 15 de Abr. de 2021
Hi, Is there a way to terminate after an event occurs a certain number of times? I am thinking of using a counter in the ODE event function. But I am not sure how to pass it as an argument to the event function.
Thank you,
Sid
0 comentarios
Respuesta aceptada
Más respuestas (1)
Kiran Felix Robert
el 22 de Mzo. de 2021
Hi Siddhartha,
You don’t have to pass the counter as an argument to the event function, you can define the count variable as a global variable (persistent) and increment/decrement it, while not terminating the integration, until the control arrives at a count to terminate the integration.
The following snippet can be used as an example, for 10 events.
function [value,isterminal,direction] = Eventsfcn(t,y)
persistent count;
if isempty(count)
count = 10;
end
if count > 1
% Your code here
count = count - 1;
isterminal = 0; % Do not stop the integration
else
% Your Code here
isterminal = 1; % Stop the integration
end
2 comentarios
Siddhartha Harsha Ommi
el 28 de Mzo. de 2021
Editada: Siddhartha Harsha Ommi
el 28 de Mzo. de 2021
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!