Learning: Mathematics and Science

Mathematics: 2-by-2 and 3-by-3 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 2-by-2 system; a system with 3 equations in 3 variables is called 3-by-3 system.

A 2-by-2 system, for example, is an equation system of the form:

(1) a1x + b1y = d1
(2) a2x + b2y = d2

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 2-by-2 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 3-by-3 system, the substitution method (alone) is normally not adaquate.

 Example 1: 2-by-2 system:   (1) 4x +  y = 11   (2)  x + 2y =  8 Solving equation (2) for x:   x = -2y + 8 Substitution of x in equation (1):   4(-2y + 8) + y = 11   => -8y + 32 + y = 11   => -7y = -21   => y = 3 Calculating x by replacing y with its value in either of the 2 equations gives:   x = 2 Example 2: 2-by-2 system:   (1) 6x + 2y =  2   (2) 3x + 2y = -1 Solving equation (1) for y, after dividing its coefficients by 2   3x + y = 1   => y = -3x + 1 Substitution of y in equation (2):   3x + 2(-3x + 1) = -1   => 3x - 6x + 2 = -1   => -3x = -3   => x = 1 Calculating y by replacing x with its value in either of the 2 equations gives:   y = -2

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 2-by-2 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: 2-by-2 system:   (1) x + y = 8   (2) x - y = 2 Adding the 2 equations:   2x = 10   => x = 5 Calculating y by replacing x with its value in either of the 2 equations gives:   y = 3 Example 4: 2-by-2 system:   (1) 3x + 2y = 12   (2) 4x + 5y =  2 Multiplying equation (1) by 4 and equation (2) by -3, the system becomes:   (1)  12x +  8y = 48   (2) -12x - 15y = -6 Adding the 2 equations:   -7y = 42   => y = -6 Calculating x by replacing y with its value in either of the 2 equations gives:   x = 8

For a 3-by-3 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: 3-by-3 system:   (1)  x -  y - z =  1   (2)  x +  y + z = -3   (3) 2x + 2y - z =  3 Adding equation (1) and equation (2):   2x = -2   => x = -1 Multiplying the coefficients of equation (1) by 2 :   (2) 2x + 2y + 2z = -6 Subtracting equation (3) from equation (2):   3z = -9   => z = -3 Calculating y by replacing x and z with their values in either of the 3 equations gives:   y = 1 Example 6: 3-by-3 system:   (1)  x + 2y -  z =  2   (2) 2x + 2y + 2z = 12   (3)  x -  y + 2z =  5 Elimination of x, step 1: Multiplying equation (1) by 2 and subtracting it from equation (2):   (1) 2x + 4y - 2z =  4   (a)     -2y + 4z =  8 Elimination of x, step 2: Multiplying equation (3) by 2 and subtracting it from equation (2):   (3) 2x - 2y + 4z = 10   (b)      4y - 2z =  2 Multiplying the coefficients of equation (b) by 2:   (b) 8y - 4z = 4 Adding equation (a) and equation (b):   6y = 12   => y = 2 Calculating z by replacing y with its values in either of (a) or (b) gives:   z = 3 Calculating x by replacing y and z with their values in either of (1), (2) or (3) gives:   x = 1

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: 3-by-3 system:   (1)  x + 2y -  z = 2   (2) 2x + 2y + 2z = 8   (3)  x + 2y + 3z = 4 Solving equation (2) for x:   x = -y - z + 4 Substitution of x in equation (1):   (-y - z + 4) + 2y - z = 2   => (a) y - 2z = -2 Substitution of x in equation (3):   (-y - z + 4) + 2y + 3z = 4   => (b) y + 2z = 0 Adding equation (a) and equation (b):   2y = -2   => y = -1 Calculating z by replacing y with its values in either of (a) or (b) gives:   z = 1/2 Calculating x by replacing y and z with their values in either of (1), (2) or (3) gives:   x = 9/2 Example 8: 2-by-2 system:   (1)  3x -  y = -1   (2) -6x + 2y = -2 Multiplying equation (1) by 2 and adding the two equations:   0x + 0y = -4 No x,y-values verify this equality. Thus: The equation system has no solution. Example 9: 2-by-2 system:   (1)  3x -  y =  1   (2) -6x + 2y = -2 Multiplying equation (1) by 2 and adding the two equations:   0x + 0y = 0 Any x,y-values 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 n-by-n equation systems: the so-called 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?

1. Take the elements of the first row, one by one, and use them as constant to be multiplied with the corresponding minor.
2. For each of the first row elements, the minor is constructed by using those elements (in the same row-column disposition as in the original determinant), that do not belong to the row, nor to the column of the multiplication constant.
3. 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:

1. The 2nd element of the first row = "b", that will be used as multiplication constant.
2. 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 row-column disposition as in A.
3. 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:
xi = |Ai| / |A|   (with i = 1, 2, 3 ...)
where Ai is the matrix formed by replacing the ith column of A by the column vector b.

If |A| = 0, and all determinants |Ai| are also 0, the equation has an infinity of solutions. If |A| = 0 and any of the determinants |Ai| ≠ 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 2-by-2 linear system.

Example 10 (example 1 revisited):

2-by-2 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 = |Ax| / |A| and y = |Ay| / |A|
where |Ax| is constructed from |A|, by replacing the x-coefficients by the constant coefficients and |Ay| by replacing the y-coefficients.

 |Ax| = 11 1 = 11∙2 - 1∙8 = 22 - 8 = 14 8 2 => x = 14 / 7 = 2
 |Ay| = 4 11 = 4∙8 - 1∙11 = 32 - 11 = 21 1 8 => y = 21 / 7 = 3

Example 11 (example 8 revisited):

2-by-2 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 |Ax|:

 |Ax| = -1 -1 = (-1)∙2 - (-1)∙(-2) = -2 - 2 = - 4 ≠ 0 -2 2

As |A| = 0 and |Ax| ≠ 0, this system has no solution.

Example 12 (example 9 revisited):

2-by-2 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 |Ax| and |Ay|:

 |Ax| = 1 -1 = 1∙2 - (-1)∙(-2) = 2 - 2 = 0 -2 2
 |Ay| = 3 1 = 3∙(-2) - 1∙(-6) = -6 - (-6) = 0 -6 -2

As |A| = 0 and both |Ax| and |Ay| = 0, this system has an infinity of solutions.

Using Cramer's rule to solve a 3-by-3 linear system.

Example 13:

3-by-3 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:

 |Ax| = -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
 |Ay| = 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
 |Az| = 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:

3-by-3 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:

 |Ax| = 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
 |Ay| = 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
 |Az| = 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.

2-by-2 linear system.

A linear equation with 2 variables describes a line in a (2D) plane. Solving a 2-by-2 linear system may thus be considered as studying the intersection of 2 lines in a plane. 3 possibilities:
• 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.

3-by-3 linear system.

A linear equation with 3 variables describes a plane in a 3D space. Solving a 3-by-3 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 3-by-3 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.