Sub topic 7
Matrix Form: G v = i
This chapter assumes you can write a KCL equation at a node using Ohm's law, and that you know basic matrix notation and how to solve a small linear system. Here you will turn the node equations into one matrix equation, read it by inspection, and solve it with code.
From Equations to a Matrix
Take a circuit with a 2 A current source feeding node 1. R1 = 4 Ω runs from node 1 to ground. R2 = 2 Ω runs from node 1 to node 2. R3 = 6 Ω runs from node 2 to ground. Write each resistor as a conductance, g = 1/R, so g1 = 1/4 S, g2 = 1/2 S and g3 = 1/6 S.
KCL at node 1 (currents leaving the node equal the source current entering it):
g1 V1 + g2 (V1 − V2) = 2
KCL at node 2:
g2 (V2 − V1) + g3 V2 = 0
Collect the terms by unknown:
(g1 + g2) V1 − g2 V2 = 2
−g2 V1 + (g2 + g3) V2 = 0
In matrix form this is G v = i:
- G is the conductance matrix, with one row and one column per non-reference node.
- v is the vector of unknown node voltages.
- i is the vector of source currents entering each node.
Reading G by Inspection
You can fill in G without writing the equations first.
- Diagonal entry G[k][k]: the sum of the conductances of every resistor connected to node k.
- Off-diagonal entry G[j][k]: the negative of the total conductance directly between nodes j and k.
- Entry i[k]: the net source current flowing into node k.
For the example above:
G = [[0.75, −0.5], [−0.5, 0.6667]], i = [2, 0]
The first row sums to 0.25 because the leftover is g1, the conductance to ground. A resistor that connects two non-reference nodes adds to the diagonal twice and to the off-diagonal entries with a minus sign. A resistor to ground adds only to one diagonal entry.
Solving with NumPy
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. ]The result is V1 = 16/3 V (about 5.333 V) and V2 = 4 V. Use np.linalg.solve rather than computing the inverse of G. It is faster and loses less accuracy.
Properties to Check
For a circuit made only of resistors and independent current sources, G has useful structure:
- It is symmetric, so G[j][k] = G[k][j].
- Its diagonal entries are positive.
- Its off-diagonal entries are zero or negative.
- Each row sum equals the conductance from that node to ground.
If your matrix breaks one of these rules, you probably made a sign error or missed a resistor. Dependent sources break symmetry, so that check applies only to circuits without them.
Common Errors
- Using resistance instead of conductance in G. The entries must be in siemens.
- Forgetting that a resistor between two nodes appears in four places: two diagonal entries and two off-diagonal entries.
- Counting a resistor to ground in an off-diagonal entry. It belongs only on the diagonal.
- Putting the wrong sign on the source current for a node where the source arrow points away.
Exercise
A 3 A source feeds node 1. A 2 Ω resistor connects node 1 to ground. A 4 Ω resistor connects node 1 to node 2. A 4 Ω resistor connects node 2 to ground. Write G and i, then find V1 and V2.
Show answer
The conductances are 1/2 S, 1/4 S and 1/4 S. G = [[0.75, −0.25], [−0.25, 0.5]] and i = [3, 0]. The second equation gives V2 = 0.5 V1. Substituting into the first, 0.75 V1 − 0.125 V1 = 3, so V1 = 4.8 V and V2 = 2.4 V.