Friends from the community,
I am using the function WhenEvent as explained inder WhenEvent/Applications/Power electronics/Boost Converter. The model use there considers only one logical(discrete variable) q[t]. However, it is a nice but oversimplified example, though. A beter example muts consider two logical variables. Is this possible with WhenEvent[]? I have searched a case like that without any luck.
I have tiried this
tf = 0.03;
system = {vo'[t] == -vo[t]/(r c) + i[t] (1 - q[t])/c ,
i'[t] == (-(1 - q[t]) vo[t]/l + vi/l) g[t], vo[0] == 0,
i[0] == 0};
control = {q[0] == 0,
WhenEvent[Mod[t, \[Tau]] == 0.695 \[Tau], q[t] -> 0],
WhenEvent[Mod[t, \[Tau]] == 0, q[t] -> 1]};
control1 = {g[0] == 0, WhenEvent[q[t] == 1, g[t] -> 1],
WhenEvent[q[t] == 0 && i[t] != 0, g[t] -> 1],
WhenEvent[q[t] == 0 && i[t] == 0, g[t] -> 0]};
pars = {vi -> 5, vd -> 16, r -> 15, l -> 50 10^-6,
c -> 100 10^-6, \[Tau] -> 1/50000};
sol = NDSolve[{system, control, control1} /. pars, {vo, i, q, g}, {t,
0, tf}, DiscreteVariables -> {q, g}, MaxSteps -> Infinity];
GraphicsColumn[{Plot[{vo[t] /. sol, vd /. pars}, {t, 0, tf},
PlotRange -> All, PlotPoints -> 100],
Plot[{i[t] /. sol}, {t, 0, tf}, PlotRange -> All],
Plot[q[t] /. sol, {t, 0, .0004}]}]
Note that in this case q[t] and g[t] are related and must hold several constraints.
Can anyone help?
Thanks in advance.
Jesus

