Application: Resistor Networks
An electric circuit made of batteries and resistors obeys three simple rules, and each one is a linear equation. Writing them all down gives a linear system whose solution is every current and voltage in the circuit. This is how circuit simulators work, and it is a great example of a system you could not solve by staring at it.
The three laws
| Law | Statement | Equation |
|---|---|---|
| Ohm's law | the voltage across a resistor is proportional to the current through it | |
| Kirchhoff's current law (KCL) | the currents flowing into a junction equal those flowing out | |
| Kirchhoff's voltage law (KVL) | around any closed loop, voltage rises equal voltage drops |
Units: volts (V), amperes (A), ohms ().
Example 1: currents in a simple circuit
A 12 V battery drives current through a resistor; then the current splits into through and through , which rejoin and return to the battery.
I₁ 2 Ω KCL (junction): I₁ − I₂ − I₃ = 0
┌────→────/\/\/\────┬────────┐ KVL (outer loop via 3 Ω): 2I₁ + 3I₂ = 12
│ │ │ KVL (loop 3 Ω vs 6 Ω): 3I₂ − 6I₃ = 0
+ │ 12 V 3 Ω ▯ I₂ 6 Ω ▯ I₃
− │ │ │
└───────────────────┴────────┘from sympy import Matrix
A = Matrix([[1, -1, -1],
[2, 3, 0],
[0, 3, -6]])
b = Matrix([0, 12, 0])
I = A.solve(b)
print("I1, I2, I3 =", list(I), "amperes")
print("power from the battery:", 12 * I[0], "watts")I1, I2, I3 = [3, 2, 1] amperes
power from the battery: 36 watts
Check with the shortcut you may know: and in parallel give , plus in series is , so . ✓ The linear system needs no shortcuts, and that matters for circuits that are neither series nor parallel.
Example 2: a bridge circuit (node voltages)
The bridge below cannot be reduced with series and parallel rules. Instead we use nodal analysis: unknowns are the voltages at the nodes, and KCL at each node, with Ohm's law , gives one equation per unknown node.
Node A is held at 10 V by a battery, the ground node G is at 0 V. Resistors: A–B , A–C , B–C (the bridge), B–G , C–G .
from sympy import Matrix, Rational
half = Rational(1, 2)
G = Matrix([[1 + 1 + half, -1],
[-1, half + 1 + 1]])
rhs = Matrix([10, 10 * half])
VB, VC = G.solve(rhs)
print("V_B =", VB, " V_C =", VC)
print("bridge current B->C:", VB - VC, "A")
I_total = (10 - VB) / 1 + (10 - VC) / 2
print("current from battery:", I_total, "A")
print("equivalent resistance:", 10 / I_total, "ohm")V_B = 40/7 V_C = 30/7
bridge current B->C: 10/7 A
current from battery: 50/7 A
equivalent resistance: 7/5 ohm
The matrix is the conductance matrix: on the diagonal, the sum of conductances at each node; off the diagonal, minus the conductance between two nodes. It is symmetric, a weighted version of the graph Laplacian of the circuit.
Example 3: a long ladder in NumPy
Real circuits have thousands of nodes, so simulators build the conductance matrix automatically and solve it numerically. Here is a ladder of identical sections (a series resistor followed by a resistor to ground):
import numpy as np
def ladder_resistance(n, R=1.0):
# unknown voltages at nodes 1..n; node 0 is held at 1 V, ground at 0 V
G = np.zeros((n, n)); rhs = np.zeros(n)
g = 1.0 / R
for k in range(1, n + 1):
i = k - 1
G[i, i] += g # series resistor to node k-1
if k == 1:
rhs[i] += g * 1.0 # node 0 is the 1 V source
else:
G[i, i - 1] -= g; G[i - 1, i] -= g; G[i - 1, i - 1] += g
G[i, i] += g # shunt resistor to ground
V = np.linalg.solve(G, rhs)
current_in = (1.0 - V[0]) * g
return 1.0 / current_in
for n in [1, 2, 3, 5, 10, 30]:
print(f"n = {n:2d}: R_eq = {ladder_resistance(n):.10f}")
print("golden ratio:", (1 + 5 ** 0.5) / 2)n = 1: R_eq = 2.0000000000
n = 2: R_eq = 1.6666666667
n = 3: R_eq = 1.6250000000
n = 5: R_eq = 1.6181818182
n = 10: R_eq = 1.6180339985
n = 30: R_eq = 1.6180339887
golden ratio: 1.618033988749895
As the ladder grows, its resistance approaches the golden ratio , a classic result that the linear system confirms numerically. The exact values are ratios of Fibonacci numbers.
In software
- SPICE and every circuit simulator use modified nodal analysis: one row per node, assembled automatically from a netlist, solved with sparse LU factorization.
- The same Laplacian matrix appears in graph algorithms: spectral clustering, random walks and "effective resistance" between nodes, which measures how well connected two vertices of a network are.
- Physics engines and mesh smoothing in graphics solve Laplacian systems of exactly this form, with springs or mesh edges instead of resistors.
Exercises
Exercise 1: Series and parallel check
A 9 V battery is connected to a resistor in series with a parallel pair of and . Find all currents.
Answer
3 A from the battery, 1.5 A through each resistor.
Solution
Exercise 2: Two batteries
Two batteries share a resistor: battery 1 (10 V) with a resistor and battery 2 (4 V) with a resistor, both feeding the junction above the resistor. With the node-voltage method, find the junction voltage .
Answer
.
Solution
Exercise 3: Change the bridge (code)
In Example 2, change the bridge resistor B–C from to . What is the new equivalent resistance?
Answer
(, ).
Solution
The B–C conductance becomes , which changes both diagonal entries and the off-diagonal entries.
from sympy import Matrix, Rational
g_bc = Rational(1, 3)
G = Matrix([[1 + g_bc + Rational(1, 2), -g_bc],
[-g_bc, Rational(1, 2) + g_bc + 1]])
VB, VC = G.solve(Matrix([10, 5]))
I = (10 - VB) + (10 - VC) / 2
print(VB, VC, 10 / I)80/13 50/13 13/9
Exercise 4: Balanced bridge
For which value of the C–G resistor (other resistors as in Example 2: A–B , A–C , B–G ) does no current flow through the bridge?
Answer
.
Solution
No bridge current means , so the two sides act as separate voltage dividers with equal ratios:
Test yourself
Kirchhoff's current law at a junction gives which kind of equation?
- A quadratic equation
- A linear equation in the currents
- An inequality
- A differential equation
In nodal analysis, what are the unknowns?
- The resistances
- The battery voltages
- The loop areas
- The node voltages
What is on the diagonal of a circuit's conductance matrix?
- Zeros
- The node voltages
- The sum of conductances connected to each node
- The resistances themselves