# Cramer's rule

Cramer's rule is an elegant formula for the solutions of a system of linear equations. A typical linear system (also known as a set of "simultaneous linear equations") is a set of N linear equations in N variables (or "unknowns".)

For N=3, it might look like this:

$Ax+By+Cz=P\,$ $Dx+Ey+Fz=Q\,$ $Gx+Hy+Iz=R\,$ The numbers A...I (the "coefficient matrix") are given, as are the numbers P, Q, R (the "right-hand-sides".) The values of x, y, z (the "unknowns") are to be found. A system of N linear equations in N unknowns has a uniquely determined solution except in unusual circumstances (the coefficient matrix having determinant zero, as will be shown below.)

If the number of equations were greater than the number of unknowns, there would be no solutions except in unusual circumstances. If the number of equations were less than the number of unknowns, there would be infinitely many solutions. Neither of those cases is covered by Cramer's rule.

Cramer's rule gives the solution in terms of the determinants of the coefficient matrix and the coefficient matrix with individual columns replaced. It says that the value of the nth unknown is the quotient of the determinant of the coefficient matrix with its nth column replaced by the right-hand-side numbers, divided by the determinant of the unmodified coefficient matrix.

For the 3-equation example given above:

$x={\frac {\begin{vmatrix}\color {Red}P&B&C\\\color {Red}Q&E&F\\\color {Red}R&H&I\end{vmatrix}}{\begin{vmatrix}A&B&C\\D&E&F\\G&H&I\end{vmatrix}}}\ \ \ \ y={\frac {\begin{vmatrix}A&\color {Red}P&C\\D&\color {Red}Q&F\\G&\color {Red}R&I\end{vmatrix}}{\begin{vmatrix}A&B&C\\D&E&F\\G&H&I\end{vmatrix}}}\ \ \ \ z={\frac {\begin{vmatrix}A&B&\color {Red}P\\D&E&\color {Red}Q\\G&H&\color {Red}R\end{vmatrix}}{\begin{vmatrix}A&B&C\\D&E&F\\G&H&I\end{vmatrix}}}$ This works for any number of equations.

It can be seen that this will fail if the determinant of the coefficient matrix is zero, that is, the matrix is singular.

While Cramer's rule is certainly an elegant expression of the solution, it is not necessarily a useful way to solve a system of linear equations by hand where the number of equations is greater than about 3. This is because pencil-and-paper evaluation of determinants is a tedious and error-prone process. Computer programs to solve linear systems could use Cramer's rule, but they typically use Gaussian elimination, which is the computer equivalent of the "multiply by a constant and subtract" method that is taught in algebra classes.