Event functions with ode15s not halting integration
Show older comments
I want to halt integration when the global variable "phase" switches from 2 to 3 or from 3 to 2 (it is always either 2 or 3). Here (below) is how I set this up in my event function, but it does not work even when I output value2 and see that it crosses zero many times. Does the value that crosses zero have to be one that is solved for by the ode solver? i.e. does it have to be part of the y vector?
function [value,isterminal,direction] = stopSolver(y)
global phase
value1 = y(1);
if phase == 3
value2 = 1;
elseif phase == 2
value2= -1;
end
value = [value1; value2];
isterminal = [1; 1]; % Stop the integration
direction = [0; 0]; % detect all zeros (default)
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!