q[t] is a switching function, and I want to mark the corresponding time point when the value of q[t] changes from 1 to 0 in the curve. How should I rewrite my code? (From the code, it can be seen that when Mod [t, \ [Tau]]=(2/3) \ [Tau], q[t] changes from 1 to 0.)
The code:
tstart = 0;
tend = 0.06;
step = 0.00000005;
n = (tend - tstart)/step;
system = {vi q[t] == l iL'[t] + vC[t],
vC'[t] == iL[t]/c - vC[t]/(r c), vC[0] == 0, iL[0] == 0};
control = {q[0] == 1,
WhenEvent[Mod[t, \[Tau]] == (2/3) \[Tau], q[t] -> 0],
WhenEvent[Mod[t, \[Tau]] == 0, q[t] -> 1]};
pars = {vi -> 24, r -> 22, l -> 2 10^-2,
c -> 1 10^-4, \[Tau] -> 2.5 10^-5};
sol = NDSolve[{system, control} /. pars, {vC, iL, q}, {t, 0, .2},
StartingStepSize -> step,
Method -> {"FixedStep", Method -> "LinearlyImplicitEuler"},
DiscreteVariables -> q];
a = Evaluate[iL[t] /. sol];
b = Evaluate[vC[t] /. sol];
p1 = Plot[{a}, {t, 0, 0.08}, AxesLabel -> {"s", "il[t]/A"},
PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Green},
PlotRange -> All]
p2 = Plot[{b}, {t, 0, 0.08}, AxesLabel -> {"s", "vc[t]/A"},
PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Yellow},
PlotRange -> All]