You are on page 1of 4

Appendix A

Solving m Linear Equations in n Unknowns

In this appendix, we develop a procedure for solving a system of m linear equations


in n variables subject to a constraint that all the variables are nonnegative integers.
We first discuss a method for solving one equation in n unknowns. Then, we extend
the method to solving a system of m equations in n unknowns.

A.1 Solving One Equation in n Unknowns

Consider the following linear equation:

c1 x1 + c2 x2 + c3 x3 + · · · + cn xn = k , (A.1)

where xi s are the variables and ci s are the coefficients. The ci s are nonnegative
integers and k is a positive integer. We wish to solve for xi , for i = 1, 2, . . . , n
subject to a constraint that all xi s must be nonnegative integers. In addition, the
following constraint may be imposed:

xi ≤ qi (constant) . (A.2)

Since there are n unknowns in one equation, we may choose n − 1 number of


unknowns arbitrarily and solve Equation (A.1) for the remaining unknown, provided
that all the solutions are nonnegative integers. This can be accomplished by a com-
puter program using a nested-do loops algorithm to vary the value of each xi and
check for the validity of the solutions. A more rigorous procedure for solving one
linear equation in two unknowns can be found in [1].

© 2001 by CRC Press LLC


Table A.1 A Nested-do Loops Algorithm for Solving One Linear
Equation in n Unknowns.
FOR I1 = 0 TO q1
x(1) = I1
FOR I2 = 0 TO q2
x(2) = I2
FOR I3 = 0 TO q3
x(3) = I3
..
.
FOR In−1 = 0 TO qn−1
x(n − 1) = In−1
x(n) = (k − c(1) ∗ x(1) − . . .
−c(n − 1) ∗ x(n − 1))/c(n).
IF x(n) < 0, DISCARD THE SOLUTION.
IF x(n) ≥ 0, SAVE THE SOLUTION.
NEXT In−1
..
.
NEXT I3
NEXT I2
NEXT I1

A.2 Solving m Equations in n Unknowns


Next, we consider a system of m linear equations in n unknowns:

c11 x1 + c12 x2 + · · · + c1n xn = k1 ,


c21 x1 + c22 x2 + · · · + c2n xn = k2 ,
..
. (A.3)
cm1 x1 + cm2 x2 + · · · + cmn xn = km ,

where the coefficients cij s are nonnegative integers, the constants ki s are positive
integers, and n > m. Furthermore, the solutions to the system of equations are
subject to a constraint that all the variables xi , for i = 1, 2, . . . , n, must be nonnegative
integers. Writing Equation (A.3) in matrix form yields

Cx=0, (A.4)

© 2001 by CRC Press LLC


where
 
c11 c12 c13 ... c1n −k1
 c21 c22 c23 ... c2n −k2 
 
C =  .. .. .. .. .. ..  ,
 . . . . . . 
cm1 cm2 cn3 ... cmn −km
T
x = [x1 , x2 , . . . , xn , 1] .

Applying Gauss elimination, Equation (A.4) can be reduced to an upper triangular


form:

Gx = 0 , (A.5)

where  
g11 g12 g13 ... ... g1n p1
 0 g22 g23 ... ... g2n p2 
 
G= .. .. .. ..  .
 0 0 . . ... . . 
0 0 0 gm,m ... gmn pm
The last row in Equation (A.5) contains n − m + 1 unknowns which can be solved
by the procedure outlined in the preceding section. Once xm , . . . , xn are known, the
remaining unknowns are found by back substitution.

Example A.1 We wish to solve the following two equations for all possible nonneg-
ative integers of xi s

x 1 + x2 + x3 = 6, (A.6)
2x1 + 3x2 + 4x3 = 16 . (A.7)

Subtracting Equation (A.6)×2 from Equation (A.7), we obtain

x2 + 2x3 = 4 . (A.8)

Equation (A.8) contains two unknowns. Since both 2x3 and 4 are even numbers, x2
must be an even number. Let x2 assume the values of 0, 2, and 4, one at a time, and
solve Equation (A.8) for x3 . Once x3 is found, we solve Equation (A.6) for x1 . As a
result, we obtain the three solutions:

Solution x1 x2 x3
1 4 0 2
2 3 2 1 .
3 2 4 0

© 2001 by CRC Press LLC


References

[1] Gelfond, A.O., 1981, Solving Equations in Integers, Translated by Sheinin,


O.B., Mir Publisher, Moscow.

© 2001 by CRC Press LLC

You might also like