---
title: Mesh analysis and loop matrices
heading: Solving a circuit with loop currents
eyebrow: A7 · Lesson 20 · Mesh analysis
xp: 40
---

::: hook
Nodal analysis picks node voltages as the unknowns, one for every node except ground. Lesson 19 found a second set of unknowns hiding in the same circuit: the left null space of the incidence matrix, whose vectors are currents that circulate around loops and automatically satisfy KCL. Choose one current per independent loop, write KVL around each, and you get **mesh analysis**: a different square system for the same circuit, often a smaller one.
:::

::: play
- A 10 V source drives two meshes that share the resistor $R_2$. The meters read the current in $R_1$ (mesh 1's current), in $R_3$ (mesh 2's current) and in $R_2$ (their difference).
- Make $R_2$ small. It shorts mesh 2 out, and almost nothing flows in $R_3$.
- Make $R_2$ large. Mesh 1's current now has to flow through mesh 2's resistors, and the two mesh currents approach each other.
:::

```sim circuit
V1 in 0 10          @ 0,0 down
R1 in a 1k          @ 0,0 right
R2 a 0 2k           @ 2,0 down
R3 a b 1k           @ 2,0 right
R4 b 0 1k           @ 4,0 down
slider: R2 100..10k log
scope: v(a), v(b)
time: 0..1m s
meter: i(R1), i(R2), i(R3)
```

::: predict
## The shared resistor $R_2$ rises from 100 Ω to 10 kΩ. What happens to mesh 2's current, the current in $R_3$?

- [x] It rises toward $\frac{10}{1 + 1 + 1}$ mA, as if $R_2$ weren't there
- [ ] It falls toward zero
- [ ] It stays at 2.5 mA
- [ ] It rises without limit

::: reveal
It rises. A small $R_2$ is nearly a short across mesh 2, so mesh 2's current is small. As $R_2$ grows, less current can take the shortcut, and in the limit all of the source's current goes round through $R_1$, $R_3$ and $R_4$: $\frac{10\text{ V}}{3\text{ kΩ}} = 3.33$ mA. With $R_2$ = 2 kΩ it's 2.5 mA, in between.
:::
:::

::: nameit
## Mesh currents

In a planar circuit, each **mesh** (a loop with no other loop inside it) gets a current $i_k$, all drawn clockwise. A branch on the boundary of one mesh carries that mesh's current; a branch shared by two meshes carries their difference. KCL is then satisfied automatically, so only KVL is left: one equation per mesh.

## The mesh matrix

KVL around mesh $k$ gives $R\mathbf{i} = \mathbf{v}$, where:
- $R_{kk}$ is the total resistance around mesh $k$;
- $R_{jk} = -(\text{resistance shared by meshes } j \text{ and } k)$;
- $v_k$ is the sum of source voltages around mesh $k$, counted positive when they push current clockwise.

It's the mirror image of nodal analysis's $G$: symmetric, positive on the diagonal, negative off it.

## The loop matrix

Collect the branches each mesh runs through in a **loop matrix** $B$, one row per mesh, with $+1$ where a branch points along the mesh direction and $-1$ where it points against. Branch currents are $B^T\mathbf{i}$, and KVL around every mesh is $B\mathbf{v}_b = \mathbf 0$. With branch resistances on the diagonal of $R_b$:

$$R = BR_bB^T$$

the same pattern as $G = A^TCA$. The rows of $B$ span the left null space of the incidence matrix, which is why there are $b - n + 1$ of them.

## Which to use

Nodal analysis has $n - 1$ unknowns and mesh analysis has $b - n + 1$. Pick the smaller. Current sources favor nodal analysis and voltage sources favor mesh analysis, because each fixes one unknown directly. Circuit simulators use modified nodal analysis, which works for any circuit, planar or not.
:::

::: example
## Find the mesh currents in the circuit above with $R_2$ = 2 kΩ.

::: solution
1. **Mesh 1.** In kilohms, milliamps and volts, mesh 1 runs through $R_1$ and $R_2$, total 3.
2. **Mesh 2.** It runs through $R_2$, $R_3$ and $R_4$, total 4, and shares $R_2$ = 2 with mesh 1.
3. **The mesh equations.** The source pushes mesh 1 clockwise:
   $$\begin{bmatrix}3 & -2\\-2 & 4\end{bmatrix}\begin{bmatrix}i_1\\i_2\end{bmatrix} = \begin{bmatrix}10\\0\end{bmatrix}$$
4. **Solve.** The determinant is $12 - 4 = 8$, so
   $$\begin{aligned} i_1 &= \frac{40}{8} \\ &= 5\ \text{mA} \\ i_2 &= \frac{20}{8} \\ &= 2.5\ \text{mA} \end{aligned}$$
   and $R_2$ carries $i_1 - i_2$ = 2.5 mA.
5. **Check by nodal analysis.** Node a sits at $10 - 5 \times 1$ = 5 V, and $5/2$ = 2.5 mA flows down $R_2$.

**Answer:** $i_1$ = 5 mA and $i_2$ = 2.5 mA, so 2.5 mA flows in $R_2$.
:::
:::

::: example
## Build the mesh matrix of that circuit from its loop matrix.

::: solution
1. **Orient the branches.** Take them in the order $R_1$, $R_2$, $R_3$, $R_4$, with $R_1$ pointing toward node a, $R_2$ and $R_4$ pointing down and $R_3$ pointing right.
2. **Write the loop matrix.** Mesh 1 runs along $R_1$ and down $R_2$; mesh 2 runs up $R_2$, along $R_3$ and down $R_4$:
   $$B = \begin{bmatrix}1 & 1 & 0 & 0\\0 & -1 & 1 & 1\end{bmatrix}$$
   $$R_b = \text{diag}(1, 2, 1, 1)$$
3. **Multiply.**
   $$\begin{aligned} BR_bB^T &= \begin{bmatrix}1 + 2 & -2\\-2 & 2 + 1 + 1\end{bmatrix} \\ &= \begin{bmatrix}3 & -2\\-2 & 4\end{bmatrix} \end{aligned}$$
   the matrix written down by inspection.
4. **Branch currents.**
   $$B^T\mathbf{i} = (5, 2.5, 2.5, 2.5)\ \text{mA}$$

**Answer:** $BR_bB^T = \begin{bmatrix}3 & -2\\-2 & 4\end{bmatrix}$, the same mesh matrix as by inspection.
:::
:::

::: example
## A circuit has 6 nodes and 9 branches, with three voltage sources. Which method gives fewer unknowns?

::: solution
1. **Nodal unknowns.** Nodal analysis needs $6 - 1 = 5$ node voltages.
2. **Mesh unknowns.** Mesh analysis needs $9 - 6 + 1 = 4$ mesh currents, so it wins by one.
3. **Current sources.** If a mesh's outside branch is a current source, that mesh's current is simply the source's value, so the system shrinks again.
4. **Voltage sources.** They do the same for nodal analysis: a source from a node to ground fixes that node's voltage.

**Answer:** mesh analysis, with 4 unknowns to nodal analysis's 5.
:::
:::

::: check
given: R1 = 1 | 2; R2 = 1 | 3; R3 = 2 | 4; V = 5 | 12
answer: V*(R2 + R3)/((R1 + R2)*(R2 + R3) - R2^2)
unit: mA
tolerance: 0.5%

## A {V} V source drives mesh 1 through $R_1$ = {R1} kΩ; $R_2$ = {R2} kΩ is shared with mesh 2, which also has $R_3$ = {R3} kΩ. What is mesh 1's current?

::: right
Right. $i_1 = \frac{V(R_2 + R_3)}{(R_1 + R_2)(R_2 + R_3) - R_2^2}$ = {answer}.
:::

::: misses
- [V/(R1 + R2)] That ignores mesh 2, which draws current through $R_2$ too.
- [V/R1] The other resistors matter.
- [any] Not yet. Solve $\begin{bmatrix}R_1 + R_2 & -R_2\\-R_2 & R_2 + R_3\end{bmatrix}\mathbf{i} = (V, 0)$.
:::
:::

::: check
given: R1 = 1 | 2; R2 = 1 | 3; R3 = 2 | 4; V = 5 | 12
answer: V*R2/((R1 + R2)*(R2 + R3) - R2^2)
unit: mA
tolerance: 0.5%

## In the same circuit, what is mesh 2's current?

::: right
Right. $i_2 = \frac{VR_2}{(R_1 + R_2)(R_2 + R_3) - R_2^2}$ = {answer}.
:::

::: misses
- [V/(R1 + R2 + R3)] Mesh 2 isn't simply in series with the source: $R_2$ offers a parallel path.
- [any] Not yet. Use Cramer's rule, or row 2: $i_2 = \frac{R_2}{R_2 + R_3}i_1$.
:::
:::

::: check
given: n = 5 | 7 | 10; b = 13 | 16
answer: b - n + 1
tolerance: 0

## A planar circuit has {n} nodes and {b} branches. How many mesh currents does mesh analysis need?

::: right
Right. $b - n + 1$ = {answer}.
:::

::: misses
- [n - 1] That's how many node voltages nodal analysis needs.
- [b - n] One more: the incidence matrix has rank $n - 1$.
- [any] Not yet. Branches minus the rank of the incidence matrix.
:::
:::

::: check
given: a = 1 | 2.2; c = 3.3 | 4.7; s = 1 | 1.5
answer: -c
unit: kΩ
tolerance: 0.5%

## Mesh 1 contains {a} kΩ and {c} kΩ; the {c} kΩ resistor is shared with mesh 2, which also has {s} kΩ. What is the off-diagonal entry $R_{12}$ of the mesh matrix?

::: right
Right. $-${c} kΩ: minus the shared resistance.
:::

::: misses
- [c] The shared branch carries the two mesh currents in opposite directions, so it enters with a minus sign.
- [a + c] That's the diagonal entry $R_{11}$.
- [any] Not yet. Off-diagonal entries are minus the resistance two meshes share.
:::
:::

::: check
kind: parts
given: I = 1 | 2 | 5; R = 1 | 2

## A current source of {I} mA forms the outside branch of mesh 2, pointing clockwise. Mesh 1 has a 10 V source, 1 kΩ of its own, and {R} kΩ shared with mesh 2.

::: part
answer: I
unit: mA
tolerance: 0.5%

### What is mesh 2's current?

::: misses
- [any] The current source alone sets it.
:::
:::

::: part
answer: (10 + R*I)/(1 + R)
unit: mA
tolerance: 0.5%

### What is mesh 1's current?

::: misses
- [10/(1 + R)] Mesh 2's current flows through the shared resistor too, adding $R i_2$ to mesh 1's equation.
- [any] KVL around mesh 1: $(1 + R)i_1 - Ri_2 = 10$.
:::
:::
:::

::: check
kind: derivation
vars: a = 1..5, b = 1..5, r = 0.5..3

## Two meshes have totals $a$ and $b$ around them and share $r$. A 1 V source drives mesh 1.

::: step
answer: a*b - r^2

### What is the determinant of the mesh matrix?
:::

::: step
answer: b/(a*b - r^2)

### What is $i_1$?
:::

::: step
answer: r/(a*b - r^2)

### What is $i_2$?
:::

::: right
Right. The shared resistance couples the meshes; with $r = 0$ they separate into $i_1 = 1/a$ and $i_2 = 0$.
:::
:::

::: explain
## A circuit has several voltage sources and only a few loops, but many nodes. Why does mesh analysis suit it, and why do simulators still use nodal analysis?

::: model
Mesh analysis has one unknown per independent loop, $b - n + 1$, against nodal analysis's $n - 1$, so a circuit with many nodes and few loops (a long chain of series parts, say) gives a smaller system. Voltage sources sit naturally in KVL equations, adding a known term to a mesh's right side, while in nodal analysis each floating voltage source needs special handling. Simulators use modified nodal analysis anyway, because meshes are only defined for planar circuits (ones you can draw without crossings), while every circuit has nodes, and because building $G$ from a netlist part by part is simpler than finding meshes.
:::
:::

::: practice

::: check
given: R1 = 0.5..5; R2 = 0.5..5; R3 = 0.5..5; V = 1..20
answer: V*(R2 + R3)/((R1 + R2)*(R2 + R3) - R2^2)
unit: mA
tolerance: 0.5%

## Two meshes: {V} V, $R_1$ = {R1} kΩ, shared $R_2$ = {R2} kΩ, $R_3$ = {R3} kΩ. Mesh 1's current, in mA?

::: misses
- [any] $\frac{V(R_2 + R_3)}{(R_1 + R_2)(R_2 + R_3) - R_2^2}$.
:::
:::

::: check
given: n = 3..30 int; b = 31..60 int
answer: b - n + 1
tolerance: 0

## Mesh currents for {n} nodes and {b} branches?

::: misses
- [any] $b - n + 1$.
:::
:::
:::
