Linear systems in use: networks, chemical equations, fitting curves
Traffic around a block, atoms in a reaction, a curve through measured points. Why does each one come down to a single linear system, and what does the solution set say about it?
Where you are 7 in Row reduction
When you reach for it
Reach for a linear system whenever a situation is described by quantities that must add up: cars into a corner equal cars out, atoms of each element before a reaction equal atoms after, and the height of a curve at each measured point equals the measurement. Each such requirement is one linear equation, and the whole situation is one system A\mathbf{x} = \mathbf{b}.
The work is in setting it up. Solving is already known: row reduce and write the answer as in Homogeneous systems and solutions in parametric vector form, one particular solution plus the homogeneous ones, \mathbf{x} = \mathbf{p} + \mathbf{v}_h. What is new is reading that answer back: a free variable is a real freedom in the network, the null space of a reaction is its set of balanced forms, and a unique solution is a curve the points pin down.
The procedure
Day 1: networks and chemical equations
Networks. A network is a set of junctions (nodes) joined by branches, with something flowing along each branch: cars, water, current. Give each branch an unknown flow x_1, x_2, \dots and a direction. The one law is conservation at each node: nothing is stored or created there, so
That is one linear equation per node, with the flows that enter or leave the network from outside as constants. Two features of the answer recur. First, in a connected network every branch leaves one node and enters another, so adding all the node equations cancels every unknown and leaves “total entering the network = total leaving it”. One node equation is therefore always a combination of the others: if the totals agree it reduces to 0 = 0, and if they do not, the system is inconsistent. Second, flow that runs around a closed loop enters and leaves every node equally, so it is invisible to the equations. Each independent loop shows up as a free variable, and the homogeneous solutions are exactly these circulations.
A one-way street cannot carry negative flow. That is an inequality, x_i \ge 0, not part of the linear system: solve the system first, then ask which values of the free variables keep every flow nonnegative.
Chemical equations. A reaction such as \mathrm{CO_2} + \mathrm{H_2O} \to \mathrm{C_6H_{12}O_6} + \mathrm{O_2} is balanced when each element has as many atoms on the left as on the right. Put an unknown coefficient x_i in front of each compound. Each element gives one equation, “atoms on the left = atoms on the right”, and moving everything to the left makes it homogeneous. So balancing means finding the null space of a matrix with one row per element and one column per compound, with a minus sign on the columns of the products.
The system is homogeneous, so it is always consistent, and when there are more compounds than elements it has nontrivial solutions automatically. In the usual case the null space is a line, \operatorname{span}\{\mathbf{v}\}: every balanced form is a multiple of one vector. The balanced equation chemists write is the multiple whose entries are positive whole numbers with no common factor. Positive, because the compounds stay on the sides they were written on; whole numbers, because the coefficients count molecules; and no common factor, because the equation records a ratio, and (12, 12, 2, 12) says nothing that (6, 6, 1, 6) does not.
Day 2: a polynomial through given points
Given points (x_1, y_1), \dots, (x_n, y_n), look for a polynomial
with p(x_i) = y_i for each i. The unknowns are the coefficients a_0, \dots, a_{n-1}, not x. Each x_i is a known number, so the condition p(x_i) = y_i reads
which is linear in the a’s even though p is not linear in x. The n conditions form a square system V\mathbf{a} = \mathbf{y} whose ith row is 1, x_i, x_i^2, \dots, x_i^{n-1}. This V is the Vandermonde matrix of the points. Other conditions that are linear in the coefficients join the system the same way; a required slope p'(x_0) = m, for instance, is the row 0, 1, 2x_0, 3x_0^2, \dots (Example 6).
Theorem. If x_1, \dots, x_n are distinct, then for any y_1, \dots, y_n there is exactly one polynomial of degree at most n - 1 with p(x_i) = y_i for every i.
Proof. First the homogeneous system. If V\mathbf{a} = \mathbf{0}, the polynomial with coefficients \mathbf{a} is 0 at the n distinct numbers x_1, \dots, x_n. A polynomial of degree at most n - 1 that is not the zero polynomial has at most n - 1 roots, since by the The remainder and factor theorems each root r contributes a factor x - r and the degrees of the factors add. So p is the zero polynomial and \mathbf{a} = \mathbf{0}. Since V\mathbf{a} = \mathbf{0} has only the trivial solution, there is no free variable, so all n columns of V have pivots. There are only n rows, so every row has a pivot, no row can reduce to 0 = c with c \neq 0, and V\mathbf{a} = \mathbf{y} is consistent for every \mathbf{y}. Its solution is unique because \mathbf{x} = \mathbf{p} + \mathbf{v}_h with \mathbf{v}_h = \mathbf{0} the only choice. \square
The same fact can be read from a number: the determinant of V is the product of all the differences x_j - x_i with i < j, which is nonzero exactly when the x_i are distinct. That formula is stated here without proof.
If two of the x_i are equal, two rows of V are equal and the theorem says nothing. Example 5 shows what happens then.
Worked examples
Day 1: the one-way streets around a block
Csaba counts traffic around one downtown block whose corners are P (northwest), Q (northeast), R (southeast) and S (southwest). The four streets are one-way, clockwise: x_1 from P to Q, x_2 from Q to R, x_3 from R to S and x_4 from S to P, in cars an hour. From outside, 400 cars an hour enter at P, 250 leave at Q, 300 enter at R and 450 leave at S. Find every possible set of flows, the least flow each street can carry, and which streets could be closed.
At each corner, cars in equal cars out:
With the unknowns on the left, the augmented matrix is
and row 2 minus row 1, then times -1, row 3 plus the new row 2, and row 4 minus the new row 3 reduce it to
The zero row is the redundant corner: 700 cars enter and 700 leave. The variable x_4 is free; call it t:
The homogeneous part t(1, 1, 1, 1) is t cars an hour circling the block, which every corner passes on unchanged. Counts taken outside the block cannot see them, so the data do not fix the flows.
Every street is one-way, so t = x_4 \ge 0, and then x_1 = t + 400 \ge 400, x_2 = t + 150 \ge 150 and x_3 = t + 450 \ge 450. These least flows all occur together, at t = 0. Only street x_4 can be closed: closing it forces the flows (400, 150, 450, 0). Closing x_2 would need t = -150, a flow of 150 cars an hour driving from P to S against the one-way sign, so the 250 cars leaving at Q have no other way to arrive.
Day 1: a reaction whose null space is one line
Balance the decomposition of ammonium dichromate,
One molecule of \mathrm{(NH_4)_2Cr_2O_7} holds 2 nitrogen, 8 hydrogen, 2 chromium and 7 oxygen atoms. Counting each element on both sides:
Moving everything left, the coefficient matrix is
The oxygen row became zero: once nitrogen, hydrogen and chromium balance, x_2 = x_1 and x_4 = 4x_1, so oxygen reads 7x_1 = 3x_1 + 4x_1 and balances by itself. The rank is 3, and x_4 = t is free:
so the null space is \operatorname{span}\{(1, 1, 1, 4)\}.
The whole-number multiples are t = 4, 8, 12, \dots, and the smallest, t = 4, gives
Check: oxygen is 7 on the left and 3 + 4 on the right.
Day 1: photosynthesis, with a free variable chosen well
In the school chemistry lab, Gergo asks for the balanced form of photosynthesis, x_1\,\mathrm{CO_2} + x_2\,\mathrm{H_2O} \to x_3\,\mathrm{C_6H_{12}O_6} + x_4\,\mathrm{O_2} in general.
SolutionThree elements give three equations in four unknowns:
With more unknowns than equations, a nontrivial solution is guaranteed before any work is done. Take x_3 = t as the free variable, because every other count is a multiple of it. Carbon gives x_1 = 6t, hydrogen gives x_2 = 6t, and oxygen gives 12t + 6t = 6t + 2x_4, so x_4 = 6t:
The rank is 3, so this line is the whole null space. Every t > 0 balances the atoms, t = 2 gives (12, 12, 2, 12), but only t = 1 leaves no common factor:
A negative t describes the reverse reaction, sugar burning in oxygen.
Day 2: the cubic through four points
Find the polynomial of degree at most 3 through (-2, -15), (0, 1), (1, 3) and (3, 25).
SolutionWrite p(x) = a_0 + a_1x + a_2x^2 + a_3x^3. Each point is one row 1, x_i, x_i^2, x_i^3 of the Vandermonde system:
The point at x = 0 gives a_0 = 1 at once. Putting that into the other rows and dividing the first by -2 and the last by 3:
Subtracting the first equation from the second gives 3a_2 - 3a_3 = -6, so a_2 - a_3 = -2. Subtracting the second from the third gives 2a_2 + 8a_3 = 6, so a_2 + 4a_3 = 3. Then 5a_3 = 5, so a_3 = 1, a_2 = -1 and a_1 = 2 - a_2 - a_3 = 2:
Check: p(-2) = -8 - 4 - 4 + 1 = -15 and p(3) = 27 - 9 + 6 + 1 = 25. The four x values are distinct, so by the theorem this is the only polynomial of degree at most 3 through the points.
Day 2: two points with the same x
(a) Is there a quadratic through (2, 3), (2, 5) and (4, 1)? (b) Find every quadratic through (2, 3) and (4, 1).
Solution(a) With p(x) = a_0 + a_1x + a_2x^2, the two points at x = 2 give rows with the same left side and different right sides:
The middle row says 0 = 2, so there is no quadratic, and no polynomial of any degree: a function has one value at x = 2, not two.
(b) Two conditions on three coefficients leave a free variable. A particular solution is the line through the points, 5 - x, with coefficients (5, -1, 0). The homogeneous solutions are the quadratics that are 0 at x = 2 and x = 4, the multiples of (x - 2)(x - 4) = x^2 - 6x + 8. So, as particular plus homogeneous,
that is, p(x) = 5 - x + t(x^2 - 6x + 8).
A repeated point, such as (2, 3) twice, gives this same answer.
Day 2: a ramp profile with slopes
Sirpa designs the curved profile of a skatepark ramp as y = a_0 + a_1x + a_2x^2 + a_3x^3 for 0 \le x \le 3, in meters. It must leave the ground level, so y(0) = 0 and y'(0) = 0, and meet the flat deck 1.5 meters up, so \displaystyle y(3) = \frac{3}{2} and y'(3) = 0. Find the profile.
SolutionThe slope is y' = a_1 + 2a_2x + 3a_3x^2, which is also linear in the coefficients, so a slope condition is one more row: 0, 1, 2x, 3x^2. The four conditions give
The first two rows give a_0 = a_1 = 0. The others become \displaystyle 9a_2 + 27a_3 = \frac{3}{2} and 6a_2 + 27a_3 = 0. Subtracting, \displaystyle 3a_2 = \frac{3}{2}, so \displaystyle a_2 = \frac{1}{2}, and then 27a_3 = -3, so \displaystyle a_3 = -\frac{1}{9}:
Check: \displaystyle y(3) = \frac{9}{2} - 3 = \frac{3}{2} and y'(3) = 3 - 3 = 0. Halfway along, y(1.5) = 1.125 - 0.375 = 0.75 meters, half the deck height, as the symmetry of the conditions suggests.
Boundaries
Networks need conservation. The node equations hold only if nothing is stored at a node; a parking garage at a corner breaks them. If the outside flows do not balance, the system has no solution. The equations never see flow around a closed loop, so outside counts alone cannot fix the flows in a network with a loop. Nonnegative flow on one-way branches is a separate inequality, applied after solving.
Balancing conserves atoms and nothing else. It says what ratio is consistent, not whether the reaction happens. For ions, charge must balance too, which is one more row. If the null space has dimension 2 or more, the compounds can take part in two independent reactions and no single balanced form exists; if no vector in the null space has all entries positive, the equation cannot be balanced as written.
One polynomial needs distinct x values and the right degree. With n distinct x values the degree-at-most-(n - 1) polynomial exists and is unique. Two equal x values give either no solution or a repeated condition (Example 5). Fewer coefficients than points (a line through three points) usually gives an inconsistent system; the best approximate answer is the subject of Least squares: the best approximate solution of Ax = b. More coefficients than conditions give infinitely many.
An exact fit can be a poor model. The polynomial passes through the points but may swing far from the data between them, and for many points the Vandermonde system is sensitive to rounding: small errors in the data can move the coefficients a great deal.
Where this goes next
The balanced forms of a reaction are the kernel of its element matrix, and the circulations of a network are the kernel of its node matrix. Fitting a polynomial is solving V\mathbf{a} = \mathbf{y} for a square V that is invertible exactly when the x_i are distinct, an instance of the The invertible matrix theorem, and its determinant makes that a single number to compute. The map from coefficients \mathbf{a} to values (p(x_1), \dots, p(x_n)) is a Linear transformation, which is why the problem is linear at all. When the data have more points than the model has coefficients, an exact fit is gone and Least squares: the best approximate solution of Ax = b finds the closest one.
Exercises
Day 1: networks
Exercises 1 to 3 use Csaba’s block from Example 1, with the same four one-way streets and new outside counts.
- 500 cars an hour enter at P, 200 leave at Q, 100 enter at R and 400 leave at S. Find the general solution and the least flow on each street.
- 300 enter at P, 400 leave at Q, 350 enter at R and 250 leave at S. Find the general solution, the least flow on each street, and which street could be closed.
- 400 enter at P, 250 leave at Q, 300 enter at R and 400 leave at S. Show that no flows fit, and say why without row reducing.
- In Gergo’s lab, one-way cooling pipes join junctions A, B, C, D, in liters per minute: x_1 from A to B, x_2 from B to C, x_3 from C to D, x_4 from D to A and x_5 from A to C. Water enters at A at 50 and leaves at B at 30, at C at 10 and at D at 10. Find the general solution in parametric vector form. If pipe x_4 is shut, what is the largest possible flow in pipe x_5?
Day 1: balancing chemical equations
Set up the homogeneous system, find its null space, and give the balanced equation.
- x_1\,\mathrm{KClO_3} \to x_2\,\mathrm{KCl} + x_3\,\mathrm{O_2}
- x_1\,\mathrm{Fe} + x_2\,\mathrm{O_2} \to x_3\,\mathrm{Fe_2O_3}
- x_1\,\mathrm{C_2H_6} + x_2\,\mathrm{O_2} \to x_3\,\mathrm{CO_2} + x_4\,\mathrm{H_2O}
- x_1\,\mathrm{Al} + x_2\,\mathrm{HCl} \to x_3\,\mathrm{AlCl_3} + x_4\,\mathrm{H_2}
- x_1\,\mathrm{Cu} + x_2\,\mathrm{HNO_3} \to x_3\,\mathrm{Cu(NO_3)_2} + x_4\,\mathrm{NO} + x_5\,\mathrm{H_2O}
Day 2: polynomials through points
- Find the quadratic through (-1, 8), (1, 2) and (2, 5).
- Find the polynomial of degree at most 3 through (-1, 2), (0, 1), (1, 2) and (2, 11).
- Find the polynomial of degree at most 3 through (1, 0), (2, 0), (3, 0) and (4, 6).
- Is there a quadratic through (1, 1), (3, 5) and (3, 7)?
- Find every quadratic through (0, 2) and (2, 6), as particular plus homogeneous.
- Sirpa tries a second profile y = a_0 + a_1x + a_2x^2 + a_3x^3 that leaves the ground level, y(0) = 0 and y'(0) = 0, and passes through heights 0.5 meters at x = 2 and 2.4 meters at x = 4. Find it.
- Is there a line y = a_0 + a_1x through (0, 1), (1, 3) and (2, 4)?
Reasoning
- Explain why, in any connected network, the sum of all the node equations has no unknowns left in it, and what that says about the rank of the system.
- Explain why a chemical equation with more compounds than elements always has a nonzero solution, and why that alone does not guarantee a balanced form with all coefficients positive.
- Prove directly that two polynomials of degree at most n - 1 that agree at n distinct numbers are the same polynomial.
- In Example 1, explain in terms of cars why adding (1, 1, 1, 1) to any solution gives another solution, and why no outside count could ever reveal t.
- Explain why n points with distinct x values usually have no polynomial through them of degree less than n - 1, but infinitely many of degree at most n.
Answers
- \mathbf{x} = (500, 300, 400, 0) + t(1, 1, 1, 1) with t \ge 0. Corner equations: x_1 - x_4 = 500, x_1 - x_2 = 200, x_3 - x_2 = 100, x_3 - x_4 = 400. Least flows 500, 300, 400, 0, all at t = 0.
- \mathbf{x} = (300, -100, 250, 0) + t(1, 1, 1, 1) in general. Here x_2 = t - 100 \ge 0 forces t \ge 100, so the least flows are x_1 = 400, x_2 = 0, x_3 = 350, x_4 = 100, all at t = 100. Only street x_2 can be closed; closing x_4 would make x_2 = -100.
- Reducing as in Example 1 leaves the last row 0 = -50. Without reducing: 700 cars an hour enter but only 650 leave, and the sum of the corner equations says these totals must agree.
- \mathbf{x} = (50, 20, 10, 0, 0) + s(1, 1, 1, 1, 0) + t(-1, -1, 0, 0, 1) from x_1 + x_5 - x_4 = 50, x_1 - x_2 = 30, x_2 + x_5 - x_3 = 10, x_3 - x_4 = 10, with x_4 = s and x_5 = t free. The two loops are the outer ring and the short cut A \to C replacing A \to B \to C. With s = 0, x_2 = 20 - t \ge 0 gives the largest flow x_5 = 20, with flows (30, 0, 10, 0, 20).
- 2\,\mathrm{KClO_3} \to 2\,\mathrm{KCl} + 3\,\mathrm{O_2} is balanced. K and Cl both give x_1 = x_2, O gives 3x_1 = 2x_3; the null space is \operatorname{span}\{(2, 2, 3)\}.
- 4\,\mathrm{Fe} + 3\,\mathrm{O_2} \to 2\,\mathrm{Fe_2O_3} is balanced. Fe: x_1 = 2x_3; O: 2x_2 = 3x_3; null space \operatorname{span}\{(4, 3, 2)\}.
- 2\,\mathrm{C_2H_6} + 7\,\mathrm{O_2} \to 4\,\mathrm{CO_2} + 6\,\mathrm{H_2O} is balanced. C: 2x_1 = x_3; H: 6x_1 = 2x_4; O: 2x_2 = 2x_3 + x_4. With x_1 = t: x_3 = 2t, x_4 = 3t, \displaystyle x_2 = \frac{7}{2}t; t = 2 clears the fraction. Null space \operatorname{span}\{(2, 7, 4, 6)\}.
- 2\,\mathrm{Al} + 6\,\mathrm{HCl} \to 2\,\mathrm{AlCl_3} + 3\,\mathrm{H_2} is balanced. Al: x_1 = x_3; H: x_2 = 2x_4; Cl: x_2 = 3x_3. Null space \operatorname{span}\{(2, 6, 2, 3)\}.
- 3\,\mathrm{Cu} + 8\,\mathrm{HNO_3} \to 3\,\mathrm{Cu(NO_3)_2} + 2\,\mathrm{NO} + 4\,\mathrm{H_2O} is balanced. Cu: x_1 = x_3; H: x_2 = 2x_5; N: x_2 = 2x_3 + x_4; O: 3x_2 = 6x_3 + x_4 + x_5. The rank is 4, so the null space is the line \operatorname{span}\{(3, 8, 3, 2, 4)\}.
- p(x) = 2x^2 - 3x + 3. The rows at x = \pm 1 subtract to 2a_1 = -6; then a_0 + a_2 = 5 and a_0 + 4a_2 = 11 give a_2 = 2, a_0 = 3.
- p(x) = x^3 + x^2 - x + 1. a_0 = 1; the rows at x = \pm 1 give a_2 = 1 and a_1 + a_3 = 0; the row at x = 2 gives 2a_1 + 8a_3 = 6, so a_3 = 1, a_1 = -1.
- p(x) = x^3 - 6x^2 + 11x - 6. Solving the Vandermonde system gives coefficients (-6, 11, -6, 1); it is (x - 1)(x - 2)(x - 3), the polynomial that is 0 at the first three points and 6 at x = 4.
- No. The two rows at x = 3 are 1, 3, 9 with right sides 5 and 7, and subtracting them gives 0 = 2.
- (a_0, a_1, a_2) = (2, 2, 0) + t(0, -2, 1) or p(x) = 2 + 2x + t(x^2 - 2x). The line 2 + 2x fits both points, and x^2 - 2x = x(x - 2) is 0 at both.
- \displaystyle y = \frac{1}{10}x^2 + \frac{1}{80}x^3. The level start gives a_0 = a_1 = 0; then 4a_2 + 8a_3 = 0.5 and 16a_2 + 64a_3 = 2.4. Four times the first is 16a_2 + 32a_3 = 2, so 32a_3 = 0.4, \displaystyle a_3 = \frac{1}{80} and \displaystyle a_2 = \frac{1}{10}.
- No. The first two points force a_0 = 1 and a_1 = 2, and then y(2) = 5, not 4; reduction gives 0 = -1. The best line in the least-squares sense comes later.
- Each branch joins two nodes; its flow appears as “in” at one and “out” at the other, so in the sum it cancels. Only the outside flows remain, saying total in equals total out. So one node equation is a combination of the others and the rank is at most the number of nodes minus 1.
- The system is homogeneous with one equation per element and one unknown per compound. With more unknowns than equations there is a column without a pivot, hence a free variable and a nonzero solution. But a null space vector may have entries of both signs; then some compound would have to switch sides, and the equation cannot be balanced as written.
- If p(x_i) = q(x_i) for n distinct x_i, then p - q has degree at most n - 1 and n roots. A nonzero polynomial of degree at most n - 1 has at most n - 1 roots, by the factor theorem, so p - q is the zero polynomial and p = q.
- Adding 1 to every street is one more car an hour driving round the block; it enters and leaves each corner once, so every corner still balances. Outside counts measure only what crosses the boundary, and a circling car never does, so every value of t gives the same counts.
- Degree less than n - 1 gives fewer than n unknowns in n equations, so the reduced matrix has a zero row on the left, and unless the right side is 0 there the system is inconsistent. Degree at most n gives n + 1 unknowns; the first n columns form the square Vandermonde matrix, with a pivot in every row, so the system is consistent, and the last column has no pivot, so there are infinitely many solutions.