ENع
→First-order ODEs
الدرس 28 · Maths for circuits and signals

First-order differential equations

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

15 دقيقة10 خطوات5 أسئلةIntermediate
عن هذا الدرس

A differential equation is a rule that links a quantity to its own rate of change. Follow one capacitor charging from 10 V through 1 kΩ: turn the circuit into RC·dv/dt + v = Vs, walk it forward with Euler's method in Python, solve it exactly by separating the variables, and meet the time constant τ = RC that the Electric circuits course uses everywhere.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 28 · تفاعلي
01 / 10

An equation about change

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.

>>> R, C, Vs = 1e3, 1e-4, 10    # 1 kΩ, 100 µF, 10 V
>>> R * C                       # seconds
0.1
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. An equation about change

    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.

    >>> R, C, Vs = 1e3, 1e-4, 10    # 1 kΩ, 100 µF, 10 V
    >>> R * C                       # seconds
    0.1
  2. From circuit to equation

    Around the loop the source voltage is shared: Vs = iR + v. A capacitor's current is i = C·dv/dt. Substitute and you get RC·dv/dt + v = Vs. It is first order because only the first derivative of v appears.

    >>> R, C, Vs = 1e3, 1e-4, 10
    >>> v, dvdt = 0.0, 100.0          # the instant the switch closes
    >>> i = C * dvdt                  # capacitor law, in amps
    >>> i
    0.01
    >>> i * R + v                     # Kirchhoff: equals Vs
    10.0
  3. The slope rule

    Rearrange to dv/dt = (Vs − v)/RC. Here RC = 1 kΩ × 100 µF = 0.1 s, so at v = 0 the slope is 10 ÷ 0.1 = 100 V/s. The emptier the capacitor, the steeper the rise; a full one barely moves.

    >>> Vs, tau = 10, 0.1
    >>> def slope(v):
    ...     return (Vs - v) / tau
    ...
    >>> slope(0), slope(5), slope(10)
    (100.0, 50.0, 0.0)
  4. Euler's method: small steps

    Walk the rule forward in steps of dt = 0.05 s: new v = v + dt × slope. First 0 + 0.05 × 100 = 5 V. The slope drops to 50 V/s, so next v = 7.5 V. A loop repeats it.

    >>> Vs, tau, dt = 10, 0.1, 0.05
    >>> v = 0.0
    >>> for n in range(4):
    ...     v += dt * (Vs - v) / tau
    ...     print(v)
    ...
    5.0
    7.5
    8.75
    9.375
  5. Separate the variables

    For the exact answer, gather every v on one side: dv/(Vs − v) = dt/RC. Integrate both sides: −ln(Vs − v) = t/RC + K. At t = 0 the voltage is 0, which fixes the constant: K = −ln Vs.

    >>> import math
    >>> Vs, tau = 10, 0.1
    >>> v = 6.0                       # any voltage on the way up
    >>> t = tau * math.log(Vs / (Vs - v))   # solve -ln(Vs-v) = t/tau - ln(Vs) for t
    >>> round(t, 4)
    0.0916
  6. The exact solution

    Solve for v: v(t) = Vs(1 − e^(−t/RC)). Check it: at t = 0 it gives 0, and its slope (Vs/RC)·e^(−t/RC) equals (Vs − v)/RC at every moment. So it obeys both the equation and the starting value.

    >>> import math
    >>> Vs, tau = 10, 0.1
    >>> v = lambda t: Vs * (1 - math.exp(-t / tau))
    >>> v(0)
    0.0
    >>> h = 1e-7                       # numeric slope at t = 0.2 s
    >>> round((v(0.2 + h) - v(0.2)) / h, 2), round((Vs - v(0.2)) / tau, 2)
    (13.53, 13.53)
  7. Time constant τ = RC

    RC sets the speed, so it gets a name: the time constant τ (tau), here 0.1 s. At t = τ, v = 10(1 − e^−1) = 6.32 V, 63% of the way. Each further τ closes 63% of the gap that is left.

    >>> import math
    >>> round(10 * (1 - math.exp(-1)), 2)
    6.32
    >>> round(1 - math.exp(-1), 3)        # fraction after one tau
    0.632
  8. Full after about 5τ

    At t = 5τ = 0.5 s, v = 9.93 V, more than 99% of 10 V. The curve never quite reaches 10 V, but after five time constants engineers treat the capacitor as full. The current i = C·dv/dt has died away too.

    >>> import math
    >>> round(10 * (1 - math.exp(-5)), 2)
    9.93
    >>> round(0.01 * math.exp(-5) * 1000, 3)   # current in mA, from 10 mA
    0.067
  9. Euler versus exact

    At t = 0.1 s Euler says 7.5 V, but the exact value is 6.32 V. Each step uses the slope at its start, which is too steep by the end. Change line 2 to dt = 0.001 and Euler gives 6.34 V.

    >>> def euler(dt, steps, Vs=10, tau=0.1):
    ...     v = 0.0
    ...     for n in range(steps):
    ...         v += dt * (Vs - v) / tau
    ...     return v
    ...
    >>> euler(0.05, 2)
    7.5
    >>> round(euler(0.001, 100), 4)
    6.3397
  10. One pattern, many places

    Every equation of the form dy/dt = (y∞ − y)/τ has the answer y = y∞ + (y0 − y∞)e^(−t/τ). The same curve describes a capacitor discharging, the current in an RL circuit and a cup of coffee cooling.

    >>> import math
    >>> def first_order(y0, y_inf, tau, t):
    ...     return y_inf + (y0 - y_inf) * math.exp(-t / tau)
    ...
    >>> round(first_order(0, 10, 0.1, 0.1), 2)     # charging
    6.32
    >>> round(first_order(10, 0, 0.1, 0.1), 2)     # discharging
    3.68

اختبار يتاح بعد الخطوة الأخيرة.