Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
ode45 event function problem

Subject: ode45 event function problem

From: Tijana

Date: 28 Dec, 2012 10:39:07

Message: 1 of 2


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?


Subject: ode45 event function problem

From: Maurice

Date: 3 Jul, 2013 10:55:13

Message: 2 of 2

Did you solve this issue?
Thanks in advance

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us