Sub topic 8
Matrix form: the resistance matrix and source vector
This chapter assumes you can write a KVL equation around a mesh, apply Ohm's law, and solve a small linear system. Here you turn the mesh equations into the matrix equation R i = v, which you can solve by hand or with software.
Why use matrix form
Each mesh gives one KVL equation, so a circuit with N meshes gives N equations in N unknown mesh currents. Written out, the equations follow a pattern. Matrix form captures that pattern, so you can fill in the coefficients by inspection instead of deriving each equation.
The matrix equation is:
- R is the resistance matrix (N by N).
- i is the vector of mesh currents.
- v is the source vector (N entries).
Building the matrix by inspection
Assume every mesh current runs clockwise. Then these rules apply:
- Diagonal entry R[k][k] is the sum of all resistances in mesh k. It is always positive.
- Off-diagonal entry R[j][k] is minus the sum of the resistances shared by meshes j and k. It is negative because clockwise currents run in opposite directions through a shared branch.
- Source entry v[k] is the sum of the voltage rises in mesh k, taken in the direction of its mesh current. A source whose positive terminal is met first when travelling with the current counts as a rise only if you enter at the negative terminal. Otherwise it counts as negative.
- If there are no shared resistors between two meshes, the off-diagonal entry is zero.
With only resistors and independent voltage sources, R is symmetric: R[j][k] = R[k][j].
Worked example
Take a two-mesh circuit with both currents clockwise:
- Mesh 1: V1 = 10 V (a rise), R1 = 2 Ω, and shared R2 = 4 Ω.
- Mesh 2: shared R2 = 4 Ω, R3 = 6 Ω, and V2 = 5 V opposing the clockwise current.
The entries are:
| Entry | Value | Reason |
|---|---|---|
| R[1][1] | 2 + 4 = 6 Ω | R1 and R2 are in mesh 1 |
| R[2][2] | 4 + 6 = 10 Ω | R2 and R3 are in mesh 2 |
| R[1][2] = R[2][1] | -4 Ω | R2 is shared |
| v[1] | +10 V | V1 is a rise |
| v[2] | -5 V | V2 opposes the current |
The equation is:
[ 6 -4 ] [i1] [ 10 ]
[ -4 10 ] [i2] = [ -5 ]Solving it in code
import numpy as np
# Two-mesh circuit, both mesh currents clockwise.
# Mesh 1: V1 = 10 V, R1 = 2 ohm, shared R2 = 4 ohm
# Mesh 2: shared R2 = 4 ohm, R3 = 6 ohm, V2 = 5 V opposing clockwise current
R1, R2, R3 = 2.0, 4.0, 6.0
V1, V2 = 10.0, 5.0
# Resistance matrix: diagonal = sum of resistances in the mesh,
# off-diagonal = minus the resistance shared by the two meshes.
R = np.array([[R1 + R2, -R2],
[-R2, R2 + R3]])
# Source vector: sum of voltage rises in the direction of each mesh current.
v = np.array([V1, -V2])
i1, i2 = np.linalg.solve(R, v)
print(f"i1 = {i1:.4f} A, i2 = {i2:.4f} A")
print(f"Current through R2 (mesh 1 direction) = {i1 - i2:.4f} A")
# Power balance: power absorbed by resistors equals power delivered by sources.
p_resistors = R1 * i1**2 + R2 * (i1 - i2)**2 + R3 * i2**2
p_sources = V1 * i1 - V2 * i2
print(f"P_resistors = {p_resistors:.4f} W, P_sources = {p_sources:.4f} W")The solution is i1 ≈ 1.818 A and i2 ≈ 0.227 A. The current through R2 in the mesh 1 direction is i1 - i2 ≈ 1.591 A. The two power totals match, which confirms the result.
Common errors
- Wrong sign on an off-diagonal entry. With all meshes clockwise, off-diagonal entries are negative. If you mix directions, the signs change, so keep one direction.
- Source sign reversed. Check each source against the direction of its mesh current, not against the diagram's top or bottom.
- Forgetting the shared resistor on the diagonal. A shared resistor appears in both diagonal entries and, with a minus sign, in the off-diagonal entries.
- Asymmetric R. If your matrix is not symmetric in a circuit with only resistors and independent voltage sources, recheck it.
Exercise
A two-mesh circuit has both currents clockwise. Mesh 1 contains R1 = 3 Ω, a shared R2 = 5 Ω, and a 12 V source that is a rise in the direction of i1. Mesh 2 contains the shared R2 and R3 = 7 Ω, with no source. Write R and v.
Show answer
R = [[3 + 5, -5], [-5, 5 + 7]] = [[8, -5], [-5, 12]] Ω, and v = [12, 0] V.