Consider the following linear system of equations in
`x`, `y`, and `z`:

a*x + b*y + c*z = d e*x + f*y + g*z = h p*x + q*y + r*z = s

In order to solve this system in Matlab, we take the coefficients and write them as a matrix and a vector:

>> A = [a b c; e f g; p q r] % This doesn't work, just a demonstration A = a b c d e f p q r >> v = [d h s]' % This doesn't work, just a demonstration v = d h s

The left divide operator `A\b` returns a column vector,
the entries of which are the solutions for the variables `x`,
`y`, and `z`, respectively.

As an example, consider a circuit with an 12 volt battery and three resistors with resistence 7.5 milliohms, 31.2 milliohms, and 95.3 microohms, respectively. Using Cherkoff's law, we may write the three equations:

12 - 7.5e-3*i(1) = 0 7.5e-3*i(1) - 31.2e-3*i(2) = 0 31.2e-3*i(2) - 95.3e-6*i(3) = 0

Expanding these out, we may write:

7.5e-3*i(1) = 12 7.5e-3*i(1) - 31.2e-3*i(2) = 0 31.2e-3*i(2) - 95.3e-6*i(3) = 0

or, converting these into matrix notation:

[ 7.5e-3 0 0 ] [ i(1) ] [ 12 ] [ 7.5e-3 -31.2e-3 0 ] [ i(2) ] = [ 0 ] [ 0 31.2e-3 -95.3e-6 ] [ i(3) ] [ 0 ]

In Matlab, we now enter:

>> A = [7.5e-3 0 0; 7.5e-3 -31.2e-3 0; 0 31.2e-3 -95.3e-6] A = 0.0075 0 0 0.0075 -0.0312 0 0 0.0312 -0.0001 >> v = [12 0 0]' v = 12 0 0 >> A\v ans = 1.0e+05 * 0.0160 0.0038 1.2592

Therefore we find that the three currents are:

i(1) = 1.6 kA i(2) = 380. A i(3) = 125.92 kA

Checking our answer, we not that the highest current is flowing through the resistor with the least resistence, and the least amount of current is flowing through the resistor with the most resistence.