Member-only story
Solving a System of Linear Equations with Python and Matrices

This is part of a series that I like to call “things that I will forget if I don’t write it down”. It’s how to solve a system of linear equations with Python and matrices. Yes, it’s true that there are multiple ways to solve a system of equations — but using this way is useful for some other things (solving differential equations).
A Circuit Problem
I don’t really care about DC circuits right now, I just need a good example of a system of linear equations. Let’s analyze the complicated circuit from the picture above. Of course, we are going to use two very fundamental ideas:
- The loop rule. This says that the change in electric potential around a closed loop in a circuit is equal to zero. With this, the voltage across a battery is just the battery voltage. The voltage drop across a resistor if you going in the same direction as the electric current is -IR (where I is the current and R is the resistance).
- The junction rule. When there is a junction of 2 or more wires, the total current INTO the junction is equal to the total current OUT of the junction. You can write this as I-in = I-out.
See, circuits aren’t so complicated. It’s just two rules. OK, I admit that things can get much more complicated with AC voltage sources and…