Sub topic 9
Solving for the mesh currents
This chapter assumes you can already write the mesh equations and arrange them as a resistance matrix R and a source vector v. It also assumes you can solve two or three linear equations by hand. The task here is to solve R i = v for the mesh currents i and to check that the answer is believable.
The system you are solving
Take the two-mesh circuit from the previous chapter. Its resistances are R1 = 2 Ω, R2 = 4 Ω (shared) and R3 = 6 Ω. Its sources are V1 = 10 V and V2 = 5 V. Both mesh currents run clockwise, and V2 opposes mesh 2's current. The mesh equations are:
6 i1 - 4 i2 = 10
-4 i1 + 10 i2 = -5Solving by hand
For two meshes, substitution is quick. Solve the first equation for i1:
i1 = (10 + 4 i2) / 6Substitute into the second equation and multiply through by 6:
-4(10 + 4 i2) + 60 i2 = -30
44 i2 = 10
i2 = 0.2273 ABack-substitution then gives i1 = (10 + 0.909) / 6 = 1.818 A.
For three meshes, Cramer's rule or Gaussian elimination is more reliable. Cramer's rule says each unknown is a ratio of determinants. The denominator is det(R). The numerator is the determinant of R with that unknown's column replaced by v. For this circuit det(R) = 6·10 − 16 = 44, which matches the 44 above.
Solving with NumPy
import numpy as np
R = np.array([[6.0, -4.0],
[-4.0, 10.0]])
v = np.array([10.0, -5.0])
print(f"det(R) = {np.linalg.det(R):.1f}")
i = np.linalg.solve(R, v)
print(f"i1 = {i[0]:.4f} A, i2 = {i[1]:.4f} A")
# Residual check: R @ i should reproduce v.
print("residual:", R @ i - v)Use np.linalg.solve rather than computing np.linalg.inv(R) @ v. It is faster and more accurate, and it raises LinAlgError if R is singular.
Reading the result
The sign of a mesh current tells you its direction relative to the arrow you drew. A positive value means the current flows the way you drew it, and a negative value means it flows the opposite way. A negative result is not an error. Here both currents are positive, so both flow clockwise.
The mesh currents are not yet branch currents. The shared resistor R2 carries i1 − i2 = 1.591 A in mesh 1's direction. A later chapter covers this step.
Common errors
- Wrong sign in
Rorv. A symmetricRwith a positive diagonal is a good sign. IfRis not symmetric, or a diagonal entry is negative, recheck the equations. This holds when all meshes use the same direction and the circuit has no dependent sources. - Solving correctly from wrong equations. The solver cannot catch a mistake in the setup. Substituting back into the original circuit equations, not only into
R i = v, does catch it. - Rounding too early. Keep at least four significant digits until the final answer.
- A singular matrix.
det(R) = 0usually means two equations are duplicates or a mesh is missing. Recount the meshes.
Exercise
A two-mesh circuit gives the equations 3 i1 - i2 = 8 and -i1 + 3 i2 = 0. Solve for i1 and i2 using Cramer's rule, and check one equation by substitution.
Show answer
det(R) = 3·3 - (-1)(-1) = 8. i1 = (8·3 - (-1)·0)/8 = 3 A. i2 = (3·0 - (-1)·8)/8 = 1 A. Check the first equation: 3(3) - 1 = 8. ✓