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 computer 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 In1 = 0 TO qn1

x(n 1) = In1
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 In1
..
.

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
c21 x1 + c22 x2 + + c2n xn
cm1 x1 + cm2 x2 + + cmn xn

=
=
..
.

k1 ,
k2 ,

km ,

(A.3)

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,

2001 by CRC Press LLC

(A.4)

where

c11
c21
..
.

c12
c22
..
.

cm1
x

cm2

c13
c23
..
.

cn3
T

[x1 , x2 , . . . , xn , 1]

...
...
..
.

c1n
c2n
..
.

...

cmn

k1
k2
..
.

km

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


form:
Gx = 0 ,
where

g11
0

G=
0
0

g12
g22

g13
g23
..
.

0
0

(A.5)

...
...
..
.

...
...

g1n
g2n
..
.

...
...

gm,m

gmn

p1
p2
..
.

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 nonnegative 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:

2001 by CRC Press LLC

Solution

x1

x2

x3

1
2
3

4
3
2

0
2
4

2
1
0

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