SVsRC0.00 V10 V1 kΩ100 µF1R, C, Vs = 1e3, 1e-4, 102tau, dt = R*C, 0.053v = 0.04for n in range(10):5 slope = (Vs-v)/tau6 v += dt*slopev0slope–
00.10.20.30.40.50246810t (s)v (V)v(t) across the capacitorexact 10(1 − e^−t/τ)Euler, dt = 0.05 s1.18 V
RC circuit: source, switch, resistor, capacitor and a voltmeter across itPython card and variables: Euler's loop, step by stepPlot: the exact curve v(t) and Euler's pointsDashed tangent: the slope (Vs − v)/RC at a pointAn RC circuit charging: 10 V through 1 kΩ into 100 µF. Kirchhoff's voltage law and the capacitor law i = C·dv/dt give RC·dv/dt + v = Vs, so the slope of v(t) is (Vs − v)/RC. Euler's method follows that slope in steps of 0.05 s (orange tangents, violet dots); the exact solution v = 10(1 − e^(−t/0.1)) is the green curve, reaching 6.32 V at τ = 0.1 s and 9.93 V at 5τ. Euler's method has a global error roughly proportional to dt: halve the step and the error roughly halves. Real simulators such as SPICE use better methods (trapezoidal, Gear), but the idea of stepping a slope rule forward is the same.

The equation

  1. Close the switch and current flows into the capacitor, so its voltage v starts to rise. A differential equation is a rule that links a quantity to its own rate of change, dv/dt: how many volts per second v is rising right now.

Step by step

Exact solution

In practice

Try it in the Python prompt

;; step 1/10 · An equation about change
>>> R, C, Vs = 1e3, 1e-4, 10    # 1 kΩ, 100 µF, 10 V
>>> R * C                       # seconds
0.1

An equation like dv/dt = (Vs − v)/RC has a whole family of solutions; the starting value v(0) = 0 picks out one. Together they are called an initial value problem. Here ln is the natural logarithm (math.log in Python) and e ≈ 2.71828 is its base, so e^(−1) ≈ 0.368 and 1 − e^(−1) ≈ 0.632.