Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: ode45 event function problem
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Tijana

Posts: 2
Registered: 12/28/12
ode45 event function problem
Posted: Dec 28, 2012 5:51 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi,

Sorry if this is a double post.
I have a problem with the ode45 event function. I want to detect when the pairwise comonents of the solution multiplied by some 2x2 matrix A become positive and stop if this happens. This problem, however, appears in the derivative function which makes it seem that the event function is not called after every timestep.

Here is the call to the ode45:

[t, y] = ode45(@(t,y) dydt(t, y, dec, param, nVec, cellVolume),...
[tbeg : dt : tend], [hs; mSolute], odeset('MaxStep', 10, 'Events', @(t,y) ...
eventFcn(t, y, A)));

function [value, isterminal, direction] = eventFcn(t, y, A)
h = y(1 : end - 1);
value = [A(1,:) * reshaped A(2,:) * reshaped]';
isterminal = ones(length(h),1);
direction = zeros(length(h),1);

end

It happens in the function dydt that:

function g = dydt(t,y, ...)
hs = y(1 : end - 1)
for i = 1 : 2 : length(h)
h = [hs(i) hs(i+1)]'
valid = A * h;
idx = find(valid > 0);
if length(idx) > 0
error('should not happen');
else
g = ...
end
end


Any idea how to force the event function to be called after every timestep, if that is the problem?

Best,



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.