Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can't Handle Simultaneous Events with ODE45

285 views
Skip to first unread message

Trey

unread,
Dec 21, 2009, 3:29:04 PM12/21/09
to
Hi,

This issue is probably addressed elsewhere, but I have not been able to locate it yet. I am using ode45 for numerical simulations of a piecewise linear system. I detect an event, stop integration, make adjustments to the equations, and resume integration with new equations. I have 8 events total (4 actual functions, but direction matters for my code, so 8). The 4 unique event functions pertain to four physical components in the system. Typically, only one event is detected. However, due to the geometric arrangement of model, it is possible for multiple events to trigger (and I have to accurately adjust equations in multiple places if so), but it is not guaranteed (ie two events may occur on their own, or with each other, it depends). Each event has different physical meaning and requires different modifications to the equations. However, in cases where multiple events do occur,
I get the following error:

??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> ode45 at 425
ieout = [ieout, ie];


It appears to be a simple issue of concatenation (ieout is normally a single column vector, but when multiple events occur (ie 2 or more entries), it cannot append to ieout.

Is there something simple I am missing, whereby MATLAB can handle simultaneous event detection?

Do I need to modify the ode45 file logic when it comes to populating ieout, perhaps with some sort of preallocation of x columns, x being the maximum amount of simultaneous events that could occur?

I am an engineering student, by no means a MATLAB expert. Apologies if this question is easily resolved or discussed elsewhere. Code given below for reference,

Thanks

function [value,isterminal,direction] = eventsn(t,q)
value = [(sqrt((q(1)-x1)^2+(q(2)-y1)^2)-uL1)-s1,...
(sqrt((q(1)-x1)^2+(q(2)-y1)^2)-uL1)-s1,...
(sqrt((q(1)-x2)^2+(q(2)-y2)^2)-uL2)-s2,...
(sqrt((q(1)-x2)^2+(q(2)-y2)^2)-uL2)-s2,...
(sqrt((q(1)-x3)^2+(q(2)-y3)^2)-uL3)-s3,...
(sqrt((q(1)-x3)^2+(q(2)-y3)^2)-uL3)-s3,...
(sqrt((q(1)-x4)^2+(q(2)-y4)^2)-uL4)-s4,...
(sqrt((q(1)-x4)^2+(q(2)-y4)^2)-uL4)-s4]; % Detect zero of functions
isterminal = [1,1,1,1,1,1,1,1]; % Stop the integration for any event
direction = [-1,1,-1,1,-1,1,-1,1]; % Direction
end %function eventsn

Johan

unread,
Nov 17, 2011, 10:35:30 AM11/17/11
to
Did you, or someone else solve this problem? I get the same error.

Brendan

unread,
Jun 5, 2012, 9:22:05 PM6/5/12
to
"Johan" wrote in message <ja39k2$3k8$1...@newscl01ah.mathworks.com>...
> Did you, or someone else solve this problem? I get the same error.

I have gotten such a problem. I realized that I had more than one function registering an event at the same time. If you make sure that each event is registered by only one function, there should be no problem.

Mark V

unread,
Sep 2, 2015, 6:37:12 AM9/2/15
to
I just ran into this problem as well.
I have a single event function with 3 possible events.
2 of the 3 events can occur at the same time instance.

If 2 events occur simultaneously as first event occurrence in the simulation, it works.
If 1 single event occurs, later followed by 2 events simultaneously, I get the error mentioned above, i.e.

??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> ode45 at 425
ieout = [ieout, ie];


I could solve this by forcing the output of the event function to be in column format. So instead of:

value(2) = foo;
isterminal(2) = 1;
direction(2) = 1;

use:

value(2,1) = foo;
isterminal(2,1) = 1;
direction(2,1) = 1;

Houssam Abbas

unread,
Feb 12, 2016, 10:10:10 AM2/12/16
to
Same problem here and this solved it. At least the concatenation error is gone.
0 new messages