TCM Algebra 2: Linear Equations - Part 2

**By: Tao Steven Zheng (鄭濤)**

## **Fang Cheng Problems**

Chapter 8 of the *Jiuzhang Suanshu*, entitled *fang cheng* (方程, "rectangular arrays"), provides the earliest description of two important mathematical concepts: matrices and negative numbers. The Chinese were the first to discover a systematic method for solving simultaneous linear equations using arithmetic operations. In practice, the *fang cheng* method begins by instructing the arithmetician to place counting rods in a rectangular array to represent the coefficients of linear equations, with each equation confined to a column. The arithmetician then manipulates the rods by carrying out the *fang cheng* algorithm in order to eliminate more and more entries until what remains are the entries along the main diagonal (from top right to bottom left) and the entries in the bottom row. The solution set to the system of simultaneous linear equations can then be determined from the remaining entries. This practice is identical to the modern use of matrices and the elimination method when solving problems of this nature. In the West, this method is attributed to Carl Friedrich Gauss (1777 - 1855 AD), but was likely discovered roughly a century earlier by mathematicians such as Isaac Newton (1642 - 1727 AD).

Negative numbers were also used to carry out matrix calculations. Chinese mathematicians distinguished positive and negative numbers using counting rods of different color: red counting rods for positive numbers; black counting rods for negative numbers. Figure 1 illustrates this convention. The *Jiuzhang Suanshu* explains several rules on how negative numbers worked, all being identical to our modern understanding. This set of rules, known collectively as the *zheng fu shu* (正負術, "positive and negative method"), outlines the distinction between positive and negative numbers and how they work.

Although the ancient Chinese did not conceive of zero as a number, rather more like a concept akin to the absence of quantity.

### **Problem Study 1: Three Grades of Grain**

答曰：上禾一秉，九斗、四分斗之一，中禾一秉，四斗、四分斗之一，下禾一秉，二斗、四分斗之三。

方程術曰：置上禾三秉，中禾二秉，下禾一秉，實三十九斗，於右方。中、左禾列如右方。以右行上禾遍乘中行而以直除。又乘其次，亦以直除。然以中行中禾不盡者遍乘左行而以直除。左方下禾不盡者，上為法，下為實。實即下禾之實。求中禾，以法乘中行下實，而除下禾之實。餘如中禾秉數而一，即中禾之實。求上禾亦以法乘右行下實，而除下禾、中禾之實。餘如上禾秉數而一，即上禾之實。實皆如法，各得一斗。

Answer: 1 bundle of top-grade millet is

9

1
4

{\displaystyle 9 \frac{1}{4} }

 *dou*; 1 bundle of medium-grade millet is

4

1
4

{\displaystyle 4 \frac{1}{4} }

*dou*; 1 bundle of low-grade millet is

2

3
4

{\displaystyle 2 \frac{3}{4} }

*dou*.

*Fang cheng* method: Set on the right side 3 bundles of top-grade millet, 2 bundles of medium-grade millet, 1 bundle of low-grade millet, and their total is 39 *dou*. Set the middle and left columns of millet just like the one on the right column. Use the number of top-grade millet in the right column to multiply the middle column, and then directly subtract (直除 *zhi chu*). Again multiply the next column by the number of top-grade millet, and then directly subtract. The left column is eliminated. Likewise use the remaining number of medium-grade millet in the middle column to multiply the left column, and directly subtract. On the left side, the lower-grade millet has not been eliminated yet. Let the number of upper-grade millet be the divisor, and the number of lower-grade millet be the dividend. The dividend is the total amount of low-grade millet. To find the amount of medium-grade millet, use the divisor [of the left column] to multiply the total amount at the bottom of the middle column, and then subtract the total amount of low-grade millet. The difference divided by the number of bundles of medium-grade millet gives the total amount of medium-grade millet. To find the amount of top-grade millet, also use the divisor [of the left column] to multiply the total amount at the bottom of the right column, and then subtract the total amounts of low-grade millet and the medium-grade millet. The difference divided by the number of bundles of top-grade millet gives the total amount of top-grade millet. Divide the *shi* by their divisors respectively, which gives the each amount in *dou*.

**Solution for *Jiuzhang Suanshu* [8.01]**

This problem is characterized by the system of simultaneous linear equations in three variables

{

3
x
2
y
# z
39

2
x
3
y
# z
34

x
2
y
3
# z
26

{\displaystyle \begin{cases} 3x + 2y + z = 39 \\
2x + 3y + z = 34 \\
x + 2y + 3z = 26
\end{cases} }

where

x

{\displaystyle x}

 represents 1 bundle of high-grade millet,

y

{\displaystyle y}

 represents 1 bundle of medium-grade millet,

z

{\displaystyle z}

 represents 1 bundle of low-grade millet.

According to the *fang cheng* method, the ancient Chinese mathematician would arrange counting rods to represent the coefficients of the equations in vertical columns from right to left. This is different from the horizontal arrangement in modern matrix notation. The solution below showcases a side-by-side comparison of both notations.

[

1

2

3

2

3

2

3

1

1

26

34

39

]

{\displaystyle \begin{bmatrix}
 1 & 2 & 3 \\
 2 & 3 & 2 \\
 3 & 1 & 1 \\
 26 & 34 & 39
 \end{bmatrix}
}

[

3

2

1

39

2

3

1

34

1

2

3

26

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 2 & 3 & 1 & 34 \\
 1 & 2 & 3 & 26\\
 \end{bmatrix}
}

The first step is to eliminate the top entry in the middle column. This is achieved by scaling the entire middle column with the top entry in the right column, which is 3, and then subtract the middle column by the right column twice. The eliminated entry is then left empty.

[

1

6

3

2

9

2

3

3

1

26

102

39

]

{\displaystyle \begin{bmatrix}
 1 & 6 & 3 \\
 2 & 9 & 2 \\
 3 & 3 & 1 \\
 26 & 102 & 39
 \end{bmatrix}
}

[

1

3

2

5

2

3

1

1

26

24

39

]

{\displaystyle \begin{bmatrix}
 1 & & 3 \\
 2 & 5 & 2 \\
 3 & 1 & 1 \\
 26 & 24 & 39
 \end{bmatrix}
}

[

3

2

1

39

6

9

3

102

1

2

3

26

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 6 & 9 & 3 & 102 \\
 1 & 2 & 3 & 26\\
 \end{bmatrix}
}

[

3

2

1

39

0

5

1

24

1

2

3

26

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 0 & 5 & 1 & 24 \\
 1 & 2 & 3 & 26\\
 \end{bmatrix}
}

The second step is to eliminate the top entry of the left column. This is achieved by scaling the entire left column with the top entry in the right column, which is 3, and then subtract the left column by the right column.

[

3

3

6

5

2

9

1

1

78

24

39

]

{\displaystyle \begin{bmatrix}
 3 & & 3 \\
 6 & 5 & 2 \\
 9 & 1 & 1 \\
 78 & 24 & 39
 \end{bmatrix}
}

[

3

4

5

2

8

1

1

39

24

39

]

{\displaystyle \begin{bmatrix}
 & & 3 \\
 4 & 5 & 2 \\
 8 & 1 & 1 \\
 39 & 24 & 39
 \end{bmatrix}
}

[

3

2

1

39

0

5

1

24

3

6

9

78

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 0 & 5 & 1 & 24 \\
 3 & 6 & 9 & 78\\
 \end{bmatrix}
}

[

3

2

1

39

0

5

1

24

0

4

8

39

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 0 & 5 & 1 & 24 \\
 0 & 4 & 8 & 39 \\
 \end{bmatrix}
}

The third step is to eliminate the second entry of the left column. This is achieved by scaling the entire left column with the second entry in the middle column, which is 5, and then subtract the left column by the right column four times. Finally reduce all the entries of the left column by 9.

[

3

20

5

2

40

1

1

195

24

39

]

{\displaystyle \begin{bmatrix}
 & & 3 \\
 20 & 5 & 2 \\
 40 & 1 & 1 \\
 195 & 24 & 39
 \end{bmatrix}
}

[

3

5

2

36

1

1

99

24

39

]

{\displaystyle \begin{bmatrix}
 & & 3 \\
 & 5 & 2 \\
 36 & 1 & 1 \\
 99 & 24 & 39
 \end{bmatrix}
}

[

3

5

2

4

1

1

11

24

39

]

{\displaystyle \begin{bmatrix}
 & & 3 \\
 & 5 & 2 \\
 4 & 1 & 1 \\
 11 & 24 & 39
 \end{bmatrix}
}

[

3

2

1

39

0

5

1

24

0

4

8

39

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 0 & 5 & 1 & 24 \\
 0 & 4 & 8 & 39 \\
 \end{bmatrix}
}

[

3

2

1

39

0

5

1

24

0

0

36

99

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 0 & 5 & 1 & 24 \\
 0 & 0 & 36 & 99 \\
 \end{bmatrix}
}

[

3

2

1

39

0

5

1

24

0

0

1

11
4

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 0 & 5 & 1 & 24 \\
 0 & 0 & 1 & \frac{11}{4} \\
 \end{bmatrix}
}

From here, one uncovers the third unknown quantity

# z

11
4

=
2

3
4

{\displaystyle z = \frac{11}{4} = 2\frac{3}{4} }

. Back-substitution of this value eliminates the third entry of the middle and right columns. Solving for the second unknown quantity gives

# y

17
4

=
4

1
4

{\displaystyle y = \frac{17}{4} = 4\frac{1}{4} }

.

[

3

4

2

4

1

11

17

39

]

{\displaystyle \begin{bmatrix}
 & & 3 \\
 & 4 & 2 \\
 4 & & 1 \\
 11 & 17 & 39
 \end{bmatrix}
}

[

12

4

8

4

11

17

145

]

{\displaystyle \begin{bmatrix}
 & & 12 \\
 & 4 & 8 \\
 4 & & \\
 11 & 17 & 145
 \end{bmatrix}
}

[

3

2

1

39

0

5

0

85
4

0

0

1

11
4

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 1 & 39 \\
 0 & 5 & 0 & \frac{85}{4} \\
 0 & 0 & 1 & \frac{11}{4} \\
 \end{bmatrix}
}

[

3

2

0

145
4

0

1

0

17
4

0

0

1

11
4

]

{\displaystyle \begin{bmatrix}
 3 & 2 & 0 & \frac{145}{4} \\
 0 & 1 & 0 & \frac{17}{4} \\
 0 & 0 & 1 & \frac{11}{4} \\
 \end{bmatrix}
}

Another back-substitution of

# y
4

1
4

{\displaystyle y = 4\frac{1}{4} }

 eliminates the second entry of the right column. Solving for the first unknown quantity gives

# x

37
4

=
9

1
4

{\displaystyle x = \frac{37}{4} = 9\frac{1}{4} }

.

[

12

4

4

11

17

111

]

{\displaystyle \begin{bmatrix}
 & & 12 \\
 & 4 & \\
 4 & & \\
 11 & 17 & 111
 \end{bmatrix}
}

[

4

4

4

11

17

37

]

{\displaystyle \begin{bmatrix}
 & & 4 \\
 & 4 & \\
 4 & & \\
11 & 17 & 37
 \end{bmatrix}
}

[

3

0

0

111
4

0

1

0

17
4

0

0

1

11
4

]

{\displaystyle \begin{bmatrix}
 3 & 0 & 0 & \frac{111}{4} \\
 0 & 1 & 0 & \frac{17}{4} \\
 0 & 0 & 1 & \frac{11}{4} \\
 \end{bmatrix}
}

[

1

0

0

37
4

0

1

0

17
4

0

0

1

11
4

]

{\displaystyle \begin{bmatrix}
 1 & 0 & 0 & \frac{37}{4} \\
 0 & 1 & 0 & \frac{17}{4} \\
 0 & 0 & 1 & \frac{11}{4} \\
 \end{bmatrix}
}

### **Problem Study 2: Buying and Selling Livestock**

答曰：牛價一千二百，羊價五百，豕價三百。

術曰：如方程，置牛二、羊五正，豕一十三負，餘錢數正；次牛三正，羊九負，豕三正；次牛五負，羊六正，豕八正，不足錢負。以正負術入之。

Answer: The price of one cow is 1200 *qian*; the price of one sheep is 500 *qian*; the price of one pig is 300 *qian*.

Method: Use the *fangcheng* method. Set 2 for cows and 5 for sheep; both are positive, negative 13 for pigs, and the excess *qian* is positive. Next set positive 3 for cows, negative 9 for sheep, and positive 3 for pigs. Next set negative 5 for cows, positive 6 for sheep, positive 8 for pigs, and the deficit *qian* is negative. Solve this using the *zheng fu* method.

**Solution for *Jiuzhang Suanshu* [8.08]**

Let

x
,
y
,
z

{\displaystyle x, y, z}

 represent the cost one one cow, one sheep, and one pig respectively. This problem is characterized by the system of three equations in three unknowns:

{

2
x
5
# y
13
z
1000

3
x
3
# z
9
y

6
y
8
# z
5
x
−
600

{\displaystyle \begin{cases}
2x + 5y = 13z + 1000 \\
3x + 3z = 9y \\
6y + 8z = 5x - 600
\end{cases} }

Set up the initial matrix and solve using modern matrix methods.

[

2

5

−
13

1000

3

−
9

3

0

−
5

6

8

−
600

]

{\displaystyle
\begin{bmatrix}
2 & 5 & -13 & 1000 \\
3 & -9 & 3 & 0 \\
-5 & 6 & 8 & -600
\end{bmatrix} }

(1) Divide row 2 by three:

1
3

R
2

{\displaystyle \frac{1}{3} R\_2 }

[

2

5

−
13

1000

1

−
3

1

0

−
5

6

8

−
600

]

{\displaystyle
\begin{bmatrix}
2 & 5 & -13 & 1000 \\
1 & -3 & 1 & 0 \\
-5 & 6 & 8 & -600
\end{bmatrix} }

(2) Subtract row 1 by two times row 2:

R
1

−
2

R
2

{\displaystyle R\_1 - 2R\_2 }

[

0

11

−
15

1000

1

−
3

1

0

−
5

6

8

−
600

]

{\displaystyle
\begin{bmatrix}
0 & 11 & -15 & 1000 \\
1 & -3 & 1 & 0 \\
-5 & 6 & 8 & -600
\end{bmatrix} }

(3) Add row 3 by five times row 2:

R
3

5

R
2

{\displaystyle R\_3 + 5R\_2 }

[

0

11

−
15

1000

1

−
3

1

0

0

−
9

13

−
600

]

{\displaystyle
\begin{bmatrix}
0 & 11 & -15 & 1000 \\
1 & -3 & 1 & 0 \\
0 & -9 & 13 & -600
\end{bmatrix} }

(4) Add row 1 by row 3:

R
1

R
3

{\displaystyle R\_1 + R\_3 }

[

0

2

−
2

400

1

−
3

1

0

0

−
9

13

−
600

]

{\displaystyle
\begin{bmatrix}
0 & 2 & -2 & 400 \\
1 & -3 & 1 & 0 \\
0 & -9 & 13 & -600
\end{bmatrix} }

(5) Divide row 1 by two:

1
2

R
1

{\displaystyle \frac{1}{2}R\_1 }

[

0

1

−
1

200

1

−
3

1

0

0

−
9

13

−
600

]

{\displaystyle
\begin{bmatrix}
0 & 1 & -1 & 200 \\
1 & -3 & 1 & 0 \\
0 & -9 & 13 & -600
\end{bmatrix} }

(6) Add nine times row 1 to row 3:

R
3

9

R
1

{\displaystyle R\_3 + 9R\_1 }

[

0

1

−
1

200

1

−
3

1

0

0

0

4

1200

]

{\displaystyle
\begin{bmatrix}
0 & 1 & -1 & 200 \\
1 & -3 & 1 & 0 \\
0 & 0 & 4 & 1200
\end{bmatrix} }

(7) Divide row 3 by four:

1
4

R
3

{\displaystyle \frac{1}{4}R\_3}

[

0

1

−
1

200

1

−
3

1

0

0

0

1

300

]

{\displaystyle
\begin{bmatrix}
0 & 1 & -1 & 200 \\
1 & -3 & 1 & 0 \\
0 & 0 & 1 & 300
\end{bmatrix} }

(8) Add row 3 to row 1:

R
1

R
3

{\displaystyle R\_1 + R\_3 }

[

0

1

0

500

1

−
3

1

0

0

0

1

300

]

{\displaystyle
\begin{bmatrix}
0 & 1 & 0 & 500 \\
1 & -3 & 1 & 0 \\
0 & 0 & 1 & 300
\end{bmatrix} }

​(9) Subtract row 2 by row 3:

R
2

−

R
3

{\displaystyle R\_2 - R\_3 }

[

0

1

0

500

1

−
3

0

−
300

0

0

1

300

]

{\displaystyle
\begin{bmatrix}
0 & 1 & 0 & 500 \\
1 & -3 & 0 & -300 \\
0 & 0 & 1 & 300
\end{bmatrix} }

(10) Add three times row 1 to row 2:

R
2

3

R
1

{\displaystyle R\_2 + 3R\_1 }

[

0

1

0

500

1

0

0

1200

0

0

1

300

]

{\displaystyle
\begin{bmatrix}
0 & 1 & 0 & 500 \\
1 & 0 & 0 & 1200 \\
0 & 0 & 1 & 300
\end{bmatrix} }

(11) Swap row 1 with row 2:

R
1

↔

R
2

{\displaystyle R\_1 \leftrightarrow R\_2 }

[

1

0

0

1200

0

1

0

500

0

0

1

300

]

{\displaystyle
\begin{bmatrix}
1 & 0 & 0 & 1200 \\
0 & 1 & 0 & 500 \\
0 & 0 & 1 & 300
\end{bmatrix} }