Cramer's method


Cramer's rule is an explicit formula for the solution of a system of linear equations with as many equations as unknowns, valid whenever the system has a unique solution. It expresses the solution in terms of the determinants of the (square) coefficient matrix and of matrices obtained from it by replacing one column by the vector of right hand sides of the equations.
General case:
 x_i = \frac{\det(A_i)}{\det(A)} \qquad i = 1, \ldots, n \,

For a system with 2 equations:

If ad-bc\ne0, the system

\left\{\begin{matrix}
ax+by = e\\
cx+dy = f\end{matrix}\right.

has a unique solution :

x = { \begin{vmatrix}e&b\\f&d\end{vmatrix} \over \begin{vmatrix}a&b\\c&d\end{vmatrix} } = { ed - bf \over ad - bc},\quad y = { \begin{vmatrix}a&e\\c&f\end{vmatrix} \over \begin{vmatrix}a&b\\c&d\end{vmatrix} } =  { af - ec \over ad - bc}.


For a system with 3 equations:
\left\{\begin{matrix}a_1x_1 + b_1x_2 + c_1x_3 = d_1\\
a_2x_1 + b_2x_2 + c_2x_3 = d_2\\
a_3x_1 + b_3x_2 + c_3x_3 = d_3\end{matrix}\right.


A = \begin{pmatrix}a_1&b_1&c_1\\a_2&b_2&c_2\\a_3&b_3&c_3\end{pmatrix},\quad X= \begin{pmatrix}x_1\\x_2\\x_3\end{pmatrix}\quad\text{et}\quad
\Lambda = \begin{pmatrix} 
d_1\\ 
d_2\\ 
d_3
\end{pmatrix}.

The system has a unique solution if \det(A) \ne 0 :

x_1 = \frac{\det(A_1)}{\det(A)} = \frac{\begin{vmatrix}d_1&b_1&c_1\\d_2&b_2&c_2\\d_3&b_3&c_3\end{vmatrix}}{\det(A)}
x_2 = \frac{\det(A_2)}{\det(A)} = \frac{\begin{vmatrix}a_1&d_1&c_1\\a_2&d_2&c_2\\a_3&d_3&c_3\end{vmatrix}}{\det(A)}
x_3 = \frac{\det(A_3)}{\det(A)} = \frac{\begin{vmatrix}a_1&b_1&d_1\\a_2&b_2&d_2\\a_3&b_3&d_3\end{vmatrix}}{\det(A)}

Another way to present it: 

X=\begin{pmatrix}x_1\\x_2\\x_3\end{pmatrix} = \frac1{\det(A)} \cdot \begin{pmatrix}
\det(A_1)\\
\det(A_2)\\
\det(A_3)\end{pmatrix}.


Reminder about the determinant of a matrix

For 
A_{i,j}=\begin{pmatrix}a_{1,1} & \dots & a_{1,j-1}& a_{1,j+1}& \dots & a_{1,n} \\\vdots & & \vdots &  \vdots& &\vdots\\
a_{i-1,1} & \dots & a_{i-1,j-1}& a_{i-1,j+1}& \dots & a_{i-1,n} \\
a_{i+1,1} & \dots & a_{i+1,j-1}& a_{i+1,j+1}& \dots & a_{i+1,n} \\
\vdots & & \vdots & \vdots &&\vdots\\
a_{n,1} & \dots & a_{n,j-1}& a_{n,j+1}& \dots & a_{n,n}\end{pmatrix}

the determinant can be calculate with this formula

\det(A)=\sum_{j=1}^{n} a_{i;j} (-1)^{i+j}\det(A_{i,j})