Qurak

DC-to-DC buck converter

Example 5 steps, run in order in one session. Every step was executed against the engine and the output below is what it produced.

Step 1
system = {vo'[t] == -vo[t] / (r c) + i[t] / c , i'[t] == -vo[t] / l + q[t]vi / l, vo[0] == 0, i[0] == 0};

No output - this step sets something up for the next one.

Step 2
control = {q[0] == 1, WhenEvent[Mod[t, τ] == (vd / vi)τ, q[t] -> 0], WhenEvent[Mod[t, τ] == 0, q[t] -> 1]};

No output - this step sets something up for the next one.

Step 3
pars = {vi -> 24, vd -> 16, r -> 22, l -> 2 10 ^ -2, c -> 4 10 ^ -6, τ -> 2 10 ^ -4};

No output - this step sets something up for the next one.

Step 4
sol = NDSolve[{system, control} /. pars, {vo, i, q}, {t, 0, .01}, DiscreteVariables -> q, MaxSteps -> Infinity];

No output - this step sets something up for the next one.

Step 5
Row[{Plot[{vo[t] /. sol, vd /. pars}, {t, 0, .01}, PlotRange -> All, PlotLegends -> {"vo(t)", "vd"}], Spacer[50], Plot[q[t] /. sol, {t, 0, .001}, AxesLabel -> {t, q[t]}]}]
Output
-Graphics-Spacer[50]-Graphics-

Functions used

Related recipes

All recipes · Function reference · Use this from an MCP client