The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: ode45 event function problem
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

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


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);


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');
g = ...

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


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.