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