sam_rox
sam_rox

Reputation: 747

Using two conditions inside Events in Matlab ODE

I have a ODE Event as

options = odeset('RelTol',1e-11,'Events',@eventfunction);
    [time,values] = ode45(@Eq,time,x0,options);

function [value, isterminal,direction]=eventfunction(~,y)
value=y(1)+y(2)-1;
isterminal=1;
direction=0;
end  

I want to change this condition inside eventfunction so that the event will be triggered when y(1)+y(2) falls below 1 OR moves above 10^5.

How can I achieve this?

Upvotes: 0

Views: 493

Answers (1)

dweth
dweth

Reputation: 108

Specify vectors for value, isterminal, and direction.

value = [y(1)+y(2)-1, y(1)+y(2)-1e5];
isterminal = [1, 1];
direction = [0, 0];

Note that you can use direction = [], it functions the same as providing direction = zeros(1,length(value)).

Upvotes: 1

Related Questions