MATLAB ode113 Not Evaluating Events Function?

조회 수: 4 (최근 30일)
John Chilleri
John Chilleri 2017년 8월 31일
댓글: John Chilleri 2017년 8월 31일
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!

채택된 답변

Jan
Jan 2017년 8월 31일
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
John Chilleri
John Chilleri 2017년 8월 31일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by