Skip to content

How the in-browser simulator works

  • See why a switching converter is a linear circuit within each switching interval, and what stepping it exactly means.
  • Compare the exact step with a simple integration rule on a fast time constant.
  • Know how the simulator finds the periodic steady state, and what that saves over a run from rest.

Between two switching events, every switch and diode of the simulator is either on or off, and what is left is a linear circuit: resistances, inductances, capacitances and constant sources. Its state, the inductor currents and the capacitor voltages, obeys linear differential equations with constant sources in each interval, the same description that state-space averaging starts from [Erickson & Maksimović 2020, Ch. 7]. For a capacitor charged through a resistance, the solution over a step is exact, however long the step:

v1=v∞+(v0−v∞)e−Δtτv_1 = v_\infty + \left(v_0 - v_\infty\right) e^{- \frac{\Delta t}{\tau}}
v1v_1
voltage after the step
Δt\Delta t
time step
τ\tau
time constant
v0v_0
voltage at the start of the step
v∞v_\infty
voltage it tends to
One exact time step of a first-order circuit✓ verified by 8 tests
Assumptions, convention and source
Assumptions
  • the circuit is linear and its sources stay constant during the step
  • single-pole (first-order) response to a step
Notes
each step multiplies the deviation from v∞v_\infty by e−Δt/τe^{-\Delta t/\tau}, which lies between 0 and 1 however long the step is: the step is exact, and the deviation cannot grow. An inductor's current follows the same law with the time constant L over R
Source
Alexander & Sadiku 2017, Ch. 7 (First-Order Circuits: the complete response); derived here
Derivation
step-by-step sympy derivation
Equation id
sim.exact_step · equations.yaml entry

A circuit with several states steps them all at once with the exponential of its equations’ matrix, which the simulator computes by scaling and squaring [Higham 2005]. Within an interval nothing is approximated beyond rounding, so the length of a step does not limit the accuracy of the state it reaches. The simulator still takes short sub-steps, a two-thousandth of the period or shorter, because it has to find the events: a diode could turn on and off again unseen within a long step (how it computes).

A general-purpose integrator approximates the solution over small steps instead. The simplest rule, forward Euler, steps with the slope at the start of the step, and multiplies a decaying mode’s deviation by a fixed factor in every step [Hairer & Wanner 1996]:

gFE=1−Δtτg_\mathrm{FE} = 1 - \frac{\Delta t}{\tau}
gFEg_\mathrm{FE}
forward Euler's factor per step
Δt\Delta t
time step
τ\tau
time constant
Forward Euler's factor per step on a decaying mode✓ verified by 8 tests
Assumptions, convention and source
Assumptions
  • one decaying mode on its own: its rate of change is minus its deviation over tau (the test equation)
  • the same time step every step
Notes
the rule takes the slope at the start of the step. Its factor stays between -1 and 1 only while the step is shorter than 2τ2\tau; a longer step multiplies the deviation by more than one in size and flips its sign every step, so the solution grows without bound. The circuit's fastest time constant, such as a small node capacitance behind a small resistance, then limits the step for the whole circuit
Source
Hairer & Wanner 1996, Sec. IV.2 (Stability Analysis for Explicit RK Methods: explicit Euler); derived here
Derivation
step-by-step sympy derivation
Equation id
num.gain_fe · equations.yaml entry

A step longer than twice the time constant makes the factor larger than one in size, and the solution grows without bound. A converter has fast time constants, such as a small capacitance at the switch node behind a small resistance, next to the slow ones of its output filter: a rule like this would have to take steps shorter than the fastest, over as many periods as the slowest needs. SPICE avoids the blow-up with implicit rules, which keep a decaying mode from growing whatever the step (see the ngspice page).

An interval ends when a switch changes state: at the gate’s edges, and when a diode’s current reaches zero or its voltage turns it on. The simulator finds that instant within the step on the same exact solution, so the next interval starts from the right state (how it computes).

In CCM, with a filter that rings, a converter’s output settles from rest with its filter’s envelope time constant (envelope time constant), and reaching a small fraction of the start-up error takes many periods (periods to settle). The simulator looks instead for the state at the start of a period that the period maps back onto itself: the periodic steady state, a fixed point of the map from one period’s initial state to the next. Newton’s method finds it in a few iterations with the map’s derivative, how the state at the end of a period depends on the state at its start [Aprille & Trick 1972]. For a converter that derivative is the product of the steps’ matrices, corrected at every event whose instant depends on the state, such as a diode’s current reaching zero (how it computes). When neither the switching instants nor the order of the intervals depends on the state, as in a buck whose current stays above zero, with no capacitance across its switch, the map is affine, a matrix times the state plus a constant, and a single Newton step lands on the steady state if there is only one.

A capacitance charging towards a voltage with a time constant of ten nanoseconds, stepped by fifty:

Exact-step example
SymbolValueHow it is obtained
v0v_0 voltage at the start of the step0 Vgiven
v∞v_\infty voltage it tends to10 Vgiven
τ\tau time constant10 nsgiven
Δt\Delta t time step50 nsgiven
v1v_1 voltage after the step9.93 VOne exact time step of a first-order circuit
gFEg_\mathrm{FE} forward Euler's factor per step−4Forward Euler's factor per step on a decaying mode

In one step of five time constants, the exact step brings the capacitor from 0 V to 9.93 V. Forward Euler’s factor for the same step is −4: its first step lands four times as far from the final voltage as it started, on the other side, and each further step does the same again.

▶ Open in the equation explorer: Forward Euler's factor per step on a decaying mode
Preset from the example sim-exact-step

Sweep the step: forward Euler’s factor stays within one in size only below twice the time constant.

▶ Open in the equation explorer: One exact time step of a first-order circuit
Preset from the example sim-exact-step

The exact step approaches the final voltage however long the step is. Open the simulator with the buck example: its steady state is computed directly, without a start-up.

▶ Open in the simulator: Buck
Preset from the example buck-basic

Charge a capacitor through a resistor from a function generator’s square wave, and capture the capacitor’s voltage. Read it at the start of a half-period and one time constant later, and compare with the exact step. Then take the samples twice the time constant apart and apply forward Euler’s rule by hand from the first one: the first step already overshoots the final voltage, while the circuit does not.

  • The steady state is not the start-up. Where a steady state exists, the simulator reports it; a start-up or a load step on the bench passes through transients it does not show. It draws the start-up from rest only when it finds no steady state.
  • A small step does not make an explicit rule stable by itself. For a mode that decays without ringing, the step must be shorter than twice the fastest time constant, even when that mode is too fast to matter (forward Euler's factor). A lightly damped ring needs a much shorter step still, and an undamped one grows at any step [Hairer & Wanner 1996, Sec. IV.2].
  • The plots draw samples. A peak narrower than a sub-step can be in the reported numbers but not in the plot.
  • Book chapter AC Equivalent Circuit Modeling (Ch. 7) — R. W. Erickson, D. Maksimović · retrieved 2026-09-23
    Averaging, perturbation and linearisation of converter equations, and the small-signal model of the PWM modulator.
  • Course 6.002 Circuits and Electronics (Spring 2007) — A. Agarwal, MIT OpenCourseWare (course content by A. Agarwal and J. H. Lang) · retrieved 2026-09-23
    MIT's first circuits course, with video lectures, notes and problem sets.
  1. Why can the simulator step each switching interval exactly?

    1. Because it uses very small steps
    2. Because it runs SPICE in the browser
    3. Within an interval the circuit is linear with constant sources, so its solution is an exponential it can compute
    4. Because converters have no capacitors
    Answer and explanation

    Correct answer: C Every switch and diode is on or off within the interval; the exponential of the circuit's matrix gives the exact solution over any step.

  2. A capacitor charges from 0 V towards 10 V with a time constant of 10 ns. Where is it after an exact step of 10 ns?

    1. About 6.3 V
    2. About 3.7 V
    3. 10 V
    4. 5 V
    Answer and explanation

    Correct answer: A The deviation from 10 V shrinks by e in one time constant: 10 V times (1 - 1/e) is about 6.3 V.

  3. Forward Euler steps a mode with a time constant of 10 ns by 50 ns. What does each step multiply its deviation by?

    1. About 0.007
    2. 1
    3. -4
    4. -1
    Answer and explanation

    Correct answer: C One minus the step over the time constant is 1 - 5: the deviation grows four times over and changes sign in every step.

  4. Up to what step does forward Euler keep a mode that decays without ringing from growing?

    1. Half the time constant
    2. The time constant
    3. Any step
    4. Twice the time constant
    Answer and explanation

    Correct answer: D The factor, one minus the step over the time constant, stays within one in size only for steps up to twice the time constant; a ringing mode needs a shorter step still.

  5. How does the simulator find the periodic steady state?

    1. It solves for the state at the start of a period that the period maps back onto itself, with Newton's method
    2. It simulates from rest until nothing changes
    3. It uses the averaged model
    4. It reads it from ngspice
    Answer and explanation

    Correct answer: A The steady state is a fixed point of the map from one period's start to the next; Newton's method finds it with the map's derivative.

  6. For a buck whose current stays above zero, with no capacitance across its switch, how many Newton steps does that take in principle?

    1. Hundreds
    2. One, because the period map is then affine: a matrix times the state, plus a constant
    3. As many as the envelope time constants
    4. None
    Answer and explanation

    Correct answer: B Neither the switching instants nor the order of the intervals depends on the state, and Newton's method solves an affine equation in one step if its solution is unique. A diode current reaching zero, or a capacitance across the switch that has to swing first, makes an instant depend on the state, and then it takes a few steps.

The numbers in the examples, presets and exercises on this site are synthetic: round teaching values, not data from any real design.