Date: Dec 28, 2012 5:51 AM
Author: Tijana
Subject: ode45 event function problem


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?