I have the following event function for ode45. I would like the event to stop when it reaches line 7 as I set isTerminal = [1,1], however for some reason it continues computing the solution. I can't understand what I'm doing wrong. Could someone help me understand what is wrong?
function [value, isTerminal, direction] = myEvent(t, z) xObst = 100; dist = xObst - z(1); if dist == 0 value = [0; z(3)]; isTerminal = [1; 1]; direction = [0; -1]; else value = [dist; z(3)]; isTerminal = [0; 1]; direction = [-1 ; -1]; end end
Best Answer