10 Cramer's Method

Gabriel Cramer was a Swiss mathematician who lived in the first half of the 18th century. In 1750 he published his method for solving sets of linear equations which is in common use today.

If we have two simultaneous equations $a_1x+b_1y=c_1$ and $a_2x+b_2y=c_2$ we could write them in matrix form like this

$\begin{bmatrix}a_1 & b_1 \\[0.3em]a_2 & b_2\end{bmatrix} \begin{bmatrix}x \\[0.3em] y \end{bmatrix}$ $=$ $\begin{bmatrix} c_1 \\[0.3em] c_2 \end{bmatrix}$
or $AX$$=$$C$

The determinant of the matrix of coefficients is given by
$det(A)$ or $|A|=a_1b_2-a_2b_1$


$|A|=a_1b_2-a_2b_1$

Using Cramer's method we can write

$x$$=$$\frac{\begin{vmatrix} c_1 & b_1 \\[0.3em] c_2 & b_2 \end{vmatrix}}{\begin{vmatrix} a_1 & b_1 \\[0.3em] a_2 & b_2 \end{vmatrix}}$
and $y$$=$$\frac{\begin{vmatrix} a_1 & c_1 \\[0.3em] a_2 & c_2 \end{vmatrix}}{\begin{vmatrix} a_1 & b_1 \\[0.3em] a_2 & b_2 \end{vmatrix}}$

Example 10.1: Solve the following simultaneous equations using Cramer's method.
$-5x+y=13$
$2x+4y=8$

The matrix form of the equation looks like this:

$\begin{vmatrix}-5 & 1 \\[0.3em]2 & 4\end{vmatrix} \begin{vmatrix}x \\[0.3em]y \end{vmatrix}= \begin{vmatrix}13 \\[0.3em]8 \end{vmatrix}$

so we can write

$x=\frac{\begin{vmatrix}13 &1 \\[0.3em]8 & 4\end{vmatrix}}{ \begin{vmatrix}-5 &1 \\[0.3em]2 & 4\end{vmatrix}}= \frac{13 \times 4 - 1 \times 8}{-5 \times 4 - 1 \times 2}= \frac{44}{-22}=-2$

$y=\frac{\begin{vmatrix}-5 &13 \\[0.3em]2 & 8\end{vmatrix}}{ \begin{vmatrix}-5 &1 \\[0.3em]2 & 4\end{vmatrix}}= \frac{-5 \times 8 - 13 \times 2}{-5 \times 4 - 1 \times 2}= \frac{-66}{-22}=3$

so $x=-2$ and $y=3$


Sanity Check
Put $x=-1$ and $y=3$ into one of the original equations.

If we use the first equation we get $-5 \times(-2)+3 = 10 + 3 = 13$
so our answers are probably right

We can extend Cramer's method to three dimensions by adding a third variable. If we have the following equations $a_1x+b_1y+c_1z=d_1$, $a_2x+b_2y+c_2z=d_2$ and $a_3x+b_3y+c_3z=d_2$ we could write them in matrix form like this

$\begin{bmatrix} a_1 & b_1 & c_1 \\[0.3em] a_2 & b_2 & c_2 \\[0.3em] a_3 & b_3 & c_3 \end{bmatrix} \begin{bmatrix} x \\[0.3em] y \\[0.3em] z \end{bmatrix}= \begin{bmatrix} d_1 \\[0.3em] d_2 \\[0.3em] d_3 \end{bmatrix}$

$AX=D$

The determinant of the matrix of coefficients is given by $det(A)=a_1(b_2 c_3-c_2b_3)-b_1(a_2c_3-c_2b_3)+c1(a_2b_3-b_2a_3)$

Using Cramer's method we can write

$x=\frac{\begin{vmatrix} d_1 & b_1 & c_1 \\[0.3em] d_2 & b_2 & c_2 \\[0.3em] d_3 & b_3 & c_3 \end{vmatrix}}{\begin{vmatrix} a_1 & b_1 & c_1 \\[0.3em] a_2 & b_2 & c_2 \\[0.3em] a_3 & b_3 & c_3 \end{vmatrix}}$, $y=\frac{\begin{vmatrix} a_1 & d_1 & c_1 \\[0.3em] a_2 & d_2 & c_2 \\[0.3em] a_3 & d_3 & c_3 \end{vmatrix}}{\begin{vmatrix} a_1 & b_1 & c_1 \\[0.3em] a_2 & b_2 & c_2 \\[0.3em] a_3 & b_3 & c_3 \end{vmatrix}}$ and $z=\frac{\begin{vmatrix} a_1 & b_1 & d_1 \\[0.3em] a_2 & b_2 & d_2 \\[0.3em] a_3 & b_3 & d_3 \end{vmatrix}}{\begin{vmatrix} a_1 & b_1 & c_1 \\[0.3em] a_2 & b_2 & c_2 \\[0.3em] a_3 & b_3 & c_3 \end{vmatrix}}$



Example 10.2: Solve the following simultaneous equations using Cramer's method.
$5x-4y-z=19$
$-3x+5y+5z=1$
$5x+y+3z=25$

The matrix form of the equation looks like this:

$\begin{bmatrix} 5 & -4 & -1 \\[0.3em] -3 & 5 & 5 \\[0.3em] 5 & 1 & 3\end{bmatrix} \begin{bmatrix}x \\[0.3em]y \\[0.3em]z \end{bmatrix}= \begin{bmatrix}19 \\[0.3em]1 \\[0.3em]25 \end{bmatrix}$

so we can write

$x=\frac{\begin{vmatrix}19 & -4 & -1 \\[0.3em] 1 & 5 & 5 \\[0.3em] 25 & 1 & 3\end{vmatrix}}{ \begin{vmatrix}5 & -4 & -1 \\[0.3em] -3 & 5 & 5 \\[0.3em] 5 & 1 & 3\end{vmatrix}} =\frac{-174}{-58}=3$

$y=\frac{\begin{vmatrix}5 & 19 & -1 \\[0.3em] -3 & 1 & 5 \\[0.3em] 5 & 25 & 3\end{vmatrix}}{ \begin{vmatrix}5 & -4 & -1 \\[0.3em] -3 & 5 & 5 \\[0.3em] 5 & 1 & 3\end{vmatrix}} =\frac{116}{-58}=-2$

$z=\frac{\begin{vmatrix}5 & -4 & 19 \\[0.3em] -3 & 5 & 1 \\[0.3em] 5 & 1 & 25\end{vmatrix}}{ \begin{vmatrix}5 & -4 & -1 \\[0.3em] -3 & 5 & 5 \\[0.3em] 5 & 1 & 3\end{vmatrix}} =\frac{-232}{-58}=4$

so $x=3$, $y=-2$ and $z=4$

http://ludumdare.com/compo/ludum-dare-35/?action=preview&uid=3671