1.3 Solving systems of linear equations: Cramer's rule and matrix inversion
Consider a system of two equations in two variables
x_{1} and
x_{2}:
ax_{1} + bx_{2} 
= u 
cx_{1} + dx_{2} 
= v. 
One straightforward way to solve for
x_{1} and
x_{2} is to isolate one of the variables in one of the equations and substitute the result into the other equation. For example, from the second equation we have
x_{2} = (v − cx_{1})/d.
Substituting this expression for
x_{2} into the first equation yields
ax_{1} + b(v − cx_{1})/d = u,
which we can write as
(a − bc/d)x_{1} + bv/d = u,
so that
or
To find
x_{2} we use the fact that
x_{2} = (
v −
cx_{1})/
d, to get
While this method works well for a system of two equations in two unknowns, its generalization to systems with more equations and variables is cumbersome. A more elegant method that generalizes to any number of equations starts by writing the system in matrix form, as

a 
b 

c 
d 


x_{1} 

x_{2} 

= 

u 

v 

. (*) 
A general
nequation system may be written as
Ax = b,
where
A is an
n ×
n matrix and
x and
b are
n × 1 column vectors. If
A is
nonsingular, then multiplying each side by the
inverse A^{−1} of
A yields
x = A^{−1}b.
If n = 2 or n = 3, the inverse of A is relatively easy to compute, so that the solution of the system can easily be found, as the following examples demonstrate.
 Example

Consider the system of equations
ax_{1} + bx_{2} 
= u 
cx_{1} + dx_{2} 
= v. 
Write it in matrix form. The inverse of the matrix on the left is



d 
−b 

−c 
a 

so we have

x_{1} 

x_{2} 

= 


d 
−b 

−c 
a 


u 

v 

. 
Thus
and
as we found before.
 Example

Consider the system of equations
2 
x_{1} + 

x_{2} + 
2 
x_{3}

= 
1 

x_{1} − 

x_{2} + 

x_{3} 
= 
0 


2 
x_{2} − 

x_{3} 
= 
3. 
When written in matrix form, the matrix on the left is

2 
1 
2 

1 
−1 
1 
0 
2 
−1 

. 
Using the general formula for the inverse of a matrix, the inverse of this matrix is

−1/3 
5/3 
1 

1/3 
−2/3 
0 
2/3 
−4/3 
−1 

. 
Multiplying b, which is the transpose of (1, 0, 3), by this matrix yields (x_{1}, x_{2}, x_{3}) = (8/3, 1/3, −7/3). (By substituting this list of values into the original equations you can verify that it is indeed a solution—and therefore the solution.)
Cramer's rule
A useful implication of the fact that the solution of the system
Ax =
b is given by
x =
A^{−1}b is the following result (due to
Gabriel Cramer, 17041752), which gives an explicit expression for the value of each variable separately.
 Proposition (Cramer's rule)

Let A be an n × n matrix, let b be a n × 1 column vector, and consider the system of equations
Ax = b.
where x is an n × 1 column vector. If A is nonsingular then the (unique) value of x that satisfies the system is given by
x_{i} = A*(b,i)/A for i = 1, ..., n,
where A*(b,i) is the matrix obtained from A by replacing the ith column with b.
 Proof

We have x = A^{−1}b, so that
x_{i} = ∑n
j=1v_{ij}b_{j},
where v_{ij} is the (i,j)th component of A^{−1}.
Now, by a previous result, the (i,j)th component of A^{−1} is (−1)^{i+j}A_{ji}/A. Thus
x_{i} = ∑n
j=1(−1)^{i+j}A_{ji}b_{j}/A.
Finally, calculate the determinant of A*(b,i) in the statement of the result by expanding along its ith column. This column is b, so according to the second part of a previous result we have
A*(b,i) = ∑n
j=1(−1)^{i+j}b_{j}A_{ji},
establishing the result. (Note that because i is the index of the column along which we are expanding, the roles of i and j here are reversed relative to their roles in the statement of the result we are using.)
 Example

Applying Cramer's rule to the twovariable system
ax_{1} + bx_{2} 
= u 
cx_{1} + dx_{2} 
= v 
we get
x_{1} = 

u 
b 

v 
d 


ad − bc 

and
x_{2} = 

a 
u 

c 
v 


ad − bc 

. 
Calculating the determinants in the numerators, we have
and
Cramer's rule is particularly useful if you want to calculate the value of only some of the variables in a solution of a system of equations, as the following example demonstrates.
 Example

The value of x_{2} in a solution of the system of equations
2 
x_{1} + 

x_{2} + 
2 
x_{3}

= 
1 

x_{1} − 

x_{2} + 

x_{3} 
= 
0 


2 
x_{2} − 

x_{3} 
= 
3 
is, by Cramer's rule, the determinant of

2 
1 
2 

1 
0 
1 
0 
3 
−1 

divided by the determinant of

2 
1 
2 

1 
−1 
1 
0 
2 
−1 

. 
The first determinant is 1 and the second is 3, so the value of x_{2} in the solution of the system is 1/3.