MATLAB ode113 Not Evaluating Events Function?

5 views (last 30 days)
Hello,
I've worked with ode events in MATLAB many times now; however, I can't seem to figure out why the following events function not only won't trigger, but it's not even being evaluated:
options = odeset('RelTol',1e-12,'Events', @posEventsFcn);
[~,~,~,pos3i,~] = ode113(@findnegBt, tspan, [pos2(i,1) pos2(i,2) pos2(i,3)]', options);
where,
function [position,isterminal,direction] = posEventsFcn(~,y)
y(3)
pause
position = y(3); % The value that we want to be zero
isterminal = 1; % Halt integration
direction = 0; % The zero can be approached from either direction
end
The y(3) and pause never occur, leading me to believe this function is never evaluated.
Furthermore, if I print the y(3) values in the derivative-finding function ( @findnegBt ), I am able to watch the values change from positive/negative, approach zero, and become negative/positive - which to my understanding should trigger the events function (a change in sign).
Question: What reasons might there be for this event to not trigger, much less never be evaluated?
Note: I've already attempted reducing the integration tolerance and other parameters, but that didn't fix anything.
Thanks for your time and efforts!

Accepted Answer

Jan
Jan on 31 Aug 2017
The event function is not called only when the zero value is reached, but in each step to detect the crossing at all. If your event function is not called, there will be a reason outside your expectations. I guess, that the function handle @posEventsFcn points to a different M-file than you think it does. What do you get for:
which posEventsFcn -all
Are the multiple versions of this file or perhaps a sub-function, nested or private function?
You can use the debugger also: Open ode113 in the editor and search for the event handling. Then set a breakpoint there and check, where which function is called or why it is not called.
  1 Comment
John Chilleri
John Chilleri on 31 Aug 2017
There are only a few functions in this directory and it's uniquely named - but I think you're right.
I'm using a different computer than usual, so there may be directories added to the MATLAB path on startup, and I'm certain there are identically named functions in other folders.
Thank you, I'll return if this does not resolve the issue!

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!