Sub topic 13
Checking a solution by balancing node currents
This chapter assumes you can write nodal equations with KCL and Ohm's law and solve a small linear system. It also assumes you can read a schematic with current sources and resistors.
Why check at all
A solved nodal system can still be wrong. A sign slip when building the equations, a swapped resistor value, or a typo in a source current all produce voltages that look reasonable. The solver does not complain, because it solved the system you gave it.
KCL gives you a check that does not depend on how you built the equations. Take the voltages you found. Compute every branch current directly from the circuit using Ohm's law. Then add up the currents at each node. If any node does not balance, something upstream is wrong.
The check procedure
Two rules make the check meaningful:
- Compute branch currents from the schematic, not from your matrix. If you reuse the matrix rows, you only confirm that the solver worked.
- Check every node, including nodes you did not write an equation for. The ground node is a useful extra test. The currents entering it must also sum to zero, and the equations for the other nodes do not enforce that directly.
A worked check
Take the circuit from the earlier example. A 10 mA source feeds node 1. R1 = 1 kΩ connects node 1 to ground. R2 = 2 kΩ connects node 1 to node 2. R3 = 2 kΩ connects node 2 to ground. The nodal solution is v1 = 8 V and v2 = 4 V.
Compute the branch currents from the voltages:
- Through R1: 8 V / 1 kΩ = 8 mA, leaving node 1 to ground.
- Through R2: (8 V − 4 V) / 2 kΩ = 2 mA, leaving node 1 and entering node 2.
- Through R3: 4 V / 2 kΩ = 2 mA, leaving node 2 to ground.
At node 1, the source supplies 10 mA and 8 + 2 = 10 mA leaves. At node 2, 2 mA enters through R2 and 2 mA leaves through R3. Both nodes balance.
The code below defines a residual for each node: current entering minus current leaving. A correct solution gives residuals of zero. It then runs the same check on a wrong answer.
import numpy as np
R1, R2, R3 = 1000.0, 2000.0, 2000.0
I_SOURCE = 0.010 # amperes, entering node 1
def residuals(v1, v2):
"""Entering minus leaving current at nodes 1 and 2, in amperes."""
i_r1 = v1 / R1 # leaves node 1
i_r2 = (v1 - v2) / R2 # leaves node 1, enters node 2
i_r3 = v2 / R3 # leaves node 2
node1 = I_SOURCE - i_r1 - i_r2
node2 = i_r2 - i_r3
return node1, node2
for label, (v1, v2) in [("correct", (8.0, 4.0)), ("wrong", (8.0, 5.0))]:
r1, r2 = residuals(v1, v2)
ok = np.isclose(r1, 0, atol=1e-12) and np.isclose(r2, 0, atol=1e-12)
# Adding 0.0 turns -0.0 into 0.0 so the printout stays clean.
print(label, "balanced:", bool(ok),
"residuals (mA):", round(r1 * 1e3, 6) + 0.0, round(r2 * 1e3, 6) + 0.0)The correct pair prints residuals of 0.0 mA at both nodes. The wrong pair (v2 = 5 V) prints residuals of 0.5 mA and −1.0 mA. The nonzero values show which nodes fail and by how much.
Reading the residuals
The residual pattern points to the cause.
| Pattern | Likely cause |
|---|---|
| One node off, others fine | Error in that node's equation, or a wrong resistor value there |
| Residual equals a source current | Source left out or entered with the wrong sign |
| Residuals at two nodes equal and opposite | Error in the branch between them, such as a wrong conductance or sign |
| All residuals tiny, around 1e-15 A | Floating-point rounding, which is acceptable |
Use a tolerance, not exact equality. Compare against a small fraction of the largest current in the circuit.
Exercise
A circuit has a 6 mA source entering node 1. R1 = 1 kΩ connects node 1 to ground, and R2 = 3 kΩ connects node 1 to node 2. Nothing else is attached to node 2. A student reports v1 = 4.5 V and v2 = 4.5 V. Does this pass the KCL check at node 1 and at node 2?
Show answer
Branch currents: through R1, 4.5 V / 1 kΩ = 4.5 mA leaving node 1. Through R2, (4.5 − 4.5) V / 3 kΩ = 0 mA. Node 1 has 6 mA entering and 4.5 mA leaving, so the residual is 1.5 mA and the check fails. Node 2 balances (0 mA in, 0 mA out), so the error shows up only at node 1. The correct value is v1 = 6 V, since all 6 mA must flow through R1, and v2 = 6 V because no current flows in R2.