How to deal with two ode events triggered together?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I run an ode() with an event function that contains multiple conditions.
Sometimes, event 1 is triggered alone, sometimes event 2 is triggered alone, and sometimes both 1 and 2 are triggered at the same step. Event 3 is not terminal.
function [value,isterminal,direction] = events(~,u,par)
% Condition 1
value(1) = par(1) - u(1);
isterminal(1) = 1;
direction(1) = 1;
% Condition 2
value(2) = u(2) - par(2);
isterminal(2) = 1;
direction(2) = 0;
% Condition 3
value(3) = ...;
isterminal(3) = 0;
direction(3) = 0;
There are many instances where both conditions 1 and 2 are met, and the ODE function throws the following error:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in ode113 (line 534)
ieout = [ieout, ie];
Because two events take place at the same time, so while the vector ieout is e.g. [3 3 3] at that point, it is trying to append [1;2] to it, therefore the issue with dimensions.
Is there a way to deal with this issue?
Ideally, I would like to either keep the information of both events, or find a way to prioritize which event is registered over the other one. For the latter, I wrote something like this at the end:
if value(1) > 0 % event 1 is triggered
value(2) = u(2) - par(2)*10;
else
value(2) = u(2) - par(2);
end
However, when I look at value near the triggering of either or both events, I see values jumping between +/- very small values:
%value(2) value(1)
-4.70792933526809e-08 -4.02425144626197e-07
9.91988713394676e-11 8.47529370604861e-10
1.52766688188422e-13 1.30832340404161e-12
-1.52766688188422e-13 -1.30303203665395e-12
0 4.06575814682064e-19
-7.63833440942108e-14 -6.51517793708034e-13
-1.77635683940025e-15 -2.52266740483065e-16
And with the if statement included in the events:
%value(2) value(1)
-110.798199565154 8.78486128151433e-07
-7.03268163704251e-08 -6.01280467479593e-07
-110.798199667774 2.6680602297261e-09
-110.798199668085 8.03218133823246e-12
-9.36140054363932e-13 -7.98360688539571e-12
-110.798199668086 4.06575814682064e-19
-1.77635683940025e-15 -2.52266740483065e-16
I think during the steps it takes to go back and forth to find the exact crossing, the satisfaction of both or either event creates conflicts.
Therefore, my question to you is: is there a way to prioritize one of the events in case two terminal events are triggered together?
Thank you so much
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!