Event function for ODE solver with binary values
이전 댓글 표시
Is there any reason why creating an event function which can only take values of 1 or 0 a bad idea? If so, why?
I ask because, as I understand it, the event function, by definition, should recognize when the variable "crosses" 0, but technically if the outputs of my function are only 1 or 0, then it would never "cross" zero. However, I have been doing this and so far I don't think I have found any issues, except one time where my example didn't work and I never understood why.
As an example, the event function that I am using is the following:
function [value,isterminal,direction] = zeroevents(t,x,D)
%The event function should also accept yp (or xp) for the ode15i solver
isterminal = 1;
direction = 0;
insideD = D(t,x);
value = 1-insideD;
end
Where D(t,x) is a piecewise function with the following structure:
function out1 = D(t,x)
if x >= something
out1 = 1.0;
else
out1 = 0.0;
end
I hope the question is clear enough.
Thanks
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!