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: 1   Last Post: Jul 3, 2013 6:55 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

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


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


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?


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.