AC-DC Full-Wave Rectifier
Model an AC to DC full-wave rectifier with four diodes and a capacitor for smoothing the output.
vi[t_] = Sin[t];
vr[t_] = Abs[vi[t]]//PiecewiseExpand[#, t∈Reals]&;
Plot[{vi[t], vr[t]}, {t, 0, 16}]When vr increases,
; it charges the capacitor and supplies current to the load. When vr starts to decrease (
), the capacitor discharges through the load and the output voltage follows
:
system = {vo'[t] == charging[t]vr'[t] - (1 - charging[t])vo[t] / (r c), vo[0] == 0};
control = {charging[0] == 1, WhenEvent[vr'[t] < 0, charging[t] -> 0], WhenEvent[And[vo[t] < vr[t], charging[t] == 0, vr'[t] > 0], charging[t] -> 1]};pars = {r -> 0.1, c -> 1000};
sol = NDSolve[{system, control} /. pars, vo, {t, 0, 16}, DiscreteVariables -> charging∈{0, 1}];Plot[{vo[t] /. sol, vr[t]}, {t, 0, 16}]