Writing a system as a matrix equation
A system of equations is a stack of separate lines, each repeating the same letters. Can the whole stack be written as one equation, so that matrix arithmetic can work on all of it at once?
Where you are 12 in Matrices
When you reach for it
A linear system such as
carries three kinds of information: the numbers multiplying the variables, the variables themselves, and the numbers on the right. Elimination copies the letters x and y over and over, although only the numbers ever change.
Writing the system as a matrix equation AX = B puts the three kinds of information in three matrices and packs the whole system into one statement. You reach for it whenever a system is to be handled with matrices: by row operations, an inverse matrix, Cramer’s rule, or a calculator.
The procedure
The three matrices
Take a system of m linear equations in n variables, each equation written with the variable terms on the left, in the same order in every equation, and the constant on the right.
- The coefficient matrix A is m \times n. Row i holds the coefficients of equation i; column j holds every coefficient of variable j. A variable that does not appear in an equation has coefficient 0 there. A variable with no number written in front, as in x or -y, has coefficient 1 or -1.
- The variable matrix X is the n \times 1 column of variables, in the chosen order.
- The constant matrix B is the m \times 1 column of right-hand sides.
For the system above,
and the system becomes
Why the one equation is the whole system
The product AX is (m \times n)(n \times 1): the inner sizes match, so by the row-by-column rule it exists and is m \times 1, the same size as B. Its entry in row i is row i of A times the column X: the first coefficient times the first variable, plus the second times the second, and so on. That sum is exactly the left side of equation i. Here
Two matrices are equal when they have the same size and every pair of matching entries is equal (as in Rows, columns and dimensions). So AX = B says 5x + 2y = 12 and 3x - 4y = 2: one equation between columns is m equations between numbers. It follows that a column X of numbers makes AX = B true exactly when those numbers solve every equation of the system. The matrix equation and the system have the same solutions, because they are the same statement.
Two habits follow from the argument. Line every equation up first, since row i of A must be read against the same list of variables as every other row; a coefficient in the wrong column multiplies the wrong variable. And to check the work, multiply AX back out: the rows must reproduce the original equations.
Read the other way, any matrix equation AX = B with X a column of variables can be read back as a system: each row of A, paired with the matching entry of B, is one equation.
Worked examples
Writing a system and multiplying back
Write the system 5x + 2y = 12, 3x - 4y = 2 as a matrix equation, and check it by multiplying out.
SolutionBoth equations already have x first, then y, with the constant on the right. The coefficients of the first equation, 5 and 2, form row 1 of A; those of the second, 3 and -4, form row 2. The minus sign belongs to the coefficient, because 3x - 4y = 3x + (-4)y.
Check: row 1 times X is 5x + 2y, and row 2 times X is 3x + (-4)y = 3x - 4y. Setting these equal to the entries 12 and 2 of B gives back the two equations.
Testing a column
For the matrix equation of Example 1, decide whether X = \begin{bmatrix} 2 \\ 1 \end{bmatrix} and X = \begin{bmatrix} 4 \\ -4 \end{bmatrix} are solutions.
SolutionA column is a solution exactly when AX comes out equal to B, so multiply.
This is B, so x = 2, y = 1 solves the system.
The first entry matches, so (4, -4) satisfies the first equation, but 28 \ne 2. Equal matrices need every entry equal, so (4, -4) is not a solution.
Lining the equations up first
Write as a matrix equation: y = 4 - 3x, 2x = 5y + 1.
SolutionThe variables are scattered on both sides, so first rewrite each equation with x, then y, on the left. Adding 3x to both sides of the first gives 3x + y = 4; the coefficient of y is 1. Subtracting 5y from both sides of the second gives 2x - 5y = 1. Adding the same term to both sides keeps every solution, so the system is unchanged. Now
Multiplying out gives 3x + y and 2x - 5y, the rearranged left sides.
Three variables, some missing
Write as a matrix equation and check by multiplying out:
Use the order x, y, z, so X has those three entries and A has three columns. The second equation has no x, so its coefficient of x is 0, and its terms are listed z first, so they must be put back in order: 0x + 3y + 4z = -1. The third has no y: 2x + 0y - z = 5. The first has unwritten coefficients 1 and -1.
Check, row by row:
These are the three left sides, in order. The zeros cannot be dropped: without them row 2 would have only two entries, and a row of A must have one entry for each variable.
Reading a matrix equation back
Write the system that this matrix equation stands for:
Each row of A times the column of variables, set equal to the matching entry of B, is one equation. A 0 entry means that variable is absent from the equation.
More variables than equations
Write x - 2y + 5z = 3, 4x + y - z = 0 as a matrix equation, and give the size of each matrix.
SolutionThere are m = 2 equations in n = 3 variables, so A is 2 \times 3, X is 3 \times 1 and B is 2 \times 1:
The product is (2 \times 3)(3 \times 1), which is 2 \times 1, the size of B. The column X has three entries, one per variable, while B has two, one per equation. A need not be square.
Setting up a word problem
Layla, Nabil and Samir run the school woodshop’s spring sale. They plan to build cutting boards, stools and shelves. A cutting board takes 2 board feet of lumber, 1 hour of sanding and 3 ounces of oil finish; a stool takes 5 board feet, 2 hours and 4 ounces; a shelf takes 4 board feet, 3 hours and 2 ounces. They have 68 board feet of lumber, 38 hours of sanding time and 64 ounces of oil, and want to use all of each. Write the conditions as a matrix equation, and check Nabil’s plan of 12 cutting boards, 4 stools and 6 shelves.
SolutionLet c, s and h be the numbers of cutting boards, stools and shelves. Each resource gives one equation: the amount used per item times the number of items, added over the three items, equals the amount on hand.
Each row of A is one resource and each column one item:
For Nabil’s plan, multiply:
The product equals B, so the plan uses exactly the lumber, sanding time and oil on hand. Here the plan was given; finding one from scratch is what row reduction does.
Boundaries
- Linear equations only. Each entry of AX is a sum of constants times single variables. An equation with xy, x^2, \displaystyle \frac{1}{x} or \sin x has a term of no such form and cannot be written this way.
- Coefficients are constants. An entry of A cannot contain a variable of X; a term such as x \cdot y is not “coefficient x times y”.
- One variable order for every row. The columns of A and the entries of X follow a single order. Writing one row in a different order produces a matrix equation for a different system.
- A comes first. The product XA is (n \times 1)(m \times n), which is undefined unless m = 1, and even then it is not the system. Matrix multiplication is not commutative.
- Writing is not solving. Every linear system can be written as AX = B, whether it has one solution, none or infinitely many. The matrix equation has the same solutions as the system and does not decide which case holds.
Where this goes next
Once a system is AX = B, the letters can be dropped altogether. Setting B beside A gives the augmented matrix of Augmented matrices and row operations, where elimination becomes operations on rows. When A is square and has an inverse, multiplying both sides by it gives X = A^{-1}B, the method of Inverse of a 2 by 2 matrix, and solving with it; whether that inverse exists is decided by the determinant, and Cramer's rule writes each variable as a ratio of determinants. Read column by column instead of row by row, AX is a combination of the columns of A, so solving the system asks which combination of those columns makes B.
Exercises
Write the system as a matrix equation
- 3x + 7y = 1, 2x - y = 9
- x - y = 0, 6x + 5y = -8
- 2x + y - 3z = 8, x - 4y + z = -2, 5x + 2y + 6z = 0
- p + q = 6, 2q - r = 1, 3p + 5r = -4
- y = 2x + 5, 3x = 4 - y
- \displaystyle \frac{x}{2} + \frac{y}{3} = 1, \displaystyle \frac{2}{5}x - y = 2
- z = x + y, 2x + z = 7 + y, x - 3 = 2y
Read it back as a system
- \begin{bmatrix} 4 & -3 \\ 1 & 6 \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 10 \\ -5 \end{bmatrix}
- \begin{bmatrix} 1 & 0 & -2 \\ 0 & 3 & 1 \\ -1 & 1 & 0 \end{bmatrix}\begin{bmatrix} u \\ v \\ w \end{bmatrix} = \begin{bmatrix} 5 \\ 0 \\ 2 \end{bmatrix}
- \begin{bmatrix} 2 & -1 & 3 \\ 0 & 1 & -4 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} 1 \\ 6 \end{bmatrix}. How many equations and how many variables does the system have?
Test a column
- Write 2x + 5y = 1, x - 3y = 6 as AX = B. Decide whether (3, -1) and (-2, 1) are solutions by computing AX.
- Write x + 2y + z = 1, 2x - z = -2, y + 3z = 10 as AX = B, and decide whether (1, -2, 4) is a solution.
- The column \begin{bmatrix} 2 \\ 5 \end{bmatrix} solves \begin{bmatrix} k & 2 \\ 3 & -1 \end{bmatrix}X = \begin{bmatrix} 16 \\ 1 \end{bmatrix}. Find k, and check the other row.
In the woodshop
- Nabil sells cutting boards at 18 dollars and stools at 45 dollars. He sells 20 items and takes in 576 dollars. Write the conditions as AX = B with X = \begin{bmatrix} c \\ s \end{bmatrix}, and check that 12 cutting boards and 8 stools fit.
- Samir builds small, medium and large planter boxes, selling at 12, 20 and 30 dollars. He sells 30 boxes for 544 dollars, and sells three times as many small boxes as large ones. Write AX = B with X = \begin{bmatrix} s \\ m \\ l \end{bmatrix}, and check that 12 small, 14 medium and 4 large fit.
- Layla’s plan for cutting boards b and shelves h is written as \begin{bmatrix} 1 & 1 \\ 2 & 4 \end{bmatrix}\begin{bmatrix} b \\ h \end{bmatrix} = \begin{bmatrix} 25 \\ 68 \end{bmatrix}, where row 1 counts items and row 2 counts board feet of lumber. Write the two equations, say what each one states, and check whether 16 cutting boards and 9 shelves fit.
Reasoning
- A system has 3 equations in 4 variables. Give the sizes of A, X and B, and explain each from the row-by-column rule.
- In the system 2x + y = 5, y - x = 1, the second equation lists y before x. Write the system as a matrix equation with X = \begin{bmatrix} x \\ y \end{bmatrix}. Then explain why \begin{bmatrix} 2 & 1 \\ 1 & -1 \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 5 \\ 1 \end{bmatrix} states a different system.
- Samir multiplies the second equation of Example 1 by 3 before writing the matrix equation. His A and B differ from those in Example 1. Explain why his matrix equation still has exactly the same solutions.
- Explain why \begin{bmatrix} 0 & 0 \\ 1 & 2 \end{bmatrix}X = \begin{bmatrix} 3 \\ 1 \end{bmatrix} has no solution. What changes if the 3 is replaced by 0?
Answers
- A = \begin{bmatrix} 3 & 7 \\ 2 & -1 \end{bmatrix}, X = \begin{bmatrix} x \\ y \end{bmatrix}, B = \begin{bmatrix} 1 \\ 9 \end{bmatrix}. The coefficient of -y is -1.
- \begin{bmatrix} 1 & -1 \\ 6 & 5 \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 0 \\ -8 \end{bmatrix}. The constant 0 takes its place in B.
- \begin{bmatrix} 2 & 1 & -3 \\ 1 & -4 & 1 \\ 5 & 2 & 6 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} 8 \\ -2 \\ 0 \end{bmatrix}.
- \begin{bmatrix} 1 & 1 & 0 \\ 0 & 2 & -1 \\ 3 & 0 & 5 \end{bmatrix}\begin{bmatrix} p \\ q \\ r \end{bmatrix} = \begin{bmatrix} 6 \\ 1 \\ -4 \end{bmatrix}. Each missing variable gets a 0.
- Rearranged: -2x + y = 5 and 3x + y = 4, so \begin{bmatrix} -2 & 1 \\ 3 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 5 \\ 4 \end{bmatrix}.
- \displaystyle \begin{bmatrix} \frac{1}{2} & \frac{1}{3} \\ \frac{2}{5} & -1 \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 1 \\ 2 \end{bmatrix}. Multiplying the equations by 6 and 5 first gives the equally correct \begin{bmatrix} 3 & 2 \\ 2 & -5 \end{bmatrix}X = \begin{bmatrix} 6 \\ 10 \end{bmatrix}, with the same solutions.
- Rearranged: x + y - z = 0, 2x - y + z = 7, x - 2y = 3, so \begin{bmatrix} 1 & 1 & -1 \\ 2 & -1 & 1 \\ 1 & -2 & 0 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} 0 \\ 7 \\ 3 \end{bmatrix}.
- 4x - 3y = 10 and x + 6y = -5.
- u - 2w = 5, 3v + w = 0 and -u + v = 2. Each 0 marks a missing variable.
- 2x - y + 3z = 1 and y - 4z = 6: two equations (A has two rows) in three variables (A has three columns).
- A = \begin{bmatrix} 2 & 5 \\ 1 & -3 \end{bmatrix}, B = \begin{bmatrix} 1 \\ 6 \end{bmatrix}. For (3, -1), AX = \begin{bmatrix} 1 \\ 6 \end{bmatrix}, a solution. For (-2, 1), AX = \begin{bmatrix} 1 \\ -5 \end{bmatrix}, not a solution: the second entry is -5, not 6.
- A = \begin{bmatrix} 1 & 2 & 1 \\ 2 & 0 & -1 \\ 0 & 1 & 3 \end{bmatrix}, B = \begin{bmatrix} 1 \\ -2 \\ 10 \end{bmatrix}. AX = \begin{bmatrix} 1 - 4 + 4 \\ 2 - 4 \\ -2 + 12 \end{bmatrix} = \begin{bmatrix} 1 \\ -2 \\ 10 \end{bmatrix} = B, so yes.
- k = 3. Row 1 gives 2k + 10 = 16; row 2 gives 3(2) - 5 = 1, which matches.
- \begin{bmatrix} 1 & 1 \\ 18 & 45 \end{bmatrix}\begin{bmatrix} c \\ s \end{bmatrix} = \begin{bmatrix} 20 \\ 576 \end{bmatrix}. For (12, 8): 12 + 8 = 20 and 18(12) + 45(8) = 576, so it fits.
- \begin{bmatrix} 1 & 1 & 1 \\ 12 & 20 & 30 \\ 1 & 0 & -3 \end{bmatrix}\begin{bmatrix} s \\ m \\ l \end{bmatrix} = \begin{bmatrix} 30 \\ 544 \\ 0 \end{bmatrix}. The last row is s = 3l rearranged to s - 3l = 0. For (12, 14, 4): 30, 144 + 280 + 120 = 544 and 12 - 12 = 0, so it fits.
- b + h = 25: 25 items in all. 2b + 4h = 68: a cutting board uses 2 board feet, a shelf 4, and all 68 board feet are used. For (16, 9): 16 + 9 = 25 and 32 + 36 = 68, so it fits.
- A is 3 \times 4, X is 4 \times 1, B is 3 \times 1. A has one row per equation and one column per variable. X needs 4 entries so a row of A has a partner for each entry, and AX is then (3 \times 4)(4 \times 1) = 3 \times 1, which must be the size of B.
- With x first the second equation is -x + y = 1, so the system is \begin{bmatrix} 2 & 1 \\ -1 & 1 \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 5 \\ 1 \end{bmatrix}. In the other matrix, row 2 times X is 1x + (-1)y, so it states x - y = 1: the first column always multiplies x, and the coefficients 1 and -1 have landed on the wrong variables.
- His second equation is 9x - 12y = 6, so row 2 of A becomes 9, -12 and entry 2 of B becomes 6. Multiplying both sides of an equation by a nonzero number keeps exactly the same solutions, as in elimination, so his system, and with it his matrix equation, has the same solutions.
- Row 1 says 0x + 0y = 3, that is 0 = 3, false for every x and y. A solution must satisfy every row, so there is none. With 0 in place of 3, row 1 says 0 = 0, true for every x and y, and the system is just x + 2y = 1, with infinitely many solutions.