A solution to a system of equations is a series of numbers, one per variable, such that if we replace the variable by its corresponding number, the two sides of each equation evaluate to the same number. In our running example, the solution is x = 1, y = 1, and z = 2 as we can easily check:
The first equation now reads as 10 = 10, the second one as 31 = 31, and the last one as 1 =1. One of the most famous methods for finding a solution is called Gaussian elimination. It consists of two steps. The first step is to transform the system of equations into a system of different shape but with the same solution. The second step is to find solutions to one equation at a time. Here we focus on the first step because it is another interesting instance of generative recursion. The first step of the Gaussiam elminiation algorithm is called ``triangulation'' because the result is a system of equations in the shape of a triangle. In contrast, the original system is typically a rectangle. To understand this terminology, take a look at this representation of the original system:
This representation captures the essence of the system, namely the numeric coefficients of the variables and the right hand sides. The names of the variables don't play any role. The generative step in the triangulation phase is to subtract the first row (list) of numbers from all the other rows. Subtracting one row from another means subtracting the corresponding items in the two rows. With our running example, this step would yield
when we subtract the first row from the second. The goal of these subtractions is to put a 0 into the first column of all but the first row. To achieve this for the last row, we subtract the first row twice from the second one:
Put differently, we first multiply each item in the first row with <#66753#><#36404#>2<#36404#><#66753#> and
then subtract the result from the last row. It is easy to check that the solution
for the original system of equations and this new one are identical.
<#36407#>Exercise 27.5.1<#36407#>
has the same solution as the one labeled with Solution<#66754#><#66754#>
<#36417#>Exercise 27.5.2<#36417#>
Solution<#66758#><#66758#>
Following mathematical convention, we drop the leading <#66759#><#36429#>0<#36429#><#66759#>'s from the
representation of the last two equations:
If, in addition, we use the same process for the remainder of the system to generate shorter rows, the final representation has a triangular shape. Let us study this idea with our running example. For the moment we ignore the first row and focus on the rest of the equations:
By subtracting the first row now <#36443#>-1<#36443#> times from the second one, we get
after dropping the leading <#66760#><#36450#>0<#36450#><#66760#>. The remainder of this system is a single
equation, which cannot be simplified any further.
Here is the result of putting together this last system with the first
equation:
As promised, the shape of this system of equations is (roughly) a triangle, and
as we can easily check, it has the same solution as the original system.
<#36461#>Exercise 27.5.3<#36461#>
has the same solution as the one labeled with Solution<#66761#><#66761#>
<#36471#>Exercise 27.5.4<#36471#>
Solution<#66763#><#66763#>
Unfortunately, the current version of the triangulation algorithm
occasionally fails to produce the solution. Consider the following
(representation of a) system of equations:
Its solution is x = 2, y = 1, and z = 1. The first step is to subtract the first row from the second and to subtract it twice from the last one, which yields the following matrix:
Next our algorithm would focus on the rest of the matrix:
but the first item of this matrix is <#66764#><#36501#>0<#36501#><#66764#>. Since we cannot divide by <#66765#><#36502#>0<#36502#><#66765#>, we are stuck. To overcome this problem, we need to use another piece of knowledge from our problem domain, namely, that we can switch equations around without changing the solution. Of course, as we switch rows, we must make sure that the first item of the row to be moved is not <#66766#><#36503#>0<#36503#><#66766#>. Here we can simply swap the two rows:
From here we may continue as before, subtracting the first equation from the remaining ones a sufficient number of times. The final triangular matrix is:
It is easy to check that this system of equations still has the solution
x = 2, y = 1, and z = 1.
<#36519#>Exercise 27.5.5<#36519#>
<#36534#>(remove<#36534#> <#36535#>(list<#36535#> <#36536#>0<#36536#> <#36537#>1)<#36537#> <#36538#>(list<#36538#> <#36539#>(list<#36539#> <#36540#>2<#36540#> <#36541#>1)<#36541#> <#36542#>(list<#36542#> <#36543#>0<#36543#> <#36544#>1)))<#36544#> <#36545#>=<#36545#> <#36546#>(list<#36546#> <#36547#>(list<#36547#> <#36548#>2<#36548#> <#36549#>1))<#36549#>
Try to produce a triangular system by hand and with
<#66775#><#36563#>triangulate<#36563#><#66775#>. What happens? Modify the function so that it signals
an error if it encounters this situation.~ Solution<#66776#><#66776#>
<#36569#>Exercise 27.5.7<#36569#>
Determine the value for <#36575#>y<#36575#>. Then repeat the substitution step for <#36576#>y<#36576#> and <#36577#>z<#36577#> in the first equation and find the value for <#36578#>x<#36578#>. Develop the function <#66777#><#36579#>solve<#36579#><#66777#>, which consumes triangular systems of equations and produces a solution. A triangular system of equations has the shape
where
<#36594#>Hint:<#36594#> Developing <#66779#><#36595#>solve<#36595#><#66779#> requires a solution for the following problem. Suppose we are give a row:
<#36600#>(list<#36600#> <#36601#>3<#36601#> <#36602#>9<#36602#> <#36603#>21)<#36603#>and a list of numbers that solve the remainder of the system:
<#36611#>(list<#36611#> <#36612#>2).<#36612#>In the world of equations, these two pieces of data represent the following knowledge:
and
which in turn means we must solve the following equation:
Develop the function <#66780#><#36616#>evaluate<#36616#><#66780#>, which evaluates the rest of the
left-hand side of an equation and subtracts the right-hand side from this
sum. Equivalently, <#66781#><#36617#>evaluate<#36617#><#66781#> consumes <#66782#><#36618#>(list<#36618#>\ <#36619#>9<#36619#>\ <#36620#>21)<#36620#><#66782#> and
<#66783#><#36621#>(list<#36621#>\ <#36622#>2)<#36622#><#66783#> and produces <#66784#><#36623#>-3<#36623#><#66784#>, that is, Solution