Mathematics: 2by2 and 3by3 linear equation systems.
In the previous text in this section, I explained the mathematical background needed to solve equations in one variable, including the simplest case: linear
equations, that may have 1 unique, no or an infinity of solutions. The following text also deals with linear equations, but this time analyzes the situation,
where we have 2 or 3 variables. Important to remember: To get a defined solution, you need as much equations as you have variables.
Thus, if you have 2 variables, you need 2 linear equations to have a chance to get a 1 unique solution (with 1 single equation you'll always get an infinity of
solutions); with 3 variables, you'll need 3 equations. In such a case, we speak of equation systems. A system with 2 equations in 2
variables is called 2by2 system; a system with 3 equations in 3 variables is called 3by3 system.
A 2by2 system, for example, is an equation system of the form:
(1) a_{1}x + b_{1}y = d_{1}
(2) a_{2}x + b_{2}y = d_{2}
all of the coefficients being reals and x and y having to verify both equations!
Note.
If you need a program to solve linear equations in 1, 2 or 3 variables, have a look at my (simple command line) linear
equation solver in the Lazarus/Free Pascal Console Programs section of this site. To test your knowledge concerning linear equations,
the mathematics trainers (exercise generators) in the Free Pascal GUI Applications section may be helpful.
There are several methods to solve linear equation systems, described in the following paragraphs.
Solving linear equation systems by substitution.
For a 2by2 system, the substitution method consists in solving one equation for one of the variables and substituting the value obtained into the other equation.
For a 3by3 system, the substitution method (alone) is normally not adaquate.
Example 1:
2by2 system:
Solving equation (2) for x:
Substitution of x in equation (1):
Calculating x by replacing y with its value in either of the 2 equations gives: 
Example 2:
2by2 system:
Solving equation (1) for y, after dividing its coefficients by 2
Substitution of y in equation (2):
Calculating y by replacing x with its value in either of the 2 equations gives: 
Note the division of the equation's coefficients in example 2. By the way: In this particular example, you could also solve
equation (1) for 2y and directly replacing in equation (2).
Solving linear equation systems by addition.
For a 2by2 system, the addition method consists in adding or subtracting the 2 equations in order to "eliminate" 1 of the variables. As for the substitution method,
multiplication or division of the coefficients by a given number may be necessary to reach this goal.
Example 3:
2by2 system:
Adding the 2 equations:
Calculating y by replacing x with its value in either of the 2 equations gives: 
Example 4:
2by2 system:
Multiplying equation (1) by 4 and equation (2) by 3, the system becomes:
Adding the 2 equations:
Calculating x by replacing y with its value in either of the 2 equations gives: 
For a 3by3 system, it's similar, but sometimes not as evident. In simple cases, two additions/subtractions of 2 of the 3 equations (eventually with
coefficient multiplication/division) allows to calculate the values of 2 variables and then, by replacing these in any of the equations, the third one.
In more complicated cases, the two additions of 2 equations don't allow to calculate values, but only to eliminate one of the variables (to continue
the procedure, this variable has to be the same in both equations!). Then, you have to perform a further addition/subtraction, that allows to eliminate
another variable, and thus gives you the remaining variable's value. Replacing this value in one of the equation with 2 variables gives a second value
and replacing the 2 values in any of the 3 original equations gives the third one.
Example 5:
3by3 system:
Adding equation (1) and equation (2):
Multiplying the coefficients of equation (1) by 2 :
Subtracting equation (3) from equation (2):
Calculating y by replacing x and z with their values in either of the 3 equations gives: 
Example 6:
3by3 system:
Elimination of x, step 1: Multiplying equation (1) by 2 and subtracting it from equation (2):
Elimination of x, step 2: Multiplying equation (3) by 2 and subtracting it from equation (2):
Multiplying the coefficients of equation (b) by 2:
Adding equation (a) and equation (b):
Calculating z by replacing y with its values in either of (a) or (b) gives:
Calculating x by replacing y and z with their values in either of (1), (2) or (3) gives: 
Some other examples.
You can make the substitution and the addition methods "work together" in order to solve linear systems (example 7). And, to be complete: showing a system,
that has no solution (example 8) and one with an infinity of solutions (example 9).
Example 7:
3by3 system:
Solving equation (2) for x:
Substitution of x in equation (1):
Substitution of x in equation (3):
Adding equation (a) and equation (b):
Calculating z by replacing y with its values in either of (a) or (b) gives:
Calculating x by replacing y and z with their values in either of (1), (2) or (3) gives: 
Example 8:
2by2 system:
Multiplying equation (1) by 2 and adding the two equations:
No x,yvalues verify this equality. Thus: The equation system has no solution. Example 9:
2by2 system:
Multiplying equation (1) by 2 and adding the two equations:
Any x,yvalues verify this equality. Thus: The equation system has an infinity of solutions. 
Calculations to be done are basic arithmetic operations; most mistakes are the result of using the bad sign, not paying attention
when multiplying terms between brackets or when passing variables or values from one side of the equation to the other.
However, the problem with the substitution and addition methods is to "see" (intuitively or by experience, in a certain sense),
what you have (best) to do: which method to use, for which value to solve in substitution or what equations to add in addition method. In some cases, this may
be hard and you'll have to do a lot of calculations before coming to an end. And the more you calculate, the bigger is the risk that you make a mistake. Having
some kind of formula, that applies and works the same way in all cases, would really be nice. Fortunately, there is a general method for solving nbyn equation
systems: the socalled Cramer's rule. Which has an inconvenient, too, however: To use it, you have to know, how to calculate
determinants.
Determinants.
In linear algebra, the determinant is a scalar value that can be computed from the elements of a square matrix and encodes certain properties of the linear
transformation described by the matrix. In the case of a 2 × 2 matrix A, the determinant may be defined as:
A =  a  b  = ad  bc 
c  d 
To calculate determinants with more elements, we use the minor expansion formula, which gives a recursive definition for the determinant.
In fact, we apply this formula until the minors are 2×2 determinants, that we can easily calculate, as shown above. Determinant of a 3×3 matrix A:
A =  a  b  c  
d  e  f  = a  e  f   b  d  f  + c  d  e  = a(ei  fh)  b(di  fg) + c(dh  eg) = aei + bfg + ceg  afh  bdi  ceg 
g  h  i  h  i  g  i  g  h 
No sense, of course to memorize the result, just remember how to transform the determinant of a 3×3 matrix to an expression containing 2×2 elements determinants and calculate those, using the formula shown above. In the same way, the determinant of a 4×4 matrix can be written as an expression, containing 3×3 elements determinants, which then may be written as expressions with 2×2 elements determinants. But, how exactly the minor expansion formula is constructed, what elements have to be included in the different minors and what is the correct operation (addition/subtraction) to be used?
 Take the elements of the first row, one by one, and use them as constant to be multiplied with the corresponding minor.
 For each of the first row elements, the minor is constructed by using those elements (in the same rowcolumn disposition as in the original determinant), that do not belong to the row, nor to the column of the multiplication constant.
 The operators to be used between the different terms are an alternation of "" and "+" (the first operation being a subtraction).
Let's take the 2nd term of the formula as example:
 The 2nd element of the first row = "b", that will be used as multiplication constant.
 The minor is formed by the elements not being part of the "b" row (1), nor the "b" column (2), i.e. "d, f, g, i", to be used in the same rowcolumn disposition as in A.
 The alternation of operators starting with a subtraction, the operator to be used is "".
If you need a PC application to calculate determinants, you may want to freely check out my Determinant
calculator (calculation of 2×2, 3×3 and 4×4 determinants, with display of the minor expansion) from the Free Pascal GUI Applications
section of my site.
Linear equation systems and determinants (Cramer's rule).
A linear equation system may be represented as a matrix, the different coefficients being its elements. Cramer's rule is based on the calculation of
specific determinants for the equation's matrix. The way to proceed is the same, for a 2×2, a 3×3 ... n×n system; the only thing that changes, it that
you get "bigger" determinants (more elements = more rows/columns).
Mathematical definition of Cramer's rule:
For a matrix equation
Ax = b (with A ≠ 0),
the solution by Cramer's rule is given by:
x_{i} = A_{i} / A (with i = 1, 2, 3 ...)
where A_{i} is the matrix formed by replacing the ith column of A by the column vector b.
If A = 0, and all determinants A_{i} are also 0, the equation has an infinity of solutions. If A = 0 and any of the determinants A_{i} ≠ 0,
the equation has no solution.
This may seem complicated, but don't bother; as the examples will show, it's all the contrary!
Using Cramer's rule to solve a 2by2 linear system.
Example 10 (example 1 revisited):
2by2 system:
(1) 4x + y = 11
(2) x + 2y = 8
Calculation of the determinant A:
A =  4  1  = 4∙2  1∙1 = 8  1 = 7 ≠ 0 
1  2 
As A ≠ 0, the system has a unique solution, given by:
x = A_{x} / A and y = A_{y} / A
where A_{x} is constructed from A, by replacing the xcoefficients by the constant coefficients and A_{y} by replacing the ycoefficients.


Example 11 (example 8 revisited):
2by2 system:
(1) 3x  y = 1
(2) 6x + 2y = 2
Calculation of the determinant A:
A =  3  1  = 3∙2  (1)∙(6) = 6  6 = 0 
6  2 
Calculation of the determinant A_{x}:
A_{x} =  1  1  = (1)∙2  (1)∙(2) = 2  2 =  4 ≠ 0 
2  2 
As A = 0 and A_{x} ≠ 0, this system has no solution.
Example 12 (example 9 revisited):
2by2 system:
(1) 3x  y = 1
(2) 6x + 2y = 2
Calculation of the determinant A:
A =  3  1  = 3∙2  (1)∙(6) = 6  6 = 0 
6  2 
Calculation of the determinants A_{x} and A_{y}:


As A = 0 and both A_{x} and A_{y} = 0, this system has an infinity of solutions.
Using Cramer's rule to solve a 3by3 linear system.
Example 13:
3by3 system:
(1) x  3y  5z = 4
(2) 7x + 7y + 4z = 3
(3) 6x  5y = 6
Calculation of the determinant A:
A =  1  3  5  
7  7  4  = 1∙  7  4   (3)∙  7  4  + (5)∙  7  7  = 293 
6  5  0  5  0  6  0  6  5 
A ≠ 0: The equation system has one unique solution:
A_{x} =  4  3  5  
3  7  4  = 4∙  7  4   (3)∙  3  4  + (5)∙  3  7  = 293 => x = 1 
6  5  0  5  0  6  0  6  5 
A_{y} =  1  4  5  
7  3  4  = 1∙  3  4   (4)∙  7  4  + (5)∙  7  3  = 0 => y = 0 
6  6  0  6  0  6  0  6  6 
A_{z} =  1  3  4  
7  7  3  = 1∙  7  3   (3)∙  7  3  + (4)∙  7  7  = 293 => z = 1 
6  5  6  5  6  6  6  6  5 
Example 14:
3by3 system:
(1) x  7y  8z = 3
(2) x + 9y  10z = 1
(3) x + 7y + 8z = 3
Calculation of the determinant A:
A =  1  7  8  
1  9  10  = 1∙  9  10   (7)∙  1  10  + (8)∙  1  9  = 0 
1  7  8  7  8  1  8  1  7 
A = 0: The equation system hasn't one unique solution. Calculation of the other determinants to see if there is no or an infinity of solutions:
A_{x} =  3  7  8  
1  9  10  = 3∙  9  10   (7)∙  1  10  + (8)∙  1  9  = 0 
3  7  8  7  8  3  8  3  7 
A_{y} =  1  3  8  
1  1  10  = 1∙  1  10   3∙  1  10  + (8)∙  1  1  = 0 
1  3  8  3  8  1  8  1  3 
A_{z} =  1  7  3  
1  9  1  = 1∙  9  1   (7)∙  1  1  + 3∙  1  9  = 0 
1  7  3  7  3  1  3  1  7 
As all 3 determinants are 0, the equation system has an infinity of solutions.
Geometrical interpretation.
2by2 linear system.
 The 2 lines cut and there is a unique intersection point.
 The 2 lines are parallel and distinct: there is no intersection point.
 The 2 lines are identical: there are an infinity of intersection points.
3by3 linear system.
A linear equation with 3 variables describes a plane in a 3D space. Solving a 3by3 linear system could thus be considered as studying the intersection of 3 planes. You may also consider that 2 linear equations with 3 variables define a line in a 3D space, the 3rd equation defining a plane. Thus, solving the 3by3 linear equations system may be seen as studying the intersection of a line and a plane. 3 possibilities:
 The line and the plane cut and there is a unique intersection point.
 The line is parallel to the plane and not included in it: there is no intersection point.
 The line is included in the plane: there are an infinity of intersection points (the line itself).
If you find this tutorial helpful, please, support me and this website by signing my guestbook.