MATLAB ode113 Not Evaluating Events Function?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposta accettata
Jan
il 31 Ago 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Function Creation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!