TExcelTAD
Home › Circuit Theory & Network Analysis › Linear Systems: The Algebra Behind Nodal Analysis

Linear Systems: The Algebra Behind Nodal Analysis

Every systematic circuit method in this course ends the same way: a set of linear equations, one per node or per mesh, that must be solved together. A three-node circuit is a pencil exercise; a forty-node filter board or a power grid with thousands of buses is not. This lesson shows what those equations look like as a matrix, how they are solved by elimination, when the answer can be trusted, and what the inverse matrix means physically. The general theory is in the Linear Algebra course: Gaussian Elimination, Cramer's Rule, Matrix Inverses and, closest to this lesson, Resistor Networks. Numerical behaviour is in LU Factorization and Matrix Conditioning.

From a circuit to Gv=iG\mathbf{v} = \mathbf{i}

Kirchhoff's current law at each node, with Ohm's law for each resistor, is linear in the node voltages. Collected into matrix form it reads

G v=iG\,\mathbf{v} = \mathbf{i}

where GG is the conductance matrix (siemens), v\mathbf{v} the unknown node voltages and i\mathbf{i} the source currents injected into the nodes. For the ladder below, with conductances in mS (since 1/kΩ=1 mS1/\text{k}\Omega = 1\ \text{mS}):

I1 6 mA R1 1 kOhm R2 1 kOhm R3 2 kOhm R4 1 kOhm R5 1 kOhm 1 2 3 v1 = 4 V v2 = 2 V v3 = 1 V
[2−10−12.5−10−12][v1v2v3]=[600]\begin{bmatrix} 2 & -1 & 0 \\ -1 & 2.5 & -1 \\ 0 & -1 & 2 \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \\ v_3 \end{bmatrix} = \begin{bmatrix} 6 \\ 0 \\ 0 \end{bmatrix}

Row 2 says: node 2 touches R2R_2, R3R_3 and R4R_4 (1+0.5+1=2.5 mS1 + 0.5 + 1 = 2.5\ \text{mS}) and is coupled to nodes 1 and 3 through 1 mS1\ \text{mS} each. The structure is typical of circuits:

  • Symmetric, Gkm=GmkG_{km} = G_{mk}, for resistors and independent sources (Node-Voltage Analysis).
  • Sparse: a node connects to a handful of neighbours, so most entries are zero. Real simulators store only the nonzeros.
  • Diagonally dominant: each diagonal entry is at least the sum of the magnitudes of the off-diagonal entries in its row (strictly larger wherever a resistor goes to ground). That guarantees a unique solution and makes elimination stable without row swaps.

Solving it: elimination, by hand once

Gaussian elimination turns the system into a triangular one and then back-substitutes. On the augmented matrix:

[2−106−12.5−100−120]→R2+12R1[2−10602−130−120]→R3+12R2[2−10602−13001.51.5]\left[\begin{array}{ccc|c} 2 & -1 & 0 & 6 \\ -1 & 2.5 & -1 & 0 \\ 0 & -1 & 2 & 0 \end{array}\right] \xrightarrow{R_2 + \frac{1}{2}R_1} \left[\begin{array}{ccc|c} 2 & -1 & 0 & 6 \\ 0 & 2 & -1 & 3 \\ 0 & -1 & 2 & 0 \end{array}\right] \xrightarrow{R_3 + \frac{1}{2}R_2} \left[\begin{array}{ccc|c} 2 & -1 & 0 & 6 \\ 0 & 2 & -1 & 3 \\ 0 & 0 & 1.5 & 1.5 \end{array}\right]

Back-substitution: v3=1.5/1.5=1 Vv_3 = 1.5/1.5 = 1\ \text{V}, v2=(3+v3)/2=2 Vv_2 = (3 + v_3)/2 = 2\ \text{V}, v1=(6+v2)/2=4 Vv_1 = (6 + v_2)/2 = 4\ \text{V}. Each rung of this ladder halves the voltage.

Cramer's rule (vk=det⁡Gk/det⁡Gv_k = \det G_k / \det G) is handy for 2×22 \times 2 systems and symbolic answers, but its cost grows factorially if done by cofactors; elimination costs about 23n3\tfrac{2}{3}n^3 operations, and sparse elimination far less. SPICE uses sparse LU factorization: it factors G=LUG = LU once and reuses LL and UU for every right-hand side.

What G−1G^{-1} means: transfer resistances

The solution is v=G−1i\mathbf{v} = G^{-1}\mathbf{i}. Column mm of G−1G^{-1} is the set of node voltages produced by 1 A1\ \text{A} injected at node mm alone, so its entries have units of ohms. They are transfer resistances: Rkm=vk/imR_{km} = v_k / i_m. The diagonal entry RkkR_{kk} is the resistance seen between node kk and ground (the Thevenin resistance there). Because GG is symmetric, so is G−1G^{-1}: injecting current at node 1 and measuring at node 3 gives the same ratio as the other way round. This is the reciprocity theorem, which returns for two-port networks.

Worked example: the ladder

Given: the ladder above, I1=6 mAI_1 = 6\ \text{mA} into node 1.

Find: the node voltages, det⁡G\det G, the resistance seen from node 1 to ground, and the transfer resistance from node 1 to node 3.

Solve: elimination gave v1=4 Vv_1 = 4\ \text{V}, v2=2 Vv_2 = 2\ \text{V}, v3=1 Vv_3 = 1\ \text{V}. The determinant is the product of the pivots: det⁡G=2⋅2⋅1.5=6 mS3\det G = 2 \cdot 2 \cdot 1.5 = 6\ \text{mS}^3. The resistance at node 1 is R11=v1/I1=4 V/6 mA=0.667 kΩR_{11} = v_1/I_1 = 4\ \text{V}/6\ \text{mA} = 0.667\ \text{k}\Omega, and the transfer resistance is R31=v3/I1=1 V/6 mA=0.167 kΩR_{31} = v_3/I_1 = 1\ \text{V}/6\ \text{mA} = 0.167\ \text{k}\Omega.

Check: by series and parallel reduction, node 1 sees R1∥(R2+R3∥(R4+R5))=1∥(1+2∥2)=1∥2=0.667 kΩR_1 \parallel (R_2 + R_3 \parallel (R_4 + R_5)) = 1 \parallel (1 + 2 \parallel 2) = 1 \parallel 2 = 0.667\ \text{k}\Omega. Same answer, by a different route.

In Python

python · try it yourself
import numpy as np
np.set_printoptions(precision=4, suppress=True)

G = np.array([[ 2.0, -1.0,  0.0],
              [-1.0,  2.5, -1.0],
              [ 0.0, -1.0,  2.0]])          # mS
i = np.array([6.0, 0.0, 0.0])                # mA

v = np.linalg.solve(G, i)                    # LU with partial pivoting
print("v (V):", v)
print("det G = %.4f mS^3" % np.linalg.det(G))
print("symmetric:", np.allclose(G, G.T))

Rt = np.linalg.inv(G)                        # kOhm: transfer resistances
print("G^-1 (kOhm):\n", Rt)

# several source patterns at once: one column per right-hand side
I = np.array([[6.0, 0.0], [0.0, 0.0], [0.0, 6.0]])
print("two cases:\n", np.linalg.solve(G, I))

# conditioning: a 1 ohm link between two nodes that each have 1 Mohm to ground
Gbad = np.array([[1 + 1e-6, -1.0], [-1.0, 1 + 1e-6]])
print("cond(G) = %.3g, cond(Gbad) = %.3g" % (np.linalg.cond(G), np.linalg.cond(Gbad)))
v (V): [4. 2. 1.]
det G = 6.0000 mS^3
symmetric: True
G^-1 (kOhm):
 [[0.6667 0.3333 0.1667]
 [0.3333 0.6667 0.3333]
 [0.1667 0.3333 0.6667]]
two cases:
 [[4. 1.]
 [2. 2.]
 [1. 4.]]
cond(G) = 4.53, cond(Gbad) = 2e+06

The second column of "two cases" is 6 mA6\ \text{mA} injected at node 3 instead. The ladder is symmetric end to end (R1=R5R_1 = R_5, R2=R4R_2 = R_4), so the answer is the first column upside down.

When to distrust the answer: conditioning

The condition number κ(G)=∥G∥∥G−1∥\kappa(G) = \lVert G \rVert \lVert G^{-1} \rVert estimates how much relative error in the data (resistor values, rounding) can grow in the solution. Rule of thumb: you lose about log⁡10κ\log_{10}\kappa of the 16 significant digits of double precision. The ladder has κ≈4.5\kappa \approx 4.5; the second matrix, a 1 Ω1\ \Omega link between two nodes that each have 1 MΩ1\ \text{M}\Omega to ground, has κ≈2×106\kappa \approx 2 \times 10^6. That is still fine in double precision (about 10 good digits remain), but it explains two things you will meet: simulators complain about "nearly singular" matrices when a node is connected only through huge resistances, and SPICE uses a tiny conductance gmin (default 10−12 S10^{-12}\ \text{S}), placed across semiconductor junctions and, during "gmin stepping", from nodes to ground, so that the matrix stays solvable. Physically, ill-conditioning means a quantity that hardly depends on the inputs you control: here the difference v1−v2v_1 - v_2 across the 1 Ω1\ \Omega link.

Guided lab: the ladder on the bench

Hand calculation. With 6 mA6\ \text{mA} injected at node 1: 4 V4\ \text{V}, 2 V2\ \text{V}, 1 V1\ \text{V}. The source sees 0.667 kΩ0.667\ \text{k}\Omega and delivers 6 mA⋅4 V=24 mW6\ \text{mA} \cdot 4\ \text{V} = 24\ \text{mW}.

Simulation. The netlist lab solves the same matrix live. Change R3R_3: every node voltage moves, because every row of GG is coupled to its neighbours.

node voltages (to ground 0)n14.000 Vn22.000 Vn31.000 VnetlistI1 0 n1 DC 6mR1 n1 0 1kR2 n1 n2 1kR3 n2 0 2kR4 n2 n3 1kR5 n3 0 1kelement currents (node 1 to node 2 through it)I10>n16.00 mAR1n1>04.00 mAR2n1>n22.00 mAR3n2>01.00 mAR4n2>n31.00 mAR5n3>01.00 mA

At the defaults it shows 4 V4\ \text{V}, 2 V2\ \text{V} and 1 V1\ \text{V}.

What you would measure. Use a bench supply in constant-current mode set to 6.0 mA6.0\ \text{mA}, with its voltage limit at 10 V10\ \text{V}, and 1 % resistors (two 1 kΩ1\ \text{k}\Omega in series make the 2 kΩ2\ \text{k}\Omega if you have no single part). Expect 4.004.00, 2.002.00 and 1.00 V1.00\ \text{V}, each within about 1.5 % (the resistors), scaled by the current you actually get: many supplies specify the current setting as a percentage plus a fixed offset of several milliamperes (for example ±(0.2 %+5 mA)\pm(0.2\,\% + 5\ \text{mA})), which is large at 6 mA6\ \text{mA}, so measure the current with a DMM in series and multiply the expected voltages by I/6.0 mAI/6.0\ \text{mA}; check your supply's manual. If a supply has no constant-current mode, 12 V12\ \text{V} through a 2.0 kΩ2.0\ \text{k}\Omega resistor into node 1 is not a substitute: Source Transformation shows it is a 6 mA6\ \text{mA} source with 2 kΩ2\ \text{k}\Omega in parallel, which loads node 1 and gives 3.003.00, 1.501.50 and 0.75 V0.75\ \text{V} instead (every voltage scaled by 0.750.75).

Hazards and safe setup: voltages stay below 10 V10\ \text{V} and the largest dissipation is 16 mW16\ \text{mW} (in R1R_1); set the supply's voltage limit before switching on, since an open circuit on a current source drives the voltage to the limit.

Pitfalls

  • Inverting to solve. np.linalg.solve(G, i) is faster and more accurate than np.linalg.inv(G) @ i; use the inverse only when you want the transfer resistances themselves.
  • A singular matrix. It almost always means a circuit error: a floating node, a loop of ideal voltage sources, a node connected only through current sources.
  • Mixed units in one matrix. Keep conductances in one unit (S or mS) and currents in the matching one (A or mA).
  • Trusting digits blindly. With a large condition number, check the residual Gv−iG\mathbf{v} - \mathbf{i} and think about which quantity is sensitive.

Practice

  1. For the ladder, find v\mathbf{v} when 2 mA2\ \text{mA} is injected at node 2 only, using the column of G−1G^{-1}.
  2. Solve by elimination: [3−1−12]v=[50]\begin{bmatrix} 3 & -1 \\ -1 & 2 \end{bmatrix}\mathbf{v} = \begin{bmatrix} 5 \\ 0 \end{bmatrix} (mS, mA).
  3. A matrix has κ=109\kappa = 10^{9}. Roughly how many significant digits of a double-precision solution can you trust?
Answer
  1. Column 2 of G−1G^{-1} is (0.333,0.667,0.333) kΩ(0.333, 0.667, 0.333)\ \text{k}\Omega; times 2 mA2\ \text{mA} gives v=(0.667,1.333,0.667) V\mathbf{v} = (0.667, 1.333, 0.667)\ \text{V}.
  2. R2+13R1R_2 + \tfrac{1}{3}R_1: 53v2=53\tfrac{5}{3}v_2 = \tfrac{5}{3}, so v2=1 Vv_2 = 1\ \text{V} and v1=(5+1)/3=2 Vv_1 = (5 + 1)/3 = 2\ \text{V}.
  3. About 16−9=716 - 9 = 7 digits.

Test yourself

A circuit of resistors and independent sources gives a conductance matrix that is…

  1. always singular
  2. symmetric
  3. upper triangular
  4. diagonal

Entry (k,m)(k, m) of G−1G^{-1} has units of…

  1. siemens
  2. volts
  3. ohms: it is the voltage at node kk per ampere injected at node mm
  4. amperes

Why does SPICE's gmin stepping add a tiny conductance from nodes to ground?

  1. to model leakage of real resistors
  2. to keep the matrix nonsingular when a node has no other path to ground
  3. to speed up AC analysis
  4. to make the matrix symmetric

Which is the preferred way to solve Gv=iG\mathbf{v} = \mathbf{i} numerically?

  1. np.linalg.inv(G) @ i
  2. np.linalg.solve(G, i)
  3. Cramer's rule with cofactors
  4. np.linalg.det(G)