Ordinary Differential Equations
An ordinary differential equation relates an unknown function of one variable to its derivatives. In electronics the variable is almost always time, and the unknowns are voltages, currents, temperatures, and shaft speeds. Capacitors and inductors are defined by derivatives, i = C dv/dt and v = L di/dt, so every circuit that stores energy obeys differential equations, and so do a motor accelerating its load and a heat sink warming up.
This article treats those equations as mathematics: classification, the classical solution of linear equations, forcing and resonance, systems and nonlinear equations, and numerical integration, including the integration inside SPICE, with worked examples on RC and RLC circuits, a thermal network, and a DC motor.
Transient Response of RC, RL, and RLC Circuits interprets the solutions physically, and the Laplace transform reaches them algebraically. Here t is time, a prime marks differentiation with respect to t, so that y′ = dy/dt, and j is the imaginary unit.
What an Ordinary Differential Equation Is
An equation is ordinary when its unknown depends on a single independent variable; the voltage along a transmission line, which varies with position as well as time, obeys partial differential equations instead. The order of an equation is that of its highest derivative: dv/dt + v/τ = 0 is first order, and d2y/dt2 + 3 dy/dt + 2y = 0 is second order.
Solutions and Initial-Value Problems
A solution satisfies the equation identically on an interval of t. Substitution shows that e−t solves the second-order equation above, since e−t − 3e−t + 2e−t = 0, and so does e−2t. An equation of order n normally has a general solution with n arbitrary constants, here K1e−t + K2e−2t, and n conditions select one member of the family. Conditions on y and its first n − 1 derivatives at one instant make an initial-value problem; conditions at two instants make a boundary-value problem, such as finding a periodic steady state.
Why Circuits Produce Differential Equations
Kirchhoff's laws are algebraic, but the element laws of capacitors and inductors contain derivatives. A current source iS(t) driving a resistor R and a capacitor C in parallel gives, by Kirchhoff's current law,
C dv/dt + v/R = iS(t)
a first-order equation in the capacitor voltage. In a circuit of resistors, capacitors, inductors, and independent sources, the order, meaning the number of independent initial conditions, equals the number of capacitors and inductors, less one for each independent loop made only of capacitors and voltage sources and one for each independent cutset made only of inductors and current sources. A circuit of order n gives n coupled first-order equations, or a single equation of order n or less in any one variable. Thermal networks and rotating machines obey equations of the same form.
Existence and Uniqueness
Write a first-order equation as dy/dt = f(t, y) with y(t0) = y0. The Picard–Lindelöf theorem guarantees exactly one solution on some interval around t0 when f is continuous near (t0, y0) and Lipschitz in y there: a constant M exists with |f(t, y1) − f(t, y2)| ≤ M|y1 − y2| for nearby y1 and y2. A continuous partial derivative ∂f/∂y near the point implies the Lipschitz condition, and the theorem extends to systems and so to equations of any order.
Continuity alone guarantees a solution but not a unique one: dy/dt = 3y2/3 with y(0) = 0 is solved by both y = 0 and y = t3, because the slope of y2/3 is unbounded at zero. The guarantee is also local: dy/dt = y2 with y(0) = 1 gives y = 1/(1 − t), which escapes to infinity as t approaches 1. Linear equations escape both limits: when the coefficients and input are continuous on an interval and the leading coefficient never vanishes there, the solution exists and is unique on that whole interval.
Classifying Equations
An equation is linear when the unknown and its derivatives appear only to the first power, multiplied by functions of t alone; t2 dy/dt + y = sin t is linear, and dy/dt + y2 = 0 is not. A linear equation is homogeneous when every term contains the unknown, and forced, or nonhomogeneous, when an input term f(t) free of the unknown is present; its coefficients are constant or time-varying; and an equation in which t does not appear explicitly is autonomous. The general linear equation of order n is
an(t) dny/dtn + … + a1(t) dy/dt + a0(t)y = f(t)
Linearity brings superposition: combinations of homogeneous solutions are solutions, the response to a sum of inputs is the sum of the responses, and every solution of the forced equation is one particular solution yp plus a homogeneous solution yh. The classical method follows that structure, with the arbitrary constants of yh fitted to the complete solution, y = yh + yp.
| Equation | Origin | Order | Type |
|---|---|---|---|
| C dv/dt + v/R = iS(t) | Parallel RC circuit driven by a current source | 1 | Linear, constant coefficients, forced |
| LC d2v/dt2 + RC dv/dt + v = vS(t) | Series RLC circuit, capacitor voltage | 2 | Linear, constant coefficients, forced |
| C dv/dt + v/R(t) = 0 | Capacitor discharging through a varying resistance | 1 | Linear, time-varying, homogeneous |
| C dv/dt + IS[ev/(nVT) − 1] = I | Diode and capacitor fed by a constant current | 1 | Nonlinear, autonomous |
| d2x/dt2 − μ(1 − x2) dx/dt + x = 0 | Van der Pol oscillator | 2 | Nonlinear, autonomous |
First-Order Equations
Separation of Variables
An equation is separable when it can be written dy/dt = g(t)h(y). Dividing by h(y) and integrating each side with respect to its own variable gives
∫ dy/h(y) = ∫ g(t) dt + K
The source-free RC circuit, dv/dt = −v/τ with τ = RC, separates into dv/v = −dt/τ, so ln|v| = −t/τ + K and v(t) = V0e−t/τ. Dividing by h(y) discards constant solutions where h(y) = 0, here v = 0, so they must be checked separately.
The method also works when h(y) is nonlinear. Model a capacitor C discharging through a diode-connected MOSFET by the square law, i = (β/2)(v − Vth)2 above the threshold voltage Vth, where β is the transconductance parameter. With u = v − Vth, C du/dt = −(β/2)u2 separates into du/u2 = −[β/(2C)] dt, and integrating from u0 gives
u(t) = u0/[1 + βu0t/(2C)]
With C = 100 nF, β = 10 mA/V2, and u0 = 2 V, the discharge starts at 20 mA, and the voltage above threshold halves after 10 µs, again 20 µs later, and again 40 µs after that. The decay is hyperbolic and has no time constant. A real transistor keeps conducting below threshold, so the model covers only the discharge above it.
The Integrating Factor
Every first-order linear equation can be written in the standard form
dy/dt + p(t)y = q(t)
Multiplying by the integrating factor μ(t) = exp[∫p(t) dt] makes the left side an exact derivative, because d(μy)/dt = μ dy/dt + μpy. The equation becomes d(μy)/dt = μq, and one integration gives
y(t) = [∫μ(t)q(t) dt + K]/μ(t)
The formula holds when p varies with time, provided the integrals can be evaluated. With constant coefficients, as in an RC or RL circuit, write dy/dt + y/τ = x(t)/τ, with the input x(t) scaled so that a constant input X gives the final value X; then μ = et/τ, and integrating from 0 to t gives
y(t) = y(0)e−t/τ + (1/τ) ∫0t e−(t − σ)/τ x(σ) dσ
The first term is the zero-input response, set by the initial state, and the second is the zero-state response, the convolution of the input with the impulse response (1/τ)e−t/τ. A constant input X gives the familiar y(t) = X + [y(0) − X]e−t/τ.
Second-Order Equations with Constant Coefficients
The standard form is
a d2y/dt2 + b dy/dt + cy = f(t)
with real constants a, b, and c, and a > 0, which a change of sign always arranges. The homogeneous equation has two linearly independent solutions, y1 and y2, and every homogeneous solution is a combination yh = K1y1 + K2y2.
The Characteristic Equation
Because the derivatives of an exponential are multiples of it, the trial solution y = eλt reduces the homogeneous equation to (aλ2 + bλ + c)eλt = 0, so λ must satisfy the characteristic equation
aλ2 + bλ + c = 0, with roots λ = [−b ± √(b2 − 4ac)]/(2a)
The roots are the natural frequencies of the system and the poles of its transfer function, and the sign of the discriminant, b2 − 4ac, sets the form of the homogeneous solution.
| Discriminant | Roots | Homogeneous solution |
|---|---|---|
| b2 − 4ac > 0 | Real and distinct, λ1 and λ2 | K1eλ1t + K2eλ2t |
| b2 − 4ac = 0 | Real and repeated, λ = −b/(2a) | (K1 + K2t)eλt |
| b2 − 4ac < 0 | Complex conjugates, σ ± jωd | eσt(K1 cos ωdt + K2 sin ωdt) |
In the complex case σ = −b/(2a) and ωd = √(4ac − b2)/(2a). Every root has a negative real part, and every homogeneous solution decays, exactly when b and c are also positive. For c > 0 the equation can be written d2y/dt2 + 2ζω0 dy/dt + ω02y = f(t)/a, with ω0 = √(c/a) and ζ = b/[2√(ac)], and for b ≥ 0 the three forms become the overdamped (ζ > 1), critically damped (ζ = 1), and underdamped (0 ≤ ζ < 1) responses of the transient-response article.
Why the Three Forms Work
Distinct roots each supply an exponential: for d2y/dt2 + 5 dy/dt + 4y = 0, (λ + 1)(λ + 4) = 0 gives yh = K1e−t + K2e−4t. A repeated root supplies one exponential, and teλt is the second solution: for distinct roots, (eλ1t − eλ2t)/(λ1 − λ2) is a solution, and as λ2 approaches λ1 it becomes the derivative of eλt with respect to λ, which is teλt.
Complex roots arrive in conjugate pairs because the coefficients are real, and by Euler's formula, ejθ = cos θ + j sin θ, the complex solutions e(σ ± jωd)t combine into the real solutions eσt cos ωdt and eσt sin ωdt. The combination eσt(K1 cos ωdt + K2 sin ωdt) equals Aeσt cos(ωdt − φ), with A = √(K12 + K22), cos φ = K1/A, and sin φ = K2/A.
Higher Orders
At order n, each distinct real root λ of the characteristic polynomial contributes eλt, a root of multiplicity m contributes eλt, teλt, …, tm−1eλt, and each complex pair contributes cosine and sine terms with the same powers of t. The denominator of a third-order Butterworth low-pass filter normalized to 1 rad/s gives λ3 + 2λ2 + 2λ + 1 = (λ + 1)(λ2 + λ + 1), with roots −1 and −½ ± j√3/2, so that
yh = K1e−t + e−t/2[K2 cos(√3 t/2) + K3 sin(√3 t/2)]
Every homogeneous solution decays exactly when every root has a negative real part, the stability condition for poles, and the Routh–Hurwitz test settles that question without finding the roots.
Initial Conditions and Fitting the Constants
An equation of order n needs n conditions, normally y and its first n − 1 derivatives at the starting instant. In a circuit the known quantities are the capacitor voltages and inductor currents, which normally cannot jump, and derivatives follow from the element laws; a capacitor voltage starts with the slope iC(0+)/C. For any linear equation:
- Find a particular solution yp.
- Write the complete solution, y = yh + yp, with the constants still unknown.
- Differentiate it once for each derivative condition.
- Evaluate at the starting instant and solve the resulting linear equations for the constants.
- Check the initial values, the final value, and the original equation.
Fitting the constants to yh alone is a common error, and it fails whenever yp or its derivatives are nonzero at the start. For d2y/dt2 + 5 dy/dt + 4y = 8 with y(0) = 0 and y′(0) = 0, the constant yp = 2 gives y = 2 + K1e−t + K2e−4t; the conditions 2 + K1 + K2 = 0 and −K1 − 4K2 = 0 give K1 = −8/3 and K2 = 2/3, so
y(t) = 2 − (8/3)e−t + (2/3)e−4t, for t ≥ 0
The result starts at zero with zero slope and settles at 2, the constant that solves 4y = 8.
When an impulse or an idealized circuit forces a state variable to jump, the values at 0− and 0+ differ. The classical method needs the values at 0+, while the Laplace transform, taken from 0−, starts from the values before the event and accounts for the jump.
Forced Response: The Method of Undetermined Coefficients
For the common engineering inputs, a particular solution can be guessed. Polynomials, exponentials, sinusoids, and their products have derivatives within a small family of functions, so a trial solution from that family, with unknown coefficients, turns the equation into algebra: substitute, collect like terms, and equate coefficients.
| Input f(t) | Trial solution yp |
|---|---|
| Constant F | A |
| Polynomial of degree k | Aktk + … + A1t + A0 |
| Keat | Aeat |
| K cos ωt or K sin ωt | A cos ωt + B sin ωt |
| Keat cos ωt or Keat sin ωt | eat(A cos ωt + B sin ωt) |
| tkeat | (Aktk + … + A1t + A0)eat |
One rule modifies the table: if any term of the trial solution already solves the homogeneous equation, multiply the whole trial solution by tm, where m is the multiplicity of the matching characteristic root, because otherwise the matching terms vanish on substitution and leave nothing to balance the input. For a capacitor charged by a constant current, C dv/dt = I, the root is zero, the trial solution is At, and v = It/C is a ramp.
Exponential and Constant Inputs
Write the characteristic polynomial as P(λ), so that the equation reads P(d/dt)y = f(t). For the input Keat, the trial solution Aeat gives P(a)A = K, so
yp = Keat/P(a), provided that P(a) is not zero
A constant input F is the case a = 0, which gives yp = F/c for the second-order standard form. The factor 1/P(a) is the transfer function evaluated at s = a. When a is a simple root of P, the rule becomes yp = Kteat/P′(a), and for a root of multiplicity m, yp = Ktmeat/P(m)(a), with P(m) the mth derivative of P. The input then matches a natural mode, a form of resonance that the first-order RC example below shows.
Sinusoidal Inputs
A sinusoid is the real part of a complex exponential, cos ωt = Re{ejωt}, so for real coefficients the exponential rule gives the particular solution for K cos ωt as the real part of Kejωt/P(jω):
yp = [K/|P(jω)|] cos(ωt − θ), where θ is the angle of P(jω)
This is the phasor method of AC Circuit Analysis in another notation. For dy/dt + 1000y = 1000 cos 1000t, an RC low-pass filter with a 1 ms time constant driven at 1000 rad/s, P(j1000) = 1000 + j1000 has the magnitude 1414 and the angle 45°, so yp = 0.707 cos(1000t − 45°), which equals the 0.5 cos 1000t + 0.5 sin 1000t that the trial solution gives.
Other Inputs and the Steady State
Inputs outside the table need a general method: variation of parameters, which replaces the constants of yh with functions of time, or, for a system starting at rest, the convolution of the input with the impulse response. A pulse or other piecewise input is solved interval by interval, each final state becoming the next initial state.
When every characteristic root has a negative real part, yh decays and yp remains, so for a constant or sinusoidal input the table's particular solution, which contains no natural modes, is the steady-state response.
Resonance
Resonance occurs when an input matches, or nearly matches, a natural mode. It is clearest in the undamped equation
d2y/dt2 + ω02y = F cos ωt
which models a lossless LC circuit or a frictionless spring and mass, and whose homogeneous solutions are cos ω0t and sin ω0t.
Undamped Resonance and Beats
For ω different from ω0, the trial solution A cos ωt gives yp = F cos ωt/(ω02 − ω2), whose amplitude grows without limit as ω approaches ω0. From rest, with y(0) = 0 and y′(0) = 0, the complete solution is
y(t) = F(cos ωt − cos ω0t)/(ω02 − ω2) = [2F/(ω02 − ω2)] sin[(ω0 − ω)t/2] sin[(ω0 + ω)t/2]
an oscillation at the mean frequency inside an envelope that varies at half the difference frequency, so that the amplitude swells and fades at the difference frequency itself: the beats. At ω = ω0, cos ω0t solves the homogeneous equation, so the trial solution must be multiplied by t, and substitution gives
y(t) = [F/(2ω0)] t sin ω0t
which already satisfies both initial conditions. The amplitude grows in proportion to t without bound, and the same function is the limit of the beat solution as ω approaches ω0.
Damped Resonance
Damping bounds the growth. For d2y/dt2 + 2ζω0 dy/dt + ω02y = F cos ωt with ζ > 0, the natural modes decay and leave the steady-state solution
yp = F cos(ωt − θ)/√[(ω02 − ω2)2 + (2ζω0ω)2]
where θ, between 0 and 180°, is the angle of (ω02 − ω2) + j2ζω0ω. Dividing the amplitude by F/ω02, the response to a constant input of the same size, gives the magnification, which equals the quality factor Q = 1/(2ζ) at ω = ω0, where the response lags by 90°. For ζ < 1/√2 the magnification peaks at ω0√(1 − 2ζ2) with the value 1/[2ζ√(1 − ζ2)]; with more damping it has no peak. The amplitude of dy/dt, which is proportional to the current when y is the capacitor voltage of a series RLC circuit, peaks exactly at ω0.
| ζ | Q = 1/(2ζ) | Peak frequency, ω/ω0 | Peak magnification |
|---|---|---|---|
| 0.01 | 50 | 0.9999 | 50.00 |
| 0.05 | 10 | 0.9975 | 10.01 |
| 0.1 | 5 | 0.9899 | 5.025 |
| 0.25 | 2 | 0.9354 | 2.066 |
| 0.5 | 1 | 0.7071 | 1.155 |
Systems of First-Order Equations
Any equation of order n can be rewritten as n first-order equations: for the second-order standard form, x1 = y and x2 = dy/dt give dx1/dt = x2 and dx2/dt = −(c/a)x1 − (b/a)x2 + f(t)/a. Circuits usually arrive in this form, one first-order equation per capacitor or inductor. A linear system with constant coefficients is written
dx/dt = Ax + Bu
where x holds the n state variables and u the inputs, A is an n × n matrix, and B routes the inputs. With matrices written row by row, commas between entries and semicolons between rows, as in State-Space Analysis and Control, a series RLC circuit driven by a voltage source, with the inductor current i and the capacitor voltage vC as states, has
A = [−R/L, −1/L; 1/C, 0], B = [1/L; 0]
Its characteristic equation, det(λI − A) = λ2 + (R/L)λ + 1/(LC) = 0, is that of the second-order equation for vC: the eigenvalues of A are the characteristic roots. When A has n independent eigenvectors, the columns of a matrix V, the substitution x = Vz separates the system into uncoupled first-order equations, one per natural mode. The complete solution is
x(t) = eAtx(0) + ∫0t eA(t − σ)Bu(σ) dσ
where the matrix exponential, eAt = I + At + (At)2/2! + …, plays the role of e−t/τ in the first-order formula. The first-order form handles any number of coupled variables, is the form that numerical solvers accept, and extends directly to nonlinear systems, dx/dt = f(x, u).
Nonlinear Equations and Linearization
Nonlinear equations lose superposition, and closed-form solutions are the exception. They also show new behavior: multiple equilibria, self-sustained oscillations called limit cycles, finite escape times, and chaos, which an autonomous system can show only with three or more state variables. Nonlinear Circuit Analysis surveys the specialized methods; linearization carries linear results over locally.
Equilibria and the Jacobian
An autonomous system dx/dt = f(x) is at equilibrium where f(x*) = 0. A small deviation δx = x − x* then obeys, to first order,
d(δx)/dt = J δx
where J is the Jacobian matrix of partial derivatives ∂fi/∂xk evaluated at x*. By Lyapunov's indirect method, the eigenvalues of J decide local stability: if every eigenvalue has a negative real part, the equilibrium is locally asymptotically stable; if any has a positive real part, it is unstable; and if the largest real part is exactly zero, the linearization cannot decide.
A diode fed by a constant current I, with a capacitor C across it, obeys C dv/dt = I − IS[ev/(nVT) − 1]. At equilibrium the diode current equals I, and the slope of the diode law there, the small-signal conductance gd = (I + IS)/(nVT), gives small deviations the time constant C/gd. With I = 1 mA, n = 1, VT = 25.85 mV at 300 K, and C = 10 µF, gd = 38.7 mS and the time constant is 258.5 µs. In the nonlinear equation, a 2 mV rise decays to 1/e in 252 µs and a 2 mV fall in 265 µs, near the linear value, but a 26 mV rise does so in 186 µs and a 26 mV fall in 350 µs, because the diode's conductance changes exponentially with voltage.
A Self-Sustained Oscillator
The van der Pol equation, d2x/dt2 − μ(1 − x2) dx/dt + x = 0 with μ > 0, models an oscillator whose amplifier supplies energy at small amplitudes and absorbs it at large ones; Balthasar van der Pol published "On 'Relaxation-Oscillations'" in the Philosophical Magazine in 1926. With x1 = x and x2 = dx/dt, the Jacobian at the origin is [0, 1; −1, μ], whose eigenvalues, [μ ± √(μ2 − 4)]/2, have positive real parts, so any disturbance grows. Only the nonlinear equation says where the growth stops: numerical solution shows a limit cycle with a peak amplitude of 2.000 and a period of 6.287 for μ = 0.1, and 2.009 and 6.663 for μ = 1, in the equation's normalized time.
Numerical Solution: Euler and Runge–Kutta Methods
A numerical method advances dy/dt = f(t, y) in steps of size h, producing approximations yn to y(tn). The error of one step from exact starting values is the local truncation error, and the error accumulated by a fixed final time is the global error; a method of order p has a global error proportional to hp. The Euler methods and the trapezoidal rule reappear in Digital Control Systems as ways to discretize a controller, the trapezoidal rule as Tustin's method.
Forward Euler follows the tangent line, yn+1 = yn + h f(tn, yn); it is explicit, costs one evaluation of f per step, and is first order. The classical fourth-order Runge–Kutta method samples the slope four times per step and weights the samples to cancel lower-order error terms:
k1 = f(tn, yn), k2 = f(tn + h/2, yn + hk1/2), k3 = f(tn + h/2, yn + hk2/2), k4 = f(tn + h, yn + hk3)
yn+1 = yn + (h/6)(k1 + 2k2 + 2k3 + k4)
The family is named for Carl Runge, who published a method of this kind in Mathematische Annalen in 1895, and Wilhelm Kutta, whose doctoral thesis, published in 1901, developed it further. The table compares four methods, including the two implicit methods of the next section, on an RC discharge with τ = 1 ms from 1 V, whose exact value at t = 1 ms is e−1 = 0.367879 V.
| Step h | Forward Euler | Backward Euler | Trapezoidal rule | Fourth-order Runge–Kutta |
|---|---|---|---|---|
| 0.1 ms | −1.92 × 10−2 | +1.77 × 10−2 | −3.07 × 10−4 | +3.33 × 10−7 |
| 0.05 ms | −9.39 × 10−3 | +9.01 × 10−3 | −7.67 × 10−5 | +2.00 × 10−8 |
| 0.025 ms | −4.65 × 10−3 | +4.55 × 10−3 | −1.92 × 10−5 | +1.22 × 10−9 |
| Order | 1 | 1 | 2 | 4 |
Halving the step divides the errors by about 2, 2, 4, and 16, as the orders predict. At h = 0.1 ms, Runge–Kutta evaluates f 40 times, as often as forward Euler at h = 0.025 ms, yet its error is about 14,000 times smaller.
Practical solvers adapt h, using an embedded pair of formulas of different order to estimate the local error and resize each step within set tolerances. MATLAB's ode45 is based on the Dormand–Prince pair, published by J. R. Dormand and P. J. Prince in 1980, and SciPy's solve_ivp defaults to RK45, an explicit Runge–Kutta method of order 5(4) from the same pair. For stiff problems MathWorks recommends ode15s, and the SciPy documentation recommends the implicit Radau and BDF methods. The control acts on local error, so tightening the tolerance and comparing results is the simplest check.
Stiffness and Implicit Methods
Stability also limits the step. On dy/dt = −y/τ, forward Euler gives yn+1 = (1 − h/τ)yn, which decays only if h < 2τ. For τ < h < 2τ it alternates in sign as it decays, and for h > 2τ it grows without bound although the true solution decays. Every explicit method has such a limit; for classical Runge–Kutta it is h < 2.785τ.
A system is stiff when it has decaying natural modes much faster than the solution of interest: after the fast modes die away, accuracy would permit long steps, but an explicit method's stability still ties the step to the fastest time constant. Circuits are often stiff, because parasitic capacitances and inductances create time constants far shorter than the intended response.
Implicit Methods
Implicit methods evaluate the slope at the new point, so each step solves an equation for yn+1:
Backward Euler: yn+1 = yn + h f(tn+1, yn+1)
Trapezoidal rule: yn+1 = yn + (h/2)[f(tn, yn) + f(tn+1, yn+1)]
On the test equation they multiply y by 1/(1 + h/τ) and by [1 − h/(2τ)]/[1 + h/(2τ)] per step, factors smaller than 1 in magnitude for every positive h. Both are A-stable: every decaying linear mode also decays numerically, whatever the step.
| Method | h = 0.5τ | h = 1.5τ | h = 3τ | h = 10τ |
|---|---|---|---|---|
| Exact, e−h/τ | 0.607 | 0.223 | 0.0498 | 0.0000454 |
| Forward Euler | 0.500 | −0.500 | −2.00 | −9.00 |
| Fourth-order Runge–Kutta | 0.607 | 0.273 | 1.375 | 291 |
| Backward Euler | 0.667 | 0.400 | 0.250 | 0.0909 |
| Trapezoidal rule | 0.600 | 0.143 | −0.200 | −0.667 |
At long steps, backward Euler damps fast modes strongly, at the price of first-order accuracy. The trapezoidal rule is second order and preserves the amplitude of an undamped oscillation, but for a fast mode and a long step its factor approaches −1, and the mode lingers as a slowly decaying step-to-step alternation: the trap ringing that circuit simulators can show after an abrupt edge.
By Germund Dahlquist's second barrier, from his 1963 paper in BIT, no A-stable linear multistep method exceeds order 2, which the trapezoidal rule attains. The backward differentiation formulas, which circuit simulators call Gear methods, exceed order 2 by giving up full A-stability above that order. The second-order formula, yn+1 = (4/3)yn − (1/3)yn−1 + (2/3)h f(tn+1, yn+1), is A-stable and damps fast modes as backward Euler does; orders 3 through 6 are stable over a wedge of the left half-plane containing the negative real axis; and higher orders are unstable.
How SPICE Integrates
SPICE applies these methods to modified nodal analysis, whose equations mix differential and algebraic ones, because a node without capacitance contributes no derivative. At each time point the integration formula turns each capacitor and inductor into a companion model. Under backward Euler, i = C dv/dt becomes in+1 = (C/h)vn+1 − (C/h)vn, a conductance C/h with a current source set by the previous voltage; under the trapezoidal rule it becomes in+1 = (2C/h)vn+1 − [(2C/h)vn + in]. Each time point is then a resistive circuit, solved by Newton–Raphson iteration when devices are nonlinear, and an estimate of the local truncation error decides whether to accept the point and how long the next step may be.
In ngspice, trapezoidal integration is the default; .options method=gear selects Gear integration, with a maximum order, MAXORD, from 2, the default, to 6; and MAXORD = 1 with the trapezoidal method gives backward Euler. The manual notes that reducing XMU, the trapezoidal damping factor, slightly below its default of 0.5, for example to 0.495, may suppress trap ringing, though too much damping can make a circuit prone to ringing look stable. Transient Response of RC, RL, and RLC Circuits shows how to recognize trap ringing, and Circuit Simulation (SPICE) covers convergence settings.
Worked Examples: RC and RLC Circuits
An RC Stage Driven by an Exponential
A unity-gain buffer applies the decaying voltage Ve−t/τ1, with V = 5 V, to an RC low-pass filter with R = 10 kΩ and C = 100 nF, so that τ = RC = 1 ms. The capacitor starts discharged. Find the output v(t) for input time constants of 2 ms, 0.5 ms, and 1 ms.
- Write the equation. Kirchhoff's current law at the output gives C dv/dt = (Ve−t/τ1 − v)/R, or τ dv/dt + v = Ve−t/τ1, with v(0) = 0.
- Apply the integrating factor. Dividing by τ and multiplying by et/τ gives d(vet/τ)/dt = (V/τ) exp[t(1/τ − 1/τ1)].
- Integrate from zero. For τ1 different from τ, v(t) = [Vτ1/(τ1 − τ)](e−t/τ1 − e−t/τ), which peaks when t = [ττ1/(τ1 − τ)] ln(τ1/τ).
- Evaluate. For τ1 = 2 ms, v(t) = 10(e−t/2 ms − e−t/1 ms) V, which peaks at 2.50 V at t = 1.39 ms. For τ1 = 0.5 ms, v(t) = 5(e−t/1 ms − e−t/0.5 ms) V, which peaks at 1.25 V at t = 0.693 ms.
- Treat the matching case. At τ1 = τ the input is the filter's own natural mode, the integrand is the constant V/τ, and v(t) = V(t/τ)e−t/τ, which peaks at V/e = 1.84 V at t = 1 ms.
Every solution starts at zero with the slope V/τ = 5,000 V/s. The matching case is the limit of the general solution as τ1 approaches τ, and the exponential rule gives it directly, since P(λ) = τλ + 1 has the simple root −1/τ and P′ = τ.
A Series RLC Circuit Driven at Resonance
A source vS(t) = sin 10,000t volts, switched on at t = 0, drives a series loop of R = 20 Ω, L = 10 mH, and C = 1 µF that starts at rest. Find the capacitor voltage v(t).
- Write the equation. From LC d2v/dt2 + RC dv/dt + v = vS, dividing by LC = 10−8 s2 gives d2v/dt2 + 2000 dv/dt + 108v = 108 sin 10,000t, with v(0) = 0 and dv/dt(0) = i(0)/C = 0.
- Find the roots. λ2 + 2000λ + 108 = 0 gives λ = −1000 ± j9950, so ω0 = 10,000 rad/s, ζ = 0.1, and Q = 5. The source runs at ω0, but ±j10,000 are not roots, so the trial solution needs no factor of t.
- Find the particular solution. Substituting A cos 10,000t + B sin 10,000t, the terms in ω02 cancel, and the damping term must supply the input: 2 × 107(B cos 10,000t − A sin 10,000t) = 108 sin 10,000t, so B = 0, A = −5, and vp = −5 cos 10,000t V, Q times the source amplitude and 90° behind it.
- Fit the constants. With v = −5 cos 10,000t + e−1000t(K1 cos 9950t + K2 sin 9950t), v(0) = 0 gives K1 = 5, and dv/dt(0) = −1000K1 + 9950K2 = 0 gives K2 = 0.503.
- State the result. For t ≥ 0, with t in seconds, v(t) = −5 cos 10,000t + e−1000t(5 cos 9950t + 0.503 sin 9950t) V.
Because 9950 rad/s is so close to 10,000 rad/s, the decaying terms at first nearly cancel the steady one, so the amplitude starts to build at about 5,000 V/s, as in the undamped case, reaches about 3.2 V after 1 ms, and stays within 1 percent of 5 V after about 4.6 ms. Without the resistor the roots become ±j10,000, the trial solution needs the factor t, and v(t) = −5000t cos 10,000t + 0.5 sin 10,000t V grows by 5 V every millisecond.
Worked Examples: A Thermal Network and a DC Motor
A Two-Node Thermal Network
A transistor dissipating P = 20 W sits on a heat sink. Model the package as a node with thermal capacitance C1 = 2 J/K, about that of 5 g of copper, joined to the heat sink by R1 = 1.0 K/W, and the heat sink as a node with C2 = 90 J/K, about that of 100 g of aluminum, joined to the air by R2 = 1.5 K/W. The values are illustrative, and the model is a two-node Cauer ladder. Find the temperature rises above ambient, θ1 and θ2, after the power switches on at t = 0.
- Write the node equations. Heat flow balances at each node as current does in an RC circuit: C1 dθ1/dt = P − (θ1 − θ2)/R1 and C2 dθ2/dt = (θ1 − θ2)/R1 − θ2/R2.
- Put them in matrix form. With t in seconds, dθ/dt = Aθ + [P/C1; 0], where A = [−0.5, 0.5; 0.01111, −0.01852].
- Solve the characteristic equation. det(λI − A) = λ2 + 0.51852λ + 0.0037037 = 0 gives λ1 = −0.007244 s−1 and λ2 = −0.5113 s−1, time constants of 138.0 s and 1.956 s. The constant term equals 1/(R1C1R2C2), a quick check.
- Find the particular solution. In the steady state all 20 W flows through both resistances, so θ2 = PR2 = 30 K and θ1 = P(R1 + R2) = 50 K.
- Fit the constants. Each rise is its final value plus multiples of eλ1t and eλ2t in the proportions set by the eigenvectors of A, and requiring both rises to start at zero gives the result below, in kelvins.
θ1(t) = 50 − 30.88e−t/138.0 − 19.12e−t/1.956
θ2(t) = 30 − 30.43e−t/138.0 + 0.43e−t/1.956
Both rises start at zero, θ1 with the slope P/C1 = 10 K/s and θ2 with zero slope, since no heat has yet reached the heat sink. The fast mode, which barely touches θ2, is the transistor heating relative to its heat sink: within 10 s, θ1 − θ2 reaches 19.5 K of an eventual 20 K. The slow mode is the assembly warming as a whole, with θ1 at 30.0 K after 60 s, 46.5 K after 300 s, and 49.6 K after 600 s.
The stiffness ratio, 0.5113/0.007244, is about 71. Forward Euler is stable only for h < 2 × 1.956 s = 3.91 s; at h = 3.5 s its early temperatures swing from step to step with errors up to 18 K, and at h = 4 s it diverges. Over the first 600 s, backward Euler at h = 30 s takes 20 steps, never oscillates, and ends within 0.21 K. The trapezoidal rule at h = 10 s ends within 0.001 K, but its first steps put θ1 − θ2 at 28.1, 15.9, 21.3, and 19.0 K against true values of 19.5 to 19.7 K: trap ringing of the 2 s mode. A third node for the silicon die, with an assumed 0.02 J/K and 0.3 K/W, would add a 6 ms mode and push the ratio above 20,000.
DC Motor Speed After a Voltage Step
Take the permanent-magnet DC motor whose model Control System Modeling and Block Diagrams derives: armature resistance R = 1 Ω and inductance L = 1 mH, torque and back-EMF constants Kt = Ke = 0.05 in SI units, inertia J = 1.25 × 10−4 kg·m2, and negligible friction and load torque. At rest, it is connected to 24 V at t = 0. Find the speed ω(t) and the current i(t).
- Combine the equations. The armature gives L di/dt = v − Ri − Keω, and the rotor gives J dω/dt = Kti. Substituting i = (J/Kt) dω/dt gives d2ω/dt2 + (R/L) dω/dt + [KtKe/(LJ)]ω = Ktv/(LJ), or d2ω/dt2 + 1000 dω/dt + 20,000ω = 9.6 × 106.
- Find the roots. λ2 + 1000λ + 20,000 = 0 gives λ = −500 ± √230,000, or λ1 = −20.42 s−1 and λ2 = −979.58 s−1, distinct real roots with time constants of 49.0 ms and 1.02 ms.
- Find the particular solution. The constant ωp = 9.6 × 106/20,000 = 480 rad/s is the speed at which the back EMF equals the applied voltage.
- Fit the constants. The motor starts with ω(0) = 0 and no current, so dω/dt(0) = Kti(0)/J = 0. Then K1 + K2 = −480 and λ1K1 + λ2K2 = 0, so K1 = −490.22 and K2 = 10.22.
- State the results. For t ≥ 0, ω(t) = 480 − 490.22e−20.42t + 10.22e−979.58t rad/s, and i(t) = (J/Kt) dω/dt = 25.02(e−20.42t − e−979.58t) A.
The current rises at v/L = 24,000 A/s, peaks at 22.56 A after 4.04 ms, just short of the 24 A stall current, and decays as the back EMF builds. The speed reaches 63.2 percent of 480 rad/s after 50.0 ms and stays within 2 percent of it after 193 ms. With roots a factor of 48 apart, the model is mildly stiff: forward Euler needs steps under 2.04 ms, although the speed changes over tens of milliseconds.
Summary
Circuits, heat sinks, and motors obey ordinary differential equations because their stored quantities change at rates the system sets. A continuous right-hand side that is Lipschitz in the unknown guarantees a unique local solution, and a linear equation with continuous coefficients and a nonvanishing leading coefficient has one on its whole interval. Linear first-order equations yield to the integrating factor; constant-coefficient equations take homogeneous solutions from the characteristic roots and particular solutions from undetermined coefficients, with the constants fitted to the complete solution. An input that matches or nearly matches a natural mode resonates. Matrices extend the methods to systems, and the Jacobian extends them locally to nonlinear equations. When closed forms run out, order sets a numerical method's accuracy and stability sets its longest usable step, which is why stiff circuit equations are integrated implicitly, with the trapezoidal rule or Gear's formulas.