MATLAB ode113 Not Evaluating Events Function?

2 ビュー (過去 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 Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by