odeset: 'Event' as a threshold not zero

5 Ansichten (letzte 30 Tage)
Sylvia Sullivan
Sylvia Sullivan am 16 Feb. 2016
Kommentiert: Sylvia Sullivan am 17 Feb. 2016
I want to halt ode execution and save the output after one of the functions drops below a certain bound. I'm trying to do this with odeset('Events',@events) as follows
function [sol,soln] = fullSScollHM8
% set parameters
options = odeset('Events',@events);
sol2 = ode15s(@fullSSfunc,[t0,tf],init,options);
end
function dy = fullSSfunc(~,y)
dy(1) = ...
dy(7) = ...
end
function [value,isterminal,direction] = events(~,y)
value = y(7) - 10^(-10);
% detect when y(7) gets too low
isterminal = 1; % halt integration
direction = 0; % any which way
end
But if I output value, the code continues to run when y(7) drops below 10^(-10) because value is never zero. It seems like it should be straightforward to define an 'Event' within odeset not with a zero but rather a threshold. Can someone help me please?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Feb. 2016
value = y(7) > 10^(-10); %false, 0, when y(7) falls far enough
Remember, a negative value is not a 0 and the termination is to occur when a 0 is detected. The documentation does imply that a crossing should be detected, but does not really state it outright.
  1 Kommentar
Sylvia Sullivan
Sylvia Sullivan am 17 Feb. 2016
Ok, value should be defined as a boolean. thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by