How do I solve simultaneous linear equations?

Here is an example set of simultaneous linear equations. There are 3 equations in 3 unknowns.
(1) 2x - 3y + z = 13
(2) 4x + y - 2z = 8
(3) x - y + 3z = 8

If there are less equations than unknowns, then you do not have enough information to find a unique solution, although you can still parametrise a solution with a reduced number of free parameters.

If you have too many equations then it is unlikely that you will have any solution at all, unless some of the equations are redundant. --[reporting2] Doing 'do snippet' - should be imbed--

Visualising simultaneous linear equations

In two or 3 variables there is a clear geometrical relationship. A linear equation in 3 variables describes a plane in 3D space. Solutions to the one equation could be anywhere on that two dimensional surface. For example, the equation 2x+4y-z=3 represents a plane perpendicular to the vector (2,4,-1).

Add another equation and you are adding another plane. Unless it is parallel to the first one, the two equations now define a solution space which is a line, where the two planes intersect. Add one more plane and there is only a single point which is the solution to all 3 equations.

Substitution

The general way to solve simultaneous equations, not just linear ones, is to re-arrange one equation so that one of the variables is the subject. Then substitute for that variable in the next equation, and all subsequent ones, to remove that variable. Continue until there is only one variable left and solve for it.

It is a straightforward process to do with two variables, so let's solve the equations above.

Re-arrange (3) with x as the subject.
(4) x = 8 + y - 3z

and substitute in the second equation:
4(8 + y - 3z) + y - 2z = 8

which leads to:
(5) 5y -14z = -24
or y = (-24 +14z)/5

Now substitute both x and y into the first equation:
2(8 + (-24 +14z)/5 - 3z) - 3(-24 +14z)/5 + z = 13

Sorting out this horrendous mess gives z=1.

Substituting the known value of z gives
y = (-24 +14z)/5 = -2

Substituting them both:
x = 8 + y - 3z = 3

It is important that you choose the right equations to use: you must use all the equations you are given, otherwise you will end up eliminating all variables.

It is also possible that the equations do not have a solution, or do not have a unique solution.

Substitution will always find a solution if there is one, but it isn't particularly elegant.

Manipulating the equations

An equivalent but neater process is to add and subtract whole multiples of the equations.

(2) - 4 x (3) gives (5) directly.
5y - 14z = -24

(1) - 2 x (3) gives
(6) -y - 5z = -3

Now add (5) + 5 x (6)
-39z = -39

You can now substitute back as before.

Matrices

A set of n linear equations in n unknowns can be represented by an n x n square matrix A. If the unknowns are arranged as a vector x and the result vector is b then the whole set of equations can simply be written
Ax = b

The answer is equally simple,
x = A-1x

but you have to work out A-1, the inverse of the matrix.

Software can invert a matrix but you can also do it yourself. The simplest way is probably to use augmented matrices.

Matrices also give us a simple way to determine whether there is a solution. The inverse matrix only exists if the determinant of the matrix is non-zero.