Tijana
Posts:
2
Registered:
12/28/12
|
|
ode45 event function problem
Posted:
Dec 28, 2012 5:39 AM
|
|
Hi,
I have a problem that my event function does not detect zero crossigns properly. The integration is supposed to stop if the pairwise components of the solution multiplied by some 2x2 matrix A become positive. It seems that it is not called in every timestep, but only occasionally.
Here is the ode45 call: [t, y] = ode45(@(t,y) dydt(t, y, dec, param, nVec, cellVolume),... [tbeg : dt : tend], [hs; mSolute], odeset('MaxStep', 10, 'RelTol', 1e-6, 'AbsTol', 1e-12, 'Events', @(t,y) ... eventFunc(t, y, A)));
and the event function:
function [value, isterminal, direction] = eventFunc(t, y, A)
h = y(1 : end - 1); reshaped = reshape(h, 2, length(h)/2); value = [A(1,:) * reshaped A(2,:) * reshaped]'; isterminal = ones(length(h),1); direction = zeros(length(h),1);
end
The problem is that in my derivative function it happens that this product is positive, and I cannot determine the derivative in this case.
Does anyone know how I can force the event function to be called after every timestep?
Thanks,
|
|