Sub topic 7
Writing the Mesh Equations Step by Step
This chapter assumes you know Ohm's law, KVL, and how to solve two or three linear equations. It also assumes you can pick a mesh and give it a clockwise current, as covered in earlier chapters. Here you will turn a circuit into a set of mesh equations using one fixed procedure. The next chapter rearranges those equations into matrix form.
The goal: one KVL equation per mesh
A mesh is a loop with no other loop inside it. Each mesh gets one unknown, its mesh current. KVL around that mesh gives one equation. A planar circuit with m meshes therefore gives m equations in m unknowns.
Each equation has the same shape:
sum of resistor voltage drops = sum of source voltage rises
Both sums are taken while walking around the mesh in the direction of its mesh current. Ohm's law supplies each resistor drop. The only real work is getting the signs right, and the procedure below fixes them.
Step 1: Assign mesh currents
Draw a mesh current in every mesh. Use clockwise for all of them. This choice has a practical payoff. On a resistor shared by two adjacent meshes, the two clockwise currents point in opposite directions. That means every shared resistor produces a minus sign on the neighbor's current, and you never have to decide case by case.
Step 2: Sum the resistor drops
Pick a mesh. Walk around it in the direction of its current. For each resistor in the mesh:
- If the resistor belongs only to this mesh, the drop is R times the mesh current.
- If the resistor is shared with a neighbor, the current through it in your walking direction is your mesh current minus the neighbor's mesh current. The drop is R times (iown − ineighbor).
Because your own current flows in your walking direction, every resistor drop is positive with respect to your own current. The neighbor's contribution is what carries the minus sign.
Step 3: Sum the source rises
Walk around the same mesh in the same direction. For each voltage source, look at which terminal you reach first.
- If you enter at the − terminal and leave at the + terminal, the source is a rise. It adds a positive value to the right-hand side.
- If you enter at the + terminal and leave at the − terminal, the source is a drop in your walking direction. It adds a negative value to the right-hand side.
A source shared by two meshes appears in both equations. It can be a rise in one and a drop in the other.
Step 4: Write the equation
Set the drops from Step 2 equal to the rises from Step 3. Repeat for each mesh.
Worked example: two meshes
Take the circuit from the matrix-form code later in this tutorial. Mesh 1 contains a 10 V source, R1 = 2 Ω, and the shared resistor R2 = 4 Ω. Mesh 2 contains R2, R3 = 6 Ω, and a 5 V source. The 5 V source is oriented against clockwise current.
Mesh 1. The drops are R1·i1 and R2·(i1 − i2). The 10 V source is a rise.
2·i1 + 4·(i1 − i2) = 10
Mesh 2. The drops are R2·(i2 − i1) and R3·i2. Walking clockwise, you pass through the 5 V source from + to −, so it is a drop. Its rise is −5.
4·(i2 − i1) + 6·i2 = −5
Collect terms in each equation:
- Mesh 1: 6·i1 − 4·i2 = 10
- Mesh 2: −4·i1 + 10·i2 = −5
Notice the pattern in the coefficients. The coefficient of a mesh's own current is the sum of all resistances in that mesh. The coefficient of a neighbor's current is minus the resistance shared with that neighbor. The next chapter turns this pattern into a matrix, so watch for it.
Cramer's rule gives a quick check. The determinant is 6·10 − (−4)(−4) = 44, so i1 = (10·10 − (−4)(−5))/44 ≈ 1.818 A and i2 = (6·(−5) − (−4)·10)/44 ≈ 0.227 A.
Worked example: three meshes
Now apply the procedure to a chain of three meshes, left to right.
- Mesh 1: a 12 V source (rise), R1 = 1 Ω, and shared R2 = 2 Ω (with mesh 2).
- Mesh 2: shared R2, shared R3 = 3 Ω (with mesh 3), and R4 = 4 Ω.
- Mesh 3: shared R3, R5 = 5 Ω, and a 6 V source that is a drop for clockwise current.
Write the equations one at a time.
Mesh 1: 1·i1 + 2·(i1 − i2) = 12
Mesh 2: 2·(i2 − i1) + 3·(i2 − i3) + 4·i2 = 0
Mesh 3: 3·(i3 − i2) + 5·i3 = −6
Mesh 2 has no source, so its right-hand side is zero. Mesh 2 also touches two neighbors, so two subtraction terms appear. Simplified:
| Mesh | Equation |
|---|---|
| 1 | 3·i1 − 2·i2 = 12 |
| 2 | −2·i1 + 9·i2 − 3·i3 = 0 |
| 3 | −3·i2 + 8·i3 = −6 |
Check the pattern. The diagonal coefficients are 3 (1 + 2), 9 (2 + 3 + 4), and 8 (3 + 5). Meshes 1 and 3 do not share a resistor, so i3 is absent from equation 1 and i1 is absent from equation 3.
The following script solves the system. It also recomputes each KVL sum from the original element values, so you test the table against the circuit and not just the solver.
import numpy as np
R1, R2, R3, R4, R5 = 1.0, 2.0, 3.0, 4.0, 5.0
V1, V3 = 12.0, 6.0 # V1 is a rise in mesh 1; V3 is a drop in mesh 3
A = np.array([[3.0, -2.0, 0.0],
[-2.0, 9.0, -3.0],
[0.0, -3.0, 8.0]])
b = np.array([12.0, 0.0, -6.0])
i1, i2, i3 = np.linalg.solve(A, b)
print(f"i1 = {i1:.4f} A, i2 = {i2:.4f} A, i3 = {i3:.4f} A")
# Recompute each mesh's drops minus rises from the element values.
kvl1 = R1 * i1 + R2 * (i1 - i2) - V1
kvl2 = R2 * (i2 - i1) + R3 * (i2 - i3) + R4 * i2
kvl3 = R3 * (i3 - i2) + R5 * i3 + V3
print(f"KVL residuals: {kvl1:.2e}, {kvl2:.2e}, {kvl3:.2e}")The script prints i1 ≈ 4.5860 A, i2 ≈ 0.8790 A, and i3 ≈ −0.4204 A. The three residuals are zero up to rounding error. The negative sign on i3 means the real current in mesh 3 runs counterclockwise. That is not an error. It means the 6 V source opposes the current more strongly than the rest of mesh 3 drives it.
Common errors
| Symptom | Likely cause |
|---|---|
| A shared resistor's neighbor term has a plus sign | A neighbor current was drawn counterclockwise, or the subtraction was skipped |
| Diagonal coefficient is too small | A resistor in the mesh was left out of the sum |
| Answers are too big or too small by the source value | A source was added with the wrong sign |
| Equation for mesh k contains a mesh that does not touch k | A resistor was assigned to the wrong mesh |
| Equations are not independent | The same loop was written twice, or a loop that is not a mesh was used |
Quick checks before solving
Run through these checks on the finished equations. They catch most mistakes before any algebra.
- Count the equations. You should have exactly one per mesh.
- Check that every diagonal coefficient is positive and equals the total resistance around its mesh.
- Check that every off-diagonal coefficient is negative, or zero for meshes that share no resistor.
- Check symmetry. The coefficient of i2 in equation 1 should equal the coefficient of i1 in equation 2. This holds for circuits with resistors and independent sources only. It fails once dependent sources are added.
- Re-walk each mesh once more. Confirm each source sign using the direction of the current.
Exercise
A mesh circuit has two meshes with clockwise currents i1 and i2. Mesh 1 contains a 9 V source (a rise for clockwise current), R1 = 3 Ω, and a shared R2 = 6 Ω. Mesh 2 contains R2, R3 = 2 Ω, and a 4 V source that is a rise for clockwise current. Write both mesh equations in simplified form. Then solve for i1 and i2.
Show answer
Mesh 1: 3·i1 + 6·(i1 − i2) = 9, which simplifies to 9·i1 − 6·i2 = 9. Mesh 2: 6·(i2 − i1) + 2·i2 = 4, which simplifies to −6·i1 + 8·i2 = 4. The determinant is 9·8 − 36 = 36. Then i1 = (9·8 − (−6)(4))/36 = 96/36 ≈ 2.667 A, and i2 = (9·4 − (−6)(9))/36 = 90/36 = 2.5 A.
Exercise
In a three-mesh chain, meshes 1 and 3 share no resistor. Which entries of the coefficient pattern are zero, and why?
Show answer
The coefficient of i3 in the mesh 1 equation and the coefficient of i1 in the mesh 3 equation are both zero. An off-diagonal coefficient is minus the resistance shared by two meshes. Meshes 1 and 3 share none, so those terms never appear.