CMP-240 · Lesson 4 of 12 · 22 min

Nodal analysis

Series and parallel reduction works only on circuits whose parts happen to line up neatly. A bridge, a network with several sources or a sensor feeding a buffered ADC usually cannot be simplified that way. Nodal analysis is a systematic method that works on any linear circuit. It chooses the node voltages as the unknowns, writes Kirchhoff's current law at each node with the currents expressed through Ohm's law, and solves the resulting set of linear equations. Because it is so systematic, it is also how circuit simulators such as SPICE work internally, and by the end of this lesson you will have written a small simulator of your own.

Jonah's next job on the NS-4 is the temperature sensor. A negative temperature coefficient (NTC) thermistor, whose resistance falls as it warms, sits in a small network with fixed resistors so that the ADC can read temperature over the full roadside range. Ines wants to add a second, fixed reference resistor so firmware can check the ADC's accuracy, and the resulting network is no longer a simple divider.

Node voltages

In nodal analysis one node is chosen as the reference, or ground, and every other node is given a voltage measured relative to it. In a circuit with n nodes there are n − 1 unknown node voltages. Once they are known, every branch voltage is the difference between two node voltages and every resistor current follows from Ohm's law. The choice of reference is free, but choosing the node with the most connections, often the negative terminal of the main supply, usually gives the simplest equations.

The method in its basic form has four steps. First, label the reference node and the remaining node voltages v₁, v₂ and so on. Second, at each non-reference node, write KCL with every current leaving the node expressed as the node's voltage minus the neighboring node's voltage, divided by the resistance between them. Third, collect terms to get one linear equation per node. Fourth, solve the equations by substitution, by matrix methods or by computer.

\[\text{current leaving node } j \text{ through } R = \frac{v_j - v_k}{R} = G\,(v_j - v_k)\]

Writing every current as leaving the node, whatever its real direction, removes the need to guess directions in advance and makes the bookkeeping identical at every node. Current sources are added directly: a source pushing current into the node appears as a known term on the other side of the equation.

A three-node resistor network. A 3.3 volt source on the left connects through a 10 kilohm resistor to node v1. From v1 an NTC thermistor goes down to ground and a 4.7 kilohm resistor goes right to node v2. From v2 a 22 kilohm resistor goes to ground and a 100 kilohm resistor labeled ADC input goes to ground. Node v1 and node v2 are marked with dots and labels.
The temperature-sensing network with two unknown node voltages, v₁ and v₂, measured relative to ground.

Writing the equations

Consider the sensor network in the figure, with the thermistor at 10 kΩ, its value at 25 °C. The 3.3 V source fixes one node directly, so the unknowns are v₁ and v₂. At node 1, three currents leave: back through the 10 kΩ resistor to the 3.3 V node, down through the thermistor, and across the 4.7 kΩ resistor to node 2. At node 2, currents leave back through the 4.7 kΩ resistor, down through the 22 kΩ resistor and down through the 100 kΩ ADC input resistance.

\[\text{Node 1:}\quad \frac{v_1 - 3.3}{10} + \frac{v_1}{10} + \frac{v_1 - v_2}{4.7} = 0 \qquad \text{Node 2:}\quad \frac{v_2 - v_1}{4.7} + \frac{v_2}{22} + \frac{v_2}{100} = 0 \quad (\text{k}\Omega,\ \text{mA})\]

Working in kilohms and milliamperes keeps the numbers tidy; volts divided by kilohms gives milliamperes directly. Collecting terms gives two equations in two unknowns. The pattern of the coefficients is worth noticing: each node's own voltage is multiplied by the sum of the conductances connected to it, and each neighboring node's voltage is multiplied by minus the conductance between them.

\[\begin{bmatrix} \tfrac{1}{10} + \tfrac{1}{10} + \tfrac{1}{4.7} & -\tfrac{1}{4.7} \\[4pt] -\tfrac{1}{4.7} & \tfrac{1}{4.7} + \tfrac{1}{22} + \tfrac{1}{100} \end{bmatrix} \begin{bmatrix} v_1 \\ v_2 \end{bmatrix} = \begin{bmatrix} 0.33 \\ 0 \end{bmatrix}\]

Worked problem

Solving the sensor network

Solve the two node equations above for v₁ and v₂, and find the current through the thermistor.

Show solution
  1. \[0.4128\,v_1 - 0.2128\,v_2 = 0.33\]
  2. \[-0.2128\,v_1 + 0.2683\,v_2 = 0\]
  3. From the second equation, v₂ = (0.2128/0.2683) v₁ = 0.7931 v₁.
  4. \[0.4128\,v_1 - 0.2128(0.7931\,v_1) = 0.33 \;\Rightarrow\; 0.2440\,v_1 = 0.33\]
  5. \[v_1 = 1.352\ \text{V}, \qquad v_2 = 0.7931 \times 1.352 = 1.073\ \text{V}\]
  6. \[i_{th} = \frac{1.352}{10\ \text{k}\Omega} = 0.135\ \text{mA}\]

Answer: At 25 °C the thermistor node sits at 1.35 V and the ADC sees 1.07 V. The thermistor carries 135 µA and dissipates only 0.18 mW, small enough that it does not noticeably heat itself, which would otherwise make it read high.

The conductance matrix

For a circuit containing only resistors and independent current sources, the node equations always take the form G v = i, where v is the vector of unknown node voltages, i is the vector of source currents injected into each node, and G is the conductance matrix. The matrix can be written by inspection. Each diagonal entry G_jj is the sum of all conductances connected to node j. Each off-diagonal entry G_jk is minus the sum of the conductances connecting nodes j and k. The matrix is therefore symmetric, and for a connected circuit with a reference node it is always invertible.

\[\mathbf{G}\,\mathbf{v} = \mathbf{i} \qquad G_{jj} = \sum (\text{conductances at node } j) \qquad G_{jk} = -\sum (\text{conductances between } j \text{ and } k)\]

A voltage source in series with a resistor can be converted into a current source in parallel with the same resistor, a source transformation that lesson 6 justifies. In the sensor network, the 3.3 V source and its 10 kΩ resistor are equivalent to a 0.33 mA source into node 1 in parallel with 10 kΩ to ground, which is why the right-hand side contains 0.33 mA and the diagonal contains the extra 1/10.

Voltage sources and supernodes

A voltage source connected between two non-reference nodes causes a difficulty: its current is unknown and cannot be written with Ohm's law. The solution is the supernode. Draw a boundary around the source and the two nodes it connects, apply KCL to the whole boundary, which avoids the unknown source current, and add the source's constraint equation, the difference between the two node voltages. The count of equations still matches the count of unknowns.

A voltage source connected between a node and the reference is even simpler: it fixes that node's voltage, removing one unknown. This is the usual situation on a digital board, where the supply rails are fixed by regulators and only the signal nodes are unknown.

Worked problem

A supernode: the reference diode

To give firmware a stable check voltage, Ines adds a precision 1.25 V reference element between node a and node b, with a above b. Node a connects to the 3.3 V rail through 2.2 kΩ, and node b connects to ground through 10 kΩ and to the ADC input of 100 kΩ. Model the reference as an ideal 1.25 V source and find v_a and v_b.

Show solution
  1. The source fixes v_a − v_b = 1.25 V; treat a and b as one supernode.
  2. KCL out of the supernode: (v_a − 3.3)/2.2 + v_b/10 + v_b/100 = 0.
  3. Substitute v_a = v_b + 1.25:
  4. \[\frac{v_b + 1.25 - 3.3}{2.2} + 0.11\,v_b = 0 \;\Rightarrow\; 0.4545\,v_b - 0.9318 + 0.11\,v_b = 0\]
  5. \[v_b = \frac{0.9318}{0.5645} = 1.651\ \text{V}, \qquad v_a = 2.901\ \text{V}\]

Answer: The ADC sees 1.65 V at node b and node a sits at 2.90 V. The current through the reference is the current in the 2.2 kΩ resistor, (3.3 − 2.90)/2.2 = 0.18 mA, which must lie inside the reference element's specified operating range for it to hold 1.25 V accurately.

Dependent sources

Circuits containing amplifiers and transistors are modeled with dependent sources. Nodal analysis handles them by writing the source as if it were independent, then adding an equation that expresses its controlling variable in terms of the node voltages. The resulting G matrix is no longer symmetric, but the method is unchanged. Lesson 7 uses this approach to analyze op-amp circuits with a finite gain.

Solving by computer

Two node equations are easy by hand, but a board with fifty signal nodes is not. Gaussian elimination reduces the system to triangular form by subtracting multiples of one row from the rows below it, then finds the unknowns by back substitution. It costs about n³/3 multiplications for n nodes, so a 50-node circuit needs around 40,000, trivial for a computer. Real simulators exploit the fact that the conductance matrix is sparse, most nodes connecting to only a few others, and solve circuits with millions of nodes. The code below builds the G matrix by stamping each resistor into it, the same idea SPICE uses, and solves the sensor network.

# A tiny nodal-analysis solver: stamp each element into G and i, then solve G v = i
def solve(A, b):
    """Gaussian elimination with partial pivoting."""
    n = len(b)
    M = [row[:] + [b[i]] for i, row in enumerate(A)]
    for col in range(n):
        piv = max(range(col, n), key=lambda r: abs(M[r][col]))
        M[col], M[piv] = M[piv], M[col]
        for r in range(col + 1, n):
            f = M[r][col] / M[col][col]
            for c in range(col, n + 1):
                M[r][c] -= f * M[col][c]
    x = [0.0] * n
    for r in range(n - 1, -1, -1):
        s = M[r][n] - sum(M[r][c] * x[c] for c in range(r + 1, n))
        x[r] = s / M[r][r]
    return x

def nodal(n_nodes, resistors, isources):
    """Nodes are numbered 1..n_nodes; node 0 is ground."""
    G = [[0.0] * n_nodes for _ in range(n_nodes)]
    i = [0.0] * n_nodes
    for a, b, R in resistors:
        g = 1.0 / R
        for p, q in ((a, b), (b, a)):
            if p:
                G[p - 1][p - 1] += g
                if q:
                    G[p - 1][q - 1] -= g
    for node, amps in isources:          # current injected into a node
        i[node - 1] += amps
    return solve(G, i)

def ntc(T_C, R25=10e3, beta=3950.0):   # illustrative thermistor model
    T = T_C + 273.15
    return R25 * 2.718281828 ** (beta * (1 / T - 1 / 298.15))

for T in (-30, 0, 25, 60):
    Rth = ntc(T)
    # the 3.3 V source with 10k becomes 0.33 mA into node 1 with 10k to ground
    v1, v2 = nodal(2, [(1, 0, 10e3), (1, 0, Rth), (1, 2, 4.7e3), (2, 0, 22e3), (2, 0, 100e3)],
                   [(1, 3.3 / 10e3)])
    print("%4d C  Rth = %7.0f ohm  v1 = %.3f V  ADC v2 = %.3f V" % (T, Rth, v1, v2))
Output
 -30 C  Rth =  200204 ohm  v1 = 2.215 V  ADC v2 = 1.757 V
   0 C  Rth =   33621 ohm  v1 = 1.899 V  ADC v2 = 1.507 V
  25 C  Rth =   10000 ohm  v1 = 1.353 V  ADC v2 = 1.073 V
  60 C  Rth =    2486 ohm  v1 = 0.604 V  ADC v2 = 0.479 V

The output shows the ADC voltage rising as the temperature falls, because a colder thermistor has more resistance and takes a larger share of the divider. Across the roadside range from −30 °C to 60 °C the ADC voltage spans about 1.3 V, from 0.48 V to 1.76 V. That is roughly 1,600 steps of a 12-bit converter, about 18 steps per degree on average, which is far finer than the thermistor's own accuracy. Firmware converts the reading back to temperature with a lookup table generated from the same model.

Checking an answer

Nodal analysis produces numbers that are easy to check. Substitute the node voltages back into each KCL equation and confirm the currents balance. Check that the power delivered by the sources equals the power absorbed by the resistors. Check limiting cases: if the thermistor's resistance went to zero, node 1 would be shorted to ground and both node voltages should go to zero; if it went to infinity, the network would become a simple chain of resistors that you can solve with the divider rule. A solver that passes these tests is very likely correct.

Common mistakes

  • MistakeMixing current directions from node to node.

    InsteadWrite every current as leaving the node, (v_this − v_other)/R, at every node.

  • MistakeTreating a floating voltage source like a resistor.

    InsteadForm a supernode, apply KCL to the boundary and add the source's voltage constraint.

  • MistakeForgetting an element connected to the reference node.

    InsteadInclude it as a conductance on the diagonal with a 0 V neighbor.

  • MistakeGetting the wrong sign on an off-diagonal entry.

    InsteadOff-diagonal entries are minus the conductance between the two nodes.

  • MistakeMixing units, such as kilohms in one term and ohms in another.

    InsteadChoose one unit system, such as volts, kilohms and milliamperes, and use it throughout.

Summary and key terms

  • Nodal analysis uses the node voltages, relative to a chosen reference, as unknowns.
  • At each node, KCL is written with currents leaving expressed as (v_j − v_k)/R, giving one linear equation per node.
  • For resistors and current sources the equations form G v = i, where G is symmetric and can be written by inspection.
  • Floating voltage sources are handled with supernodes; sources to the reference fix a node voltage.
  • Gaussian elimination solves the equations, and circuit simulators build them by stamping each element into the matrix.
Node voltage
The voltage of a node relative to the reference node.
Reference node
The node defined as 0 V, also called ground.
Conductance matrix
The matrix G in the nodal equations G v = i.
Supernode
A boundary around a voltage source and its two nodes, used to apply KCL without the source's unknown current.
Source transformation
Replacing a voltage source in series with a resistor by a current source in parallel with the same resistor.
Stamping
Adding an element's contribution to the matrix equations, as circuit simulators do.
NTC thermistor
A resistor whose resistance falls as its temperature rises.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. How many unknown node voltages does a circuit with 6 nodes have?

    Show answer

    5, one fewer than the number of nodes.

  2. Write G₁₁ for a node connected to ground through 1 kΩ, to node 2 through 2 kΩ and to node 3 through 4 kΩ.

    Show answer

    1 + 0.5 + 0.25 = 1.75 mS.

  3. In the sensor network, what happens to v₂ if the ADC's input resistance becomes infinite?

    Show answer

    It rises slightly, because the 100 kΩ load is removed from node 2.

  4. Why is the conductance matrix symmetric for a resistor network?

    Show answer

    The conductance between nodes j and k appears with the same value in row j and in row k.

  5. What extra equation does a supernode supply?

    Show answer

    The source's constraint, such as v_a − v_b = V_s.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz