Sub topic 8
From KCL to nodal equations
This chapter assumes you can already write KCL at a single node, assign current reference directions, apply Ohm's law to a resistor, and solve a small system of linear equations. Here you will turn those pieces into a repeatable method. In nodal analysis, the unknowns are node voltages, and each equation is KCL written at one node.
The idea behind nodal analysis
KCL at one node relates the branch currents meeting there. Ohm's law relates each resistor's current to the voltage across it. Nodal analysis combines the two, so each branch current is replaced by a voltage difference divided by a resistance. The branch currents then disappear from the equations, and only node voltages remain.
A node voltage is the voltage of a node measured against a chosen reference node, which is usually called ground and given the value 0 V. Once the node voltages are known, every branch voltage is a difference of two of them. Every branch current follows from Ohm's law.
The method has two attractions:
- You never have to guess a current direction for each resistor. A single rule covers every branch.
- A circuit with N nodes needs only N − 1 equations, because the reference node's voltage is fixed at 0 V.
Step 1: choose a reference node and label the others
Pick one node as the reference. Any node works mathematically. In practice, choose the node with the most connections, or the one that many sources share. This leaves the fewest terms in the equations.
Label the remaining nodes v1, v2, and so on. Each label stands for that node's voltage relative to the reference.
Step 2: write the branch current for each resistor
Take a resistor R between node a and node b. If you define its current as flowing from a to b, then:
i(a→b) = (va − vb) / R
Current flows from the higher voltage to the lower voltage. The expression is positive when va is greater than vb, which matches the direction you defined. If b is the reference node, the expression becomes va / R.
It is often easier to use conductance, G = 1/R, measured in siemens (S). Then i(a→b) = G (va − vb). Conductances add when you collect terms, and this makes the matrix form below easy to see.
Step 3: write KCL at each non-reference node
Pick one convention and use it at every node. A good one is to write the sum of currents leaving the node and set it equal to the source current entering the node:
(sum of resistor currents leaving node k) = (source current entering node k)
With this convention, every resistor current is written as "this node's voltage minus the neighbor's voltage, divided by R". The sign of each term is then automatic, and you do not have to decide a direction for each branch.
Worked example: two nodes
A 10 mA current 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.
Write KCL at node 1. The current leaving through R1 is v1/R1. The current leaving through R2 toward node 2 is (v1 − v2)/R2. Together they equal the 10 mA source current:
v1/1000 + (v1 − v2)/2000 = 0.010
Write KCL at node 2. Nothing is injected there, so the currents leaving it sum to zero. The current leaving node 2 toward node 1 through R2 is (v2 − v1)/R2. The current leaving through R3 to ground is v2/R3:
(v2 − v1)/2000 + v2/2000 = 0
Using kΩ for resistance and mA for current keeps the numbers small. With volts, kΩ, and mA, the equations become:
- Node 1: 10 = 1.5 v1 − 0.5 v2
- Node 2: 0 = −0.5 v1 + 1.0 v2
Equation 2 gives v2 = 0.5 v1. Substituting into equation 1 gives 10 = 1.5 v1 − 0.25 v1 = 1.25 v1, so v1 = 8 V and v2 = 4 V.
Check the branch currents. R1 carries 8 V / 1 kΩ = 8 mA. R2 carries (8 − 4) V / 2 kΩ = 2 mA from node 1 to node 2. R3 carries 4 V / 2 kΩ = 2 mA. At node 1, 8 mA + 2 mA = 10 mA leave, matching the source. At node 2, 2 mA arrives through R2 and 2 mA leaves through R3.
The matrix form G v = I
Look at the coefficients in the two equations above. They follow a pattern that holds for any circuit made only of resistors and independent current sources:
- The diagonal entry for node k is the sum of all conductances connected to node k.
- The off-diagonal entry for nodes j and k is the negative of the total conductance directly between j and k. It is zero if no resistor joins them.
- The right-hand side entry for node k is the net source current entering node k.
Written as a matrix equation, this is G v = I, where G is the conductance matrix, v is the vector of node voltages, and I is the vector of injected source currents. For the example:
| Row | v1 | v2 | Right side |
|---|---|---|---|
| Node 1 | 1/R1 + 1/R2 | −1/R2 | 10 mA |
| Node 2 | −1/R2 | 1/R2 + 1/R3 | 0 |
Because the same conductance appears at positions (j, k) and (k, j), the matrix is symmetric when all the elements are resistors and independent sources. A matrix that fails this symmetry test is a warning that you made an error, or that the circuit contains dependent sources, which are covered in a later chapter.
Solving it with code
The following script solves the example and then checks KCL at node 1 using the computed voltages.
import numpy as np
# 10 mA source into node 1. R1 = 1 kohm (node 1 to ground),
# R2 = 2 kohm (node 1 to node 2), R3 = 2 kohm (node 2 to ground).
R1, R2, R3 = 1000.0, 2000.0, 2000.0
G = np.array([
[1/R1 + 1/R2, -1/R2],
[-1/R2, 1/R2 + 1/R3],
])
I = np.array([0.010, 0.0]) # source current entering each node
v1, v2 = np.linalg.solve(G, I)
print(v1, v2) # 8.0 4.0 (volts)
# Check KCL at node 1: source current equals the sum of currents leaving
i_r1 = v1 / R1
i_r2 = (v1 - v2) / R2
print(i_r1 + i_r2) # 0.01 (amperes)Writing the matrix by hand does not scale to larger circuits. The next script builds G automatically from a list of resistors. Node 0 is ground, and nodes 1, 2, and so on are the unknowns. Each resistor adds its conductance to the diagonal entries of its end nodes and subtracts it from the off-diagonal entries. Terms that involve ground are left out, because the ground voltage is 0 V.
import numpy as np
def solve_nodes(num_nodes, resistors, injections):
"""Solve G v = I for node voltages.
num_nodes: number of non-ground nodes (labeled 1..num_nodes)
resistors: list of (node_a, node_b, ohms); node 0 is ground
injections: source current entering each node 1..num_nodes, in amperes
"""
G = np.zeros((num_nodes, num_nodes))
for a, b, r in resistors:
g = 1.0 / r
if a > 0:
G[a - 1, a - 1] += g
if b > 0:
G[b - 1, b - 1] += g
if a > 0 and b > 0:
G[a - 1, b - 1] -= g
G[b - 1, a - 1] -= g
return np.linalg.solve(G, np.array(injections, dtype=float))
resistors = [(1, 0, 1000.0), (1, 2, 2000.0), (2, 0, 2000.0)]
v = solve_nodes(2, resistors, [0.010, 0.0])
print(v) # [8. 4.]Common errors
Most wrong answers in nodal analysis come from a short list of mistakes.
- Mixed sign conventions. If you write "currents leaving" at one node and "currents entering" at another, the equations still hold individually, but the matrix loses its regular pattern and mistakes are hard to spot. Pick one convention for the whole circuit.
- Wrong sign on the source. A source that pushes current into a node goes on the right-hand side with a positive sign under the "leaving equals source entering" convention. A source pulling current out of the node gets a negative sign.
- Forgetting a resistor in a diagonal entry. Each diagonal entry must include every resistor touching the node, including those to ground.
- Writing an equation for the reference node. The reference node is not an unknown, and its equation is redundant. Adding it makes the system singular or inconsistent.
- Mixing units. Using ohms with milliamps gives answers off by a factor of 1000. Either work in base units or use kΩ with mA throughout.
Checking and interpreting the result
After solving, always run a KCL check at one or two nodes using the computed voltages. The check is cheap and independent of how you built the equations. If the currents leaving a node do not equal the injected current, the equation set contains an error, even if the arithmetic in the solving step was correct.
Also check that the results are plausible. In a circuit driven by one current source and containing only resistors, node voltages measured from ground are positive when current is injected into the node. A node farther along a resistor chain from the source has a lower voltage than the node nearer it, as v2 = 4 V is lower than v1 = 8 V in the example.
Summary of the procedure
- Choose a reference node and label the other nodes.
- At each non-reference node, write the sum of currents leaving through resistors as (vk − vj)/R terms.
- Set that sum equal to the source current entering the node.
- Collect terms into G v = I, or read G directly from the conductances.
- Solve for the node voltages.
- Compute branch currents with Ohm's law and check KCL at one or more nodes.
Exercise
A 5 mA current source feeds node 1. R1 = 1 kΩ connects node 1 to ground, R2 = 1 kΩ connects node 1 to node 2, and R3 = 1 kΩ connects node 2 to ground. Write the nodal equations, find v1 and v2, and confirm KCL at node 1.
Show answer
Using kΩ and mA, node 1 gives 5 = (1 + 1) v1 − 1 v2 = 2 v1 − v2. Node 2 gives 0 = −v1 + 2 v2, so v1 = 2 v2. Substituting, 5 = 4 v2 − v2 = 3 v2, so v2 = 5/3 ≈ 1.67 V and v1 = 10/3 ≈ 3.33 V. Check at node 1: the current through R1 is 3.33 mA and the current through R2 is (3.33 − 1.67) mA = 1.67 mA. The two currents leaving node 1 sum to 5.00 mA, which equals the source current.
Exercise
In a nodal-analysis matrix built from resistors and independent current sources only, the entry in row 2, column 3 is −0.4 mS. What is the entry in row 3, column 2, and what resistor does it describe?
Show answer
The entry is also −0.4 mS, because the matrix is symmetric. It describes a resistor directly between node 2 and node 3 with R = 1/0.4 mS = 2.5 kΩ. If other resistors also join nodes 2 and 3 in parallel, −0.4 mS is their combined conductance.