Piecewise functions and event detection in ODE solvers

1 view (last 30 days)
I am trying to solve a thyristor modelled as a DAE system and for that I need to detect when the thyristor turns ON and OFF.
The thyristor switching conditions are the following:
If Vak >= Vf & vg > Vgt | Iak > Il
Switch ON
else
Switch OFF
For such matter, I created a piecewise function with matlabFunction, which results in the following expression:
function cc = cNum1(t,in2,in3)
%CNUM1
% CC = CNUM1(T,IN2,IN3)
% This function was generated by the Symbolic Math Toolbox version 7.2.
% 21-Oct-2020 09:07:51
x2 = in2(2,:);
x4 = in2(4,:);
x5 = in2(5,:);
if ((0.0 <= x4-x5) || (1.0e-4 < x2))
cc = 1.0;
else
cc = 0.0;
end
Then, for detecting the events, I am using the following expressions, which depend on the ODE solver being used:
switch ode
case 'ode15i'
eHdl=@(t,x,dx) termIfZero(t,x,dx,h);
otherwise
eHdl=@(t,x) termIfZero(t,x,[],h);
end
Where
h =
cell
@cNum1
And where termIfZero is:
function [v,IS_TERM,d]=termIfZero(t,x,dx,h)
%%
disp(t)
%%
n=numel(h);
v=NaN(n,1);
d=zeros(n,1);
IS_TERM=1*ones(n,1);
%%
for i=1:n
v(i)=h{i}(t,x,dx);
end
end
The issue is that I don't get to make it work properly. It only detects a small part of the events that are supposed to detect.
Am I doing something wrong? Why can't I detect the events? I already tried changing AbsTol and RelTol and the max step but it didn't work either.
Best regards,
Nicolas

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!