A Byte of PhysicsLogo

Transient analysis

A circuit is in a transient when its voltages and currents are changing from one state to another. A resistor responds algebraically to its present voltage. A capacitor or an inductor stores energy, so its present behavior also depends on earlier conditions. That memory turns a static circuit equation into a differential equation.

Transient analysis connects three kinds of information: the state just before a change, the circuit configuration after the change, and the laws that govern the state through time. A source can switch ideally in no time, but stored capacitor voltage and inductor current cannot usually jump without an impulse of current or voltage.

Capacitors and inductors store state

For a capacitor, charge and voltage are related by

\[Q=CV\]

Differentiating and using \(I=dQ/dt\) gives the capacitor current law for constant capacitance:

\[I_C=C\frac{dV_C}{dt}\]

The stored electric-field energy is

\[U_C=\frac{1}{2}CV_C^2\]

An ideal inductor instead obeys

\[V_L=L\frac{dI_L}{dt}\]

and stores magnetic-field energy

\[U_L=\frac{1}{2}LI_L^2\]

The capacitor voltage \(V_C\) and the inductor current \(I_L\) are natural state variables. Knowing only the source at the present instant is not enough; their initial values are also required.

Continuity at a switching instant

Integrate the capacitor law over a very short interval around a switch. A finite current can transfer only a vanishing amount of charge as the interval shrinks, so ideal capacitor voltage is continuous:

\[V_C(0^+)=V_C(0^-)\]

Likewise, integrating the inductor law shows that a finite voltage cannot change inductor current instantaneously:

\[I_L(0^+)=I_L(0^-)\]

The qualifications matter. An ideal current impulse can change capacitor voltage, and an ideal voltage impulse can change inductor current. Real switching also includes parasitic elements that keep actual voltages and currents finite. For ordinary first- order switching problems, continuity is the correct starting rule.

Series RC charging equation

Consider a voltage source \(V_s\), resistor \(R\), and capacitor \(C\) in series. With current directed into the capacitor's positive-voltage terminal, Kirchhoff's voltage law gives

\[V_s-V_R-V_C=0\]

Using \(V_R=IR\) and \(I=C\,dV_C/dt\) gives

\[RC\frac{dV_C}{dt}+V_C=V_s\]

For a constant source and an arbitrary initial capacitor voltage, the solution is

\[V_C(t)=V_s+\left[V_C(0)-V_s\right]e^{-t/(RC)}\]

This form is more useful than memorizing only the uncharged case. It says that the difference between the present state and the final state decays exponentially. At \(t=0\), the exponential is one and the initial condition is recovered. At long times, the exponential tends to zero and the capacitor approaches the source voltage.

The current follows from the derivative:

\[I(t)=\frac{V_s-V_C(0)}{R}e^{-t/(RC)}\]

The sign automatically handles charging or discharging. If the capacitor initially has a voltage larger than the source, the current is negative relative to the charging direction.

Time constant and physical meaning

The RC time constant is

\[\tau=RC\]

Its units are seconds because an ohm times a farad equals a second. After one time constant, the difference from the final value is multiplied by \(e^{-1}\), approximately \(0.368\). Equivalently, a charging capacitor has completed about 63.2 percent of its total voltage change. After five time constants, less than one percent of the original difference remains.

A larger resistance reduces current and slows charge transfer. A larger capacitance requires more charge for the same voltage change. Either change increases the time constant without altering the final voltage set by a constant ideal source.

RC discharge as the same solution

Disconnect the source and let an initially charged capacitor discharge through a resistor. Setting the final source value to zero gives

\[V_C(t)=V_C(0)e^{-t/(RC)},\qquad I(t)=-\frac{V_C(0)}{R}e^{-t/(RC)}\]

The negative current sign is relative to a direction chosen into the capacitor's positive terminal. During discharge, current leaves that terminal. The capacitor's initial energy becomes thermal energy in the resistor:

\[\int_0^\infty I^2R\,dt =\frac{1}{2}CV_C(0)^2\]

This equality is an especially useful independent check because it tests the current, time dependence, resistance, and stored-energy formula together.

The analogous RL response

For a series resistor and inductor driven by a constant voltage source, KVL gives

\[L\frac{dI}{dt}+RI=V_s\]

With arbitrary initial current, the solution is

\[I(t)=\frac{V_s}{R} +\left[I(0)-\frac{V_s}{R}\right]e^{-tR/L}\]

The RL time constant is

\[\tau=\frac{L}{R}\]

The mathematical pattern matches the RC circuit: state equals final value plus initial error times a decaying exponential. The physical state differs—capacitor voltage versus inductor current—and so do the continuity conditions.

A general first-order recipe

For either simple circuit, avoid deciding at the outset whether the state is “charging” or “discharging.” Determine the initial value, final steady value, and time constant. Then use

\[x(t)=x(\infty)+\left[x(0^+)-x(\infty)\right]e^{-t/\tau}\]
import numpy as np

R, C, initial, final = 1000.0, 1e-6, 0.0, 5.0
tau = R * C
times = np.linspace(0, 5 * tau, 101)
voltage = final + (initial - final) * np.exp(-times / tau)
print(f"Voltage after one time constant: {voltage[20]:.3f} V")

When finding resistance seen by an independent-source network, set ideal independent voltage sources to zero by replacing them with shorts and ideal independent current sources to zero by replacing them with opens. Dependent sources must remain active; a test source may be needed to find the equivalent resistance.

Worked RC example

Take \(R=2\ \mathrm{k\Omega}\) and \(C=5\ \mathrm{\mu F}\). The time constant is

\[\tau=RC=(2000\ \Omega)(5\times10^{-6}\ \mathrm F) =0.010\ \mathrm s\]

Suppose the capacitor starts at \(2\ \mathrm V\) and is connected to a constant \(10\ \mathrm V\). After one time constant,

\[V_C(\tau)=10\ \mathrm V +(2\ \mathrm V-10\ \mathrm V)e^{-1} \approx7.06\ \mathrm V\]

The value lies between the initial and final voltages and has completed 63.2 percent of the eight-volt change. The initial current is \((10\ \mathrm V-2\ \mathrm V)/(2\ \mathrm{k\Omega})=4\ \mathrm{mA}\) and then decays exponentially.

Numerical updates and convergence

For a source that varies with time, a closed-form solution may be inconvenient. The RC differential equation can be written

\[\frac{dV_C}{dt}=\frac{V_s(t)-V_C}{RC}\]

An explicit Euler update is

\[V_C^{n+1}=V_C^n +\Delta t\frac{V_s^n-V_C^n}{RC}\]
for steps in [50, 100, 200]:
    v, dt = initial, 5 * tau / steps
    for _ in range(steps):
        v += dt * (final - v) / (R * C)
    print(steps, "final voltage error (V):", v - voltage[-1])

The update is simple, not automatically accurate. If the step is too large relative to the fastest time constant, it can overshoot, oscillate, or become unstable. Compare step sizes at identical output times and check convergence toward the analytic RC result. More advanced implicit methods are often preferred for stiff networks with widely separated time constants.

Verification and limits

At the switching instant, reproduce the stored initial state exactly. At long times, recover the DC circuit: a capacitor behaves as an open branch and an inductor as a short in the ideal steady-state model. Check units of each time constant and predict whether the state rises or falls before calculating. For numerical work, halve the time step and compare at shared timestamps rather than comparing arrays with different time grids.

Ideal models omit capacitor leakage and equivalent series resistance, inductor winding resistance and saturation, switch resistance and arcing, source impedance, temperature dependence, and electromagnetic propagation. At high frequency or over long conductors, the lumped assumption fails. These omissions do not invalidate first-order transient analysis; they define when a more detailed model is needed.

A worked Python notebook

Charge an initially uncharged one microfarad capacitor through one kilohm from a five volt source. The question for this calculation is precise: how does capacitor voltage change when we change time after switching, while keeping the other choices fixed? The earlier sections explain the physical relationship. Here we turn one part of that relationship into a calculation that you can run, inspect, and change in Google Colab.

The source and components are ideal and switching establishes a constant source voltage. Keep that sentence beside the results. A formula can return a number outside its useful range, and a plotting library will usually draw that number without asking whether the physical assumptions still hold. The selected interval is from 0 to 0.005 s. It gives us a specific domain to discuss instead of leaving the graph's range to a software default.

Use the notebook link above the lesson, run the setup cell, and then run the cells in order. The code below is also included there. NumPy handles the arrays of numerical values, SymPy keeps the equation symbolic, and Matplotlib draws the results. If these libraries or notebook cells are unfamiliar, start with Your first physics notebook.

State the relationship before choosing a graph

In this small example, q stands for time after switching, expressed in s. The output is capacitor voltage, expressed in V. The equation below uses the numerical values in those units. Any fixed coefficients therefore carry the units needed to make the relation consistent. A value supplied in another unit must be converted before it enters this expression.

\[f(q) = 5 - 5 e^{- 1000.0 q}\]

This is a function of one changing input. It is not a statement that the physical system has only one variable. We deliberately hold the other inputs fixed so that one cause of variation is visible. Changing several inputs at once would make it harder to tell which change produced the output difference. Write down the held-fixed choices before trying a different experiment.

At 0.001 s, the expression gives 3.1606 V. This is our reference calculation. It is a prediction of the stated example, not a new measurement. Its displayed digits help us compare implementations. They should not be read as a claim that physical inputs are known to six significant figures.

import numpy as np
import sympy as sp
import matplotlib.pyplot as plt

q = sp.Symbol("q", real=True)
expression = sp.sympify("5*(1-exp(-q/0.001))", locals={"q": q})
reference_input = 0.001
reference_output = float(expression.subs(q, reference_input))
print("Input:", reference_input, "s")
print("Predicted capacitor voltage:", reference_output, "V")

sp.Symbol declares a mathematical symbol. It does not assign a numerical measurement to that symbol. subs then replaces the symbol with our chosen input, and float converts the resulting symbolic number into a standard Python numerical value. Keeping these steps separate lets us inspect the equation before numerical substitution. It also prevents a later plot from becoming the only surviving record of the model.

Compare a few cases you can explain

Before drawing hundreds of points, calculate three. The lower endpoint gives 0 V. The midpoint, at 0.0025 s, gives 4.58958 V. The upper endpoint gives 4.96631 V. Read these together with the assumptions: they describe different choices of time after switching within the same example, with the other inputs held fixed.

These three values are a useful first check, but they do not establish the shape between them. Two endpoints can be equal even when the curve bends or oscillates in between. Likewise, a large change between endpoints does not tell us whether the relationship is linear. We need the equation and intermediate samples to answer those questions.

evaluate = sp.lambdify(q, expression, modules="numpy")
inputs = np.array([0.0, 0.0025, 0.005])
outputs = np.asarray(evaluate(inputs), dtype=float)
outputs = np.broadcast_to(outputs, inputs.shape)
for input_value, output_value in zip(inputs, outputs):
    print(f"{input_value:.6g} s -> {output_value:.6g} V")
assert np.all(np.isfinite(outputs))

lambdify turns the symbolic expression into a numerical function. We explicitly select NumPy as its numerical backend so it can accept an array. The same expression now has two useful forms: one for algebra and one for calculating many cases. The assertion checks that the chosen inputs produce finite outputs. It would catch an infinity or an undefined numerical result, but a finite value can still be physically inappropriate.

Make a graph that answers the question

The horizontal axis shows time after switching; the vertical axis shows capacitor voltage. Every plotted point is a prediction of the same expression. We mark the reference case separately so that a reader can connect the earlier printed value to its place on the curve. The axis labels include units because a shape without a scale cannot tell us the size of a physical effect.

input_grid = np.linspace(0.0, 0.005, 301)
output_grid = np.asarray(evaluate(input_grid), dtype=float)
output_grid = np.broadcast_to(output_grid, input_grid.shape)
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot(input_grid, output_grid, label="Stated model")
ax.scatter([reference_input], [reference_output], label="Reference case", zorder=3)
ax.set_xlabel("Time after switching (s)")
ax.set_ylabel("Capacitor voltage (V)")
ax.legend()
ax.grid(alpha=0.25)
fig.tight_layout()
plt.show()

Look for a sign change, a turning point, or a region where the curve becomes steep. Connect each feature to the expression rather than to the colour of the line. If the curve has a minimum or maximum, changing the input in opposite directions may have similar effects on the output near that point. If it is nearly straight over a short interval, a local linear approximation may be useful even when the complete expression is nonlinear.

Increasing the number of samples makes the line smoother and may reveal features that a coarse grid missed. It does not improve the physical inputs or enlarge the model's validity range. For quantities that can take only discrete values, use the line as a guide to the relationship and interpret only the allowed input values. A plotting function does not enforce such restrictions for you.

Measure the local sensitivity

A derivative asks a more specific question than the whole graph: how quickly does capacitor voltage change near the reference input? Its units are the output unit divided by the input unit. For this calculation, the derivative at 0.001 s is 1839.4 in those ratio units. Locally, the output increases as the input increases. This statement is local; the sign or size of the slope can be different elsewhere on the curve.

\[f'(q) = 5000.0 e^{- 1000.0 q}\]

For a small input change, multiply the derivative by that change to estimate the output change. Then compare that estimate with a fresh evaluation of the full expression. The distinction between these two calculations matters: the derivative gives a tangent approximation, while substitution evaluates the chosen expression at the new point.

slope_expression = sp.diff(expression, q)
slope_at_reference = float(slope_expression.subs(q, reference_input))
changed_input = 0.001025
linear_prediction = reference_output + slope_at_reference * (
    changed_input - reference_input
)
full_prediction = float(evaluate(changed_input))
print("Symbolic derivative:", slope_expression)
print("Tangent prediction:", linear_prediction, "V")
print("Full expression:", full_prediction, "V")
print("Approximation difference:", full_prediction - linear_prediction, "V")

Here the changed input is 0.001025 s. The tangent estimate is 3.20659 V, while the full expression gives 3.20602 V. If the two values are close, it means the chosen input change is small enough for this local approximation at this point. It does not mean the entire model is linear. If the slope is zero, a quadratic or higher-order term may supply the leading change instead.

This is also the beginning of uncertainty propagation. If the input has a small stated standard uncertainty, the magnitude of the slope times that uncertainty estimates one contribution to output uncertainty. Do not automatically use the same rule for a wide interval, a discontinuity, a turning point with zero first derivative, or several correlated uncertain inputs. Those situations need more of the model than one slope.

Check the derivative with numerical differences

We can estimate the same slope from values on either side of the reference point. Subtract the lower output from the upper output and divide by twice the input step. Parentheses are essential: the entire output difference must be divided by the entire input interval. Without them, Python can execute a different mathematical expression while still producing a plausible number.

The calculation below uses three decreasing step sizes. Each estimate is compared with the symbolic derivative, so the reference is independent of the numerical difference formula. Near an endpoint, it is acceptable here to evaluate a small extension only because the displayed mathematical expression is smooth there; such a check does not assert that extrapolated values describe additional physical cases.

input_span = 0.005
for fraction in [1e-2, 1e-3, 1e-4]:
    step = input_span * fraction
    upper = float(evaluate(reference_input + step))
    lower = float(evaluate(reference_input - step))
    numerical_slope = (upper - lower) / (2 * step)
    difference = numerical_slope - slope_at_reference
    print(f"step={step:.6g}: slope={numerical_slope:.6g}, difference={difference:.6g}")

For a smooth function, reducing the step often reduces the approximation error at first. Very small steps can eventually make subtraction of nearly equal floating-point values less reliable. Therefore “smaller” is not an unlimited guarantee of “better.” Compare the observed behaviour over a useful range of steps instead of choosing the smallest number the computer can represent.

An absolute slope difference is useful when the expected slope is near zero. A relative difference would divide by a very small reference and could look enormous even when the absolute discrepancy is tiny. Away from zero, a relative difference can help compare quantities with very different scales. The tolerance should reflect the question and the numerical method, rather than a universal decimal threshold copied into every test.

Change the example and preserve the reasoning

Make one copy of the reference calculation before editing it. Choose a second value of time after switching inside the stated interval, predict whether capacitor voltage will rise or fall, and then evaluate the expression. Place the prediction and the result in a text cell. If they disagree, identify whether the mistake was in the sign, the unit conversion, the algebra, or the assumption about how the curve behaves.

Next choose a shorter plotting interval around the reference point. Compare the local curve with its tangent approximation. Then widen the interval again. The difference shows why a useful local estimate need not describe the whole range. Keep the axis labels and numerical scale visible when comparing the plots; automatic axis limits can make two different effects appear equally large.

Finally, return to the physical limit stated at the start: The source and components are ideal and switching establishes a constant source voltage. Describe one change to the setup that would violate that limit. State what new input, equation, or observation would be needed before trusting an answer in the changed situation. This last step connects the Python experiment to the physics instead of treating successful execution as the only criterion for a useful result.

Before saving, restart the runtime and run all cells in order. A result that depends on an earlier, now-deleted input cell is not reproducible from the saved notebook. Keep unrounded values for later calculations, round only the reported output, and label any new data as measured, assumed, or generated. The graph and printed values should remain traceable to the same expression and the same choices of inputs.

Recover the output change by integrating the slope

There is another way to check that the expression and its derivative describe the same relationship. Add up the small output changes predicted by the slope across the chosen input interval. In the continuous limit, this integral equals the output at the upper endpoint minus the output at the lower endpoint. The result has units of V: the input unit in the integration cancels the input unit in the denominator of the slope.

This statement is about the mathematics of this particular relationship. It does not assign a new physical meaning to an arbitrary area under a graph. For example, an area under force versus distance represents work, while an area under a different pair of quantities may represent something else or have no standard name. Always carry the axis units through the calculation before naming an integral.

slope_function = sp.lambdify(q, slope_expression, modules="numpy")
endpoint_change = float(evaluate(0.005) - evaluate(0.0))
for points in [101, 201, 401]:
    grid = np.linspace(0.0, 0.005, points)
    slopes = np.asarray(slope_function(grid), dtype=float)
    slopes = np.broadcast_to(slopes, grid.shape)
    integrated_change = np.trapezoid(slopes, grid)
    print(
        points,
        "integrated change:",
        integrated_change,
        "endpoint change:",
        endpoint_change,
    )

The trapezoidal rule joins neighbouring slope samples with straight segments and adds their signed areas. A negative contribution remains negative; replacing every slope by its magnitude would calculate a different quantity. Increasing the sample count provides a practical refinement check. If the values do not settle toward the endpoint difference, first inspect the interval, singularities, and array ordering.

Do not conclude that two agreeing calculations prove the model is physically complete. Both use the same selected relationship, so an omitted effect would be omitted from both. Their agreement is evidence that the numerical tools implement that relationship consistently. Comparing with an independent experiment or a more appropriate physical model is a separate test.

Keep this comparison in the notebook when you change the expression. It is particularly useful after adding a coefficient, changing a sign convention, or converting an input unit. A code cell that produces a smooth graph can conceal these mistakes; a second calculation of the same output change gives you another place to notice them.

Sources


Share to: