Sub topic 7
Matrix Form: G v = i
This chapter assumes you can write KCL equations at a node using conductance, and that you can solve a small linear system. You also need basic matrix notation: rows, columns, a matrix times a vector, and a symmetric matrix. Here you collect the nodal equations into one matrix equation, G v = i, and learn to read the matrix directly from the circuit.
Why a matrix form
For a circuit with n non-reference nodes, nodal analysis gives n equations in n unknown node voltages. Written one at a time, they are easy to get wrong when n grows. Written as G v = i, they have a fixed structure:
vis the column vector of unknown node voltages.Gis the conductance matrix, an n by n matrix built from the resistors.iis the column vector of source currents injected into each node.
Once the equations are in this form, solving them is a standard linear-algebra step. You can also check your setup by looking at the matrix before you solve it.
From KCL equations to a matrix
Take a circuit with a 2 A current source feeding node 1. Resistor R1 = 4 Ω connects node 1 to ground. Resistor R2 = 2 Ω connects node 1 to node 2. Resistor R3 = 6 Ω connects node 2 to ground. The conductances are g1 = 1/4 S, g2 = 1/2 S, and g3 = 1/6 S. The siemens (S) is the unit of conductance, equal to 1/Ω.
Write KCL at each node as "sum of currents leaving through resistors = current injected by sources".
Node 1:
g1 V1 + g2 (V1 − V2) = 2
Node 2:
g2 (V2 − V1) + g3 V2 = 0
Collect the terms in V1 and V2:
- Node 1: (g1 + g2) V1 − g2 V2 = 2
- Node 2: −g2 V1 + (g2 + g3) V2 = 0
In matrix form:
[ g1+g2 -g2 ] [V1] [2]
[ -g2 g2+g3 ] [V2] = [0]With numbers, G = [[0.75, −0.5], [−0.5, 0.6667]] and i = [2, 0].
How to read G from the circuit
The pattern in the example holds for any circuit made of resistors and independent sources, as long as you write KCL with currents leaving the node on the left side.
| Entry | Rule |
|---|---|
| Diagonal G[k,k] | Sum of the conductances of all resistors connected to node k, including those going to ground |
| Off-diagonal G[j,k] | Minus the sum of the conductances of all resistors connected directly between node j and node k |
| i[k] | Net source current flowing into node k |
Zero is the off-diagonal value when no resistor joins the two nodes. In a circuit with many nodes, G is mostly zeros, because each node touches only a few others.
Two consequences follow from these rules:
- G is symmetric. The resistor between nodes j and k contributes the same −g to both G[j,k] and G[k,j].
- Every diagonal entry is positive, and in each row the diagonal is at least as large as the sum of the magnitudes of the off-diagonal entries. The two are equal when the node has no resistor to ground.
Symmetry is a quick error check. If your matrix is not symmetric and the circuit has only resistors and independent sources, you made a mistake.
Sign convention for i
The vector i holds currents entering each node from sources. A current source pushing 2 A into node 1 gives i[1] = +2. If the source pulls current out of the node, the entry is negative. If a node has two sources, add their contributions.
Keeping the convention fixed matters. The left side of each equation counts current leaving through resistors, so the right side must count current arriving from sources.
Solving it
Here is the first example in Python.
import numpy as np
# A 2 A source feeds node 1.
# R1 = 4 ohm (node 1 to ground), R2 = 2 ohm (node 1 to node 2), R3 = 6 ohm (node 2 to ground).
g1, g2, g3 = 1/4, 1/2, 1/6
G = np.array([[g1 + g2, -g2],
[-g2, g2 + g3]])
i = np.array([2.0, 0.0])
v = np.linalg.solve(G, i)
print(v) # [5.33333333 4. ]So V1 = 16/3 V (about 5.333 V) and V2 = 4 V.
You can confirm this by hand. Node 2 has only R2 and R3, which form a divider from node 1 to ground, with total resistance 8 Ω. The divider gives V2 = V1 × 6/8 = 5.333 × 0.75 = 4 V. The result agrees.
Hand solution with Cramer's rule
For a 2 by 2 system, Cramer's rule is short. The determinant of G is:
det G = (g1 + g2)(g2 + g3) − g2²
With the example values, (0.75)(0.6667) − 0.25 = 0.5 − 0.25 = 0.25.
Replace the first column of G with i to get V1:
V1 = (2 × 0.6667 − (−0.5)(0)) / 0.25 = 1.3333 / 0.25 = 5.333 V
Replace the second column to get V2:
V2 = (0.75 × 0 − (−0.5)(2)) / 0.25 = 1 / 0.25 = 4 V
Both values match the numerical solution.
A three-node pattern
The same rules scale directly. Suppose three nodes are connected in a chain, with conductances ga from node 1 to ground, gb between nodes 1 and 2, gc between nodes 2 and 3, and gd from node 3 to ground. Then:
[ ga+gb -gb 0 ]
[ -gb gb+gc -gc ]
[ 0 -gc gc+gd ]The zeros in the corners appear because nodes 1 and 3 share no resistor. Matrices like this one are called tridiagonal. You can write the whole matrix without deriving any KCL equation, if you apply the table above.
Common errors
- Using resistance instead of conductance. Entries of G are in siemens. If you place 4 instead of 0.25, the results are wrong by a large factor.
- Wrong sign on off-diagonals. Off-diagonal entries are always negative or zero for resistive networks.
- Forgetting the resistor to ground on the diagonal. A resistor to the reference node adds to the diagonal entry of its node and appears nowhere else.
- Mixing source directions. Check each source arrow against "into the node" before writing
i. - Counting a parallel resistor once. Two resistors between the same two nodes both contribute. Add their conductances.
Diagram of the workflow
Exercises
Exercise
A circuit has two non-reference nodes. A 3 mS resistor connects node 1 to ground, a 1 mS resistor connects node 1 to node 2, and a 2 mS resistor connects node 2 to ground. A 5 mA source pushes current into node 2. Write G and i, in siemens and amperes.
Show answer
G = [[4e-3, -1e-3], [-1e-3, 3e-3]] S and i = [0, 5e-3] A. The diagonal entries are 3 mS + 1 mS = 4 mS for node 1 and 1 mS + 2 mS = 3 mS for node 2. The off-diagonal entries are −1 mS.
Exercise
Solve the system from the previous exercise for V1 and V2.
Show answer
det G = (4e-3)(3e-3) − (1e-3)² = 11e-6. V1 = (0 × 3e-3 − (−1e-3)(5e-3)) / 11e-6 = 5e-6 / 11e-6 ≈ 0.4545 V. V2 = (4e-3 × 5e-3 − 0) / 11e-6 = 20e-6 / 11e-6 ≈ 1.818 V.
Exercise
A student builds G for a resistor-only circuit and finds G[1,2] = −0.5 but G[2,1] = −0.25. What does this tell you?
Show answer
The matrix must be symmetric for a circuit of resistors and independent sources, so at least one entry is wrong. The same resistor between nodes 1 and 2 contributes the same conductance to both off-diagonal entries. Recheck the resistors connected between those two nodes.