Sub topic 13
Checking a solution by balancing node currents
Nodal analysis gives you node voltages, and a wrong voltage looks as plausible as a right one. This chapter shows how to use KCL a second time, as a test of the answer you already have. The check takes a minute and catches most algebra, sign, and unit mistakes.
This chapter assumes you can write nodal equations with Ohm's law, solve a small linear system by hand or with NumPy, and read a schematic with resistors, independent sources, and a ground node. The earlier chapters on signs and nodal equations apply directly.
The idea: substitute back and balance
A set of node voltages is correct only if KCL holds at every node when you compute each branch current from those voltages. The check has four steps:
- Take the solved node voltages.
- For every branch touching a node, compute the current from the original circuit values, using Ohm's law or the source value.
- Add up the currents leaving the node. Count currents entering as negative.
- The sum, called the residual, must be zero within rounding error.
The words "from the original circuit" matter. If you reuse your own matrix or your own equations, any mistake in them carries into the check and the check passes anyway. Go back to the schematic and recompute each branch current from the element values printed on it.
A worked check by hand
Use the circuit from the nodal-analysis chapter. A 10 mA current source pushes current into 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 solution was v1 = 8 V and v2 = 4 V.
Compute the branch currents from the voltages:
- Through R1, from node 1 to ground: 8 V / 1000 Ω = 8 mA.
- Through R2, from node 1 to node 2: (8 V − 4 V) / 2000 Ω = 2 mA.
- Through R3, from node 2 to ground: 4 V / 2000 Ω = 2 mA.
Now balance each node, taking leaving currents as positive:
- Node 1: 8 mA + 2 mA leave through R1 and R2, and 10 mA enters from the source. The residual is 8 + 2 − 10 = 0.
- Node 2: 2 mA enters through R2 and 2 mA leaves through R3. The residual is −2 + 2 = 0.
Both nodes balance, so the solution passes.
Check the ground node too
You wrote nodal equations only for the non-ground nodes, because the ground equation is redundant. Every branch current leaves one node and enters another, so it appears once with a plus sign and once with a minus sign when you add the residuals of all nodes. That sum is therefore always zero. The ground residual equals minus the sum of all the other residuals.
This helps in two ways. First, checking the ground node is a free test that does not depend on any equation you wrote. Second, if the other residuals are zero and the ground residual is not, you made an arithmetic error in a branch current, not in the equations.
In the example, the ground node sees 8 mA arriving through R1 and 2 mA through R3. That is 10 mA arriving, balanced by the source drawing 10 mA out of ground. The residual is 0.
Automating the check
For larger circuits, write the check as code that reads the circuit description and the solved voltages. This program does not use the matrix G. It rebuilds each branch current from the element list, so it tests the solution against the circuit and not against your equations.
import numpy as np
# Node 0 is ground. Each resistor is (name, node_a, node_b, ohms).
# Its current is (v[a] - v[b]) / R, positive from a to b.
resistors = [
("R1", 1, 0, 1000.0),
("R2", 1, 2, 2000.0),
("R3", 2, 0, 2000.0),
]
# Each current source is (name, node_a, node_b, amperes).
# Its current flows through the source from node_a to node_b.
sources = [("Is", 0, 1, 0.010)]
# Solve the two nodal equations for nodes 1 and 2.
G = np.array([
[1/1000.0 + 1/2000.0, -1/2000.0],
[-1/2000.0, 1/2000.0 + 1/2000.0],
])
I = np.array([0.010, 0.0])
v1, v2 = np.linalg.solve(G, I)
v = {0: 0.0, 1: v1, 2: v2}
# Sum of currents leaving each node, built branch by branch.
leaving = {n: 0.0 for n in v}
scale = {n: 0.0 for n in v} # largest single branch current at each node
def add_branch(a, b, i):
leaving[a] += i # i leaves node a
leaving[b] -= i # the same i enters node b
scale[a] = max(scale[a], abs(i))
scale[b] = max(scale[b], abs(i))
for name, a, b, r in resistors:
add_branch(a, b, (v[a] - v[b]) / r)
for name, a, b, amps in sources:
add_branch(a, b, amps)
for n in sorted(v):
tol = 1e-9 * max(scale[n], 1e-12)
status = "balanced" if abs(leaving[n]) <= tol else "NOT balanced"
print(f"node {n}: residual {leaving[n]:.3e} A, {status}")
# The residuals of all nodes always add to zero.
print(abs(sum(leaving.values())) < 1e-12)All three nodes print as balanced, and the last line prints True. The tolerance is relative to the largest branch current at the node. A fixed tolerance such as 1e-6 A would be meaningless in a circuit that carries microamps and far too strict in one that carries kiloamps.
Floating-point arithmetic leaves residuals around 1e-18 to 1e-15 times the current scale. A residual of 1e-3 times the scale is not rounding. It is an error.
Reading the residual
A nonzero residual tells you where to look. The node with the largest residual is the first place to inspect, and its size gives a clue about the cause.
| Observation | Likely cause |
|---|---|
| Residual equals twice one branch current at the node | One current was added with the wrong sign |
| Residual equals exactly one branch current | A branch was left out of the equation |
| Residual is off by a factor of 1000 | kΩ or mA used as if they were Ω or A |
| One node fails, its neighbours pass | Error in that node's own equation or in one conductance entry |
| All nodes fail by similar amounts | Wrong source value or wrong sign on the source vector |
| Node residuals pass but you doubt the answer | The check reused your equations, so recompute from the schematic |
Compare the residual with the individual branch currents before guessing. A residual of 2 mA at a node with a 1 mA branch cannot come from a missing branch alone, so look for a sign flip or a doubled term.
Checks for special cases
Supernodes
When a voltage source joins two non-ground nodes, you solved with a supernode. Check KCL on the whole supernode: add the currents leaving the resistive branches of both nodes. The source current inside the supernode cancels, so the sum must be zero.
Then compute the source current by applying KCL at one of its two nodes alone. This is the step where a supernode solution is most often left unchecked. Finally, confirm the source constraint directly. The difference between the two node voltages must equal the source voltage.
Dependent sources
A dependent source current depends on a voltage or current elsewhere in the circuit. In the check, compute that controlling quantity from your solved voltages first, then compute the dependent source's current from it, then balance the nodes. If you used the nominal source gain from memory and not from the schematic, the check fails.
Cutsets and closed surfaces
For a large circuit, you can check on a closed surface that cuts through several branches. The currents leaving the region must sum to zero. This tests the solution at several nodes at once. If the surface check fails, one of the nodes inside it fails too, and you can then check the nodes individually.
A second, independent check: power balance
KCL checks currents. A power check tests the voltages in a different way. In any circuit, the power delivered by sources equals the power absorbed by resistors. In the worked example, the current source delivers 10 mA × 8 V = 80 mW. The resistors absorb:
- R1: 8 mA × 8 V = 64 mW.
- R2: 2 mA × 4 V = 8 mW.
- R3: 2 mA × 4 V = 8 mW.
The total is 80 mW, matching the source. Use both checks together. A wrong answer that happens to balance one rarely balances the other.
Common mistakes when checking
- Using the voltage at one end instead of the difference across the branch.
- Defining currents as leaving in the equations but as entering in the check, then forgetting the sign change.
- Counting the source current at the wrong node.
- Declaring "close enough" with a tolerance larger than the smallest branch current.
- Checking only the nodes you wrote equations for, and skipping the ground node.
Practice
Exercise
A student solves a circuit with a 5 mA current source into node 1, R1 = 2 kΩ from node 1 to ground, R2 = 4 kΩ from node 1 to node 2, and R3 = 4 kΩ from node 2 to ground. The student reports v1 = 10 V and v2 = 5 V. Check each node with KCL. Does the solution pass, and if not, what is the correct answer?
Show answer
At node 1, the current leaving through R1 is 10 V / 2 kΩ = 5 mA, and through R2 it is (10 − 5) V / 4 kΩ = 1.25 mA. That is 6.25 mA leaving against 5 mA entering, so the residual is 1.25 mA and the node fails. At node 2, 1.25 mA enters through R2 and 5 V / 4 kΩ = 1.25 mA leaves through R3, so node 2 balances. The values keep the right ratio v2 = v1/2 but have the wrong overall scale. Solving the equations again gives v1 = 8 V and v2 = 4 V. Check: R1 carries 4 mA and R2 carries 1 mA, which sum to 5 mA.
Exercise
In the check above you found that node 2 balanced even though the solution was wrong. Why does a single balanced node not prove the solution is right, and which check would you do next?
Show answer
Each node equation involves only the voltages of that node and its neighbours. Node 2's balance depends only on the ratio v2 / v1 and not on their scale, so wrong voltages with the right ratio still balance there. A solution is correct only if every node balances, including the ground node. Check the other non-ground nodes and then the ground node, which tests the source current directly. A power-balance check would also catch this error, because the 10 V solution makes the source deliver 50 mW but the resistors absorb 62.5 mW.