Lesson 11 of 15

RLC Transient (RK4)

The RLC Circuit

Adding an inductor to the RC circuit creates an RLC circuit — the complete second-order system. It can exhibit oscillation.

Vs ---[R]---[L]---+--- GND
                  |
                 [C]
                  |
                 GND

The Governing ODE

By KVL: Vs = V_R + V_L + V_C = R·I + L·dI/dt + (1/C)·∫I dt

Differentiating and substituting I = C·dV_C/dt:

L·C·V_C'' + R·C·V_C' + V_C = Vs

This is a second-order linear ODE. We solve it numerically using RK4.

Damping Ratio

The behavior depends on α = R/(2L) and ω₀ = 1/√(LC):

ConditionBehavior
α > ω₀Overdamped: slow exponential approach
α = ω₀Critically damped: fastest approach, no oscillation
α < ω₀Underdamped: oscillates around Vs

Solving with RK4

We reduce to two first-order equations. Let x₁ = V_C and x₂ = dV_C/dt:

dx₁/dt = x₂
dx₂/dt = (Vs − x₁ − R·C·x₂) / (L·C)

Then apply the RK4 integrator with step h over n steps.

Your Task

Implement double rlc_voltage(double vs, double r, double l, double c, double t, double dt) that integrates the RLC circuit from t=0 to t using RK4 with step dt, starting from V_C(0) = 0 and dV_C/dt(0) = 0.

Use #include <math.h> for any math functions needed.

TCC compiler loading...
Loading...
Click "Run" to execute your code.