Matrix Equation Ax = b
The matrix equation Ax = b writes a whole linear system with one matrix A and one vector of unknowns x. The product Ax is the linear combination of the columns of A that uses the entries of x as weights. So Ax = b has a solution exactly when b is in the span of the columns of A.
Before this lesson: Span of Vectors and Linear Combinations
What the product Ax means
Let A be an m × n matrix with columns a₁, …, aₙ, and let x be a vector in ℝⁿ. The product Ax is defined as a linear combination of the columns, with the entries of x as the weights:
A\mathbf{x} = \begin{bmatrix} \mathbf{a}_1 & \mathbf{a}_2 & \cdots & \mathbf{a}_n \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix} = x_1\mathbf{a}_1 + x_2\mathbf{a}_2 + \cdots + x_n\mathbf{a}_nThe product only makes sense when x has one entry for each column of A. The answer is a vector in ℝᵐ, with one entry for each row of A.
There is also a faster way to compute by hand, the row-vector rule: entry i of Ax is the dot product of row i of A with x. Both ways give the same vector, and this is the same product you know from matrix multiplication.
Three ways to write one linear system
A linear system, a vector equation and a matrix equation are three ways of writing the same problem. They all have the same solutions, and all three are solved by row reducing the augmented matrix [A | b].
| Form | What it looks like | Use it to |
|---|---|---|
| Linear system | x₁ + 2x₂ = 5 and 3x₁ + 4x₂ = 11 | Solve by elimination or row reduction |
| Vector equation | x₁(1, 3) + x₂(2, 4) = (5, 11) | Ask whether b is a linear combination of the columns |
| Matrix equation | Ax = b, where A has rows (1, 2) and (3, 4) and b = (5, 11) | Write the system compactly and use matrix tools |
When does Ax = b have a solution?
For one vector b, row reduce [A | b]. The equation has a solution exactly when no row reads [0 ⋯ 0 | c] with c ≠ 0. In other words, b must be in the span of the columns of A.
For every b at once, there is a single test. If A is an m × n matrix, these statements are either all true or all false:
- Ax = b has a solution for every b in ℝᵐ.
- Every b in ℝᵐ is a linear combination of the columns of A.
- The columns of A span ℝᵐ.
- A has a pivot position in every row.
Use the last statement to check, since it only needs the coefficient matrix A. A pivot in every column is a different condition and does not answer this question.
The product also follows two rules that later lessons use often. For vectors u and v in ℝⁿ and any scalar c:
A(\mathbf{u} + \mathbf{v}) = A\mathbf{u} + A\mathbf{v} \qquad A(c\mathbf{u}) = c(A\mathbf{u})Matrix equation Ax = b examples
Example 1: Compute Ax two ways
Find Ax for the matrix and vector below.
A = \begin{bmatrix} 1 & 2 & -1 \\ 0 & -3 & 4 \end{bmatrix}, \qquad \mathbf{x} = \begin{bmatrix} 3 \\ 1 \\ 2 \end{bmatrix}A\mathbf{x} = 3\begin{bmatrix} 1 \\ 0 \end{bmatrix} + 1\begin{bmatrix} 2 \\ -3 \end{bmatrix} + 2\begin{bmatrix} -1 \\ 4 \end{bmatrix}Column way: A is 2 × 3 and x has 3 entries, so use x₁, x₂, x₃ as the weights.
A\mathbf{x} = \begin{bmatrix} 3 \\ 0 \end{bmatrix} + \begin{bmatrix} 2 \\ -3 \end{bmatrix} + \begin{bmatrix} -2 \\ 8 \end{bmatrix}Multiply each column by its weight.
A\mathbf{x} = \begin{bmatrix} 3 + 2 - 2 \\ 0 - 3 + 8 \end{bmatrix} = \begin{bmatrix} 3 \\ 5 \end{bmatrix}Add entry by entry.
(1)(3) + (2)(1) + (-1)(2) = 3
Row way, entry 1: row 1 of A dotted with x.
(0)(3) + (-3)(1) + (4)(2) = 5
Row way, entry 2: row 2 of A dotted with x.
Answer: Ax = (3, 5). Both ways agree.
Example 2: Write a system as a matrix equation
Write the system 2x₁ − x₂ + 4x₃ = 7 and x₁ + 3x₃ = −2 as a vector equation and as a matrix equation. Then check that x = (4, −7, −2) is a solution.
x_1\begin{bmatrix} 2 \\ 1 \end{bmatrix} + x_2\begin{bmatrix} -1 \\ 0 \end{bmatrix} + x_3\begin{bmatrix} 4 \\ 3 \end{bmatrix} = \begin{bmatrix} 7 \\ -2 \end{bmatrix}Vector equation: the coefficients of each variable form a column. The second equation has no x₂, so that entry is 0.
\begin{bmatrix} 2 & -1 & 4 \\ 1 & 0 & 3 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} 7 \\ -2 \end{bmatrix}Matrix equation Ax = b: the same columns make A.
(2)(4) + (-1)(-7) + (4)(-2) = 8 + 7 - 8
Row 1 of A dotted with x = (4, −7, −2).
8 + 7 - 8 = 7
Add: entry 1 matches b₁ = 7.
(1)(4) + (0)(-7) + (3)(-2) = 4 + 0 - 6
Row 2 of A dotted with x.
4 + 0 - 6 = -2
Add: entry 2 matches b₂ = −2.
Answer: Ax = (7, −2) = b, so x = (4, −7, −2) is a solution.
Example 3: Solve Ax = b
Solve Ax = b, where A has columns (1, 3, −1) and (2, 4, 1) and b = (5, 11, 1).
\left[\begin{array}{rr|r} 1 & 2 & 5 \\ 3 & 4 & 11 \\ -1 & 1 & 1 \end{array}\right]Augmented matrix [A | b].
\left[\begin{array}{rr|r} 1 & 2 & 5 \\ 0 & -2 & -4 \\ -1 & 1 & 1 \end{array}\right]R₂ − 3R₁ → R₂: 4 − 6 = −2 and 11 − 15 = −4 (see Gaussian elimination).
\left[\begin{array}{rr|r} 1 & 2 & 5 \\ 0 & -2 & -4 \\ 0 & 3 & 6 \end{array}\right]R₃ + R₁ → R₃: 1 + 2 = 3 and 1 + 5 = 6.
\left[\begin{array}{rr|r} 1 & 2 & 5 \\ 0 & 1 & 2 \\ 0 & 3 & 6 \end{array}\right]−(1/2)R₂ → R₂.
\left[\begin{array}{rr|r} 1 & 2 & 5 \\ 0 & 1 & 2 \\ 0 & 0 & 0 \end{array}\right]R₃ − 3R₂ → R₃.
x_2 = 2
Row 2.
x_1 + 2(2) = 5
Row 1 with x₂ = 2.
x_1 = 1
Subtract 4 from both sides.
A\mathbf{x} = 1\begin{bmatrix} 1 \\ 3 \\ -1 \end{bmatrix} + 2\begin{bmatrix} 2 \\ 4 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 + 4 \\ 3 + 8 \\ -1 + 2 \end{bmatrix} = \begin{bmatrix} 5 \\ 11 \\ 1 \end{bmatrix}Check: Ax equals b.
Answer: x = (1, 2).
Example 4: Is Ax = b consistent for every b?
Let A have rows (1, −2, 3), (2, −3, 8) and (−1, 4, 1). Is Ax = b consistent for every b in ℝ³? If not, describe the vectors b that work.
\left[\begin{array}{rrr|c} 1 & -2 & 3 & b_1 \\ 2 & -3 & 8 & b_2 \\ -1 & 4 & 1 & b_3 \end{array}\right]Augmented matrix with a general b.
\left[\begin{array}{rrr|c} 1 & -2 & 3 & b_1 \\ 0 & 1 & 2 & b_2 - 2b_1 \\ -1 & 4 & 1 & b_3 \end{array}\right]R₂ − 2R₁ → R₂: −3 + 4 = 1 and 8 − 6 = 2.
\left[\begin{array}{rrr|c} 1 & -2 & 3 & b_1 \\ 0 & 1 & 2 & b_2 - 2b_1 \\ 0 & 2 & 4 & b_3 + b_1 \end{array}\right]R₃ + R₁ → R₃: 4 − 2 = 2 and 1 + 3 = 4.
\left[\begin{array}{rrr|c} 1 & -2 & 3 & b_1 \\ 0 & 1 & 2 & b_2 - 2b_1 \\ 0 & 0 & 0 & 5b_1 - 2b_2 + b_3 \end{array}\right]R₃ − 2R₂ → R₃: b₃ + b₁ − 2(b₂ − 2b₁) = 5b₁ − 2b₂ + b₃.
A has no pivot in row 3, so Ax = b is not consistent for every b. It is consistent only when the last right side is 0.
5b_1 - 2b_2 + b_3 = 0
The condition on b.
5(1) - 2(2) + (-1) = 0
Check: column 1 of A, (1, 2, −1), satisfies it.
5(-2) - 2(-3) + 4 = 0
Check: column 2, (−2, −3, 4).
5(3) - 2(8) + 1 = 0
Check: column 3, (3, 8, 1).
Answer: no. The columns of A span only the plane 5x − 2y + z = 0, so Ax = b has a solution only for b on that plane. For example, b = (1, 0, 0) gives 5 ≠ 0, so it has no solution.
Example 5: How many batches did the bakery make?
A bakery makes muffins, scones and cookies. One batch of muffins uses 2 cups of flour, 1 cup of sugar and 1 cup of butter. A batch of scones uses 3, 1 and 2 cups, and a batch of cookies uses 2, 2 and 1 cups. Yesterday the bakery used 20 cups of flour, 12 cups of sugar and 11 cups of butter. How many batches of each did it make?
\begin{bmatrix} 2 & 3 & 2 \\ 1 & 1 & 2 \\ 1 & 2 & 1 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} 20 \\ 12 \\ 11 \end{bmatrix}Each column is one product’s recipe (flour, sugar, butter), and x holds the numbers of batches.
\left[\begin{array}{rrr|r} 2 & 3 & 2 & 20 \\ 1 & 1 & 2 & 12 \\ 1 & 2 & 1 & 11 \end{array}\right]Augmented matrix [A | b].
\left[\begin{array}{rrr|r} 1 & 1 & 2 & 12 \\ 2 & 3 & 2 & 20 \\ 1 & 2 & 1 & 11 \end{array}\right]R₁ ↔ R₂, so the first pivot is 1.
\left[\begin{array}{rrr|r} 1 & 1 & 2 & 12 \\ 0 & 1 & -2 & -4 \\ 1 & 2 & 1 & 11 \end{array}\right]R₂ − 2R₁ → R₂: 3 − 2 = 1, 2 − 4 = −2 and 20 − 24 = −4.
\left[\begin{array}{rrr|r} 1 & 1 & 2 & 12 \\ 0 & 1 & -2 & -4 \\ 0 & 1 & -1 & -1 \end{array}\right]R₃ − R₁ → R₃: 2 − 1 = 1, 1 − 2 = −1 and 11 − 12 = −1.
\left[\begin{array}{rrr|r} 1 & 1 & 2 & 12 \\ 0 & 1 & -2 & -4 \\ 0 & 0 & 1 & 3 \end{array}\right]R₃ − R₂ → R₃: −1 + 2 = 1 and −1 + 4 = 3.
x_3 = 3
Row 3.
x_2 - 2(3) = -4
Row 2 with x₃ = 3.
x_2 = 2
Add 6 to both sides.
x_1 + 2 + 2(3) = 12
Row 1 with x₂ = 2 and x₃ = 3.
x_1 + 8 = 12
Add 2 + 6.
x_1 = 4
Subtract 8 from both sides.
4\begin{bmatrix} 2 \\ 1 \\ 1 \end{bmatrix} + 2\begin{bmatrix} 3 \\ 1 \\ 2 \end{bmatrix} + 3\begin{bmatrix} 2 \\ 2 \\ 1 \end{bmatrix} = \begin{bmatrix} 8 + 6 + 6 \\ 4 + 2 + 6 \\ 4 + 4 + 3 \end{bmatrix} = \begin{bmatrix} 20 \\ 12 \\ 11 \end{bmatrix}Check: Ax equals b.
Answer: 4 batches of muffins, 2 batches of scones and 3 batches of cookies.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Multiplying when the sizes do not match | Multiplying a 2 × 3 matrix by a vector with 2 entries | x needs one entry for each column of A. |
| Using the rows as the vectors in the combination | Writing Ax as x₁(row 1) + x₂(row 2) | Ax is a combination of the columns, with the entries of x as weights. |
| Testing “every b” with a pivot in every column | “A has 2 pivots and 2 columns, so Ax = b always has a solution” for a 3 × 2 matrix A | Ax = b is consistent for every b only when A has a pivot in every row. |
| Writing the system’s rows as the columns of A | Using (2, −1, 4) as column 1 for 2x₁ − x₂ + 4x₃ = 7 | Each equation is a row of A; the coefficients of one variable form a column. |
| Forgetting a missing variable | Writing row 2 of A as [1 3] for x₁ + 3x₃ = −2 | Put a 0 for the missing x₂, so the row is [1 0 3]. |
Related ideas
Square invertible matrices. When A is square with an inverse, Ax = b has exactly one solution, x = A⁻¹b. See inverse matrices.
The case b = 0. The equation Ax = 0 always has the solution x = 0. When it has others is the topic of the next lesson, Homogeneous Systems.
Reading the weights quickly. Reducing [A | b] all the way to reduced row echelon form lets you read x without back-substitution.
Practice problems
- Compute Ax for A with rows (2, −1) and (0, 3) and x = (4, 1).
- Compute Ax for A with rows (1, 0, 2) and (3, −1, 1) and x = (2, 5, −1).
- Compute Ax for A with rows (1, 4), (−2, 0) and (3, 1) and x = (−1, 2).
- A is 3 × 2 and x is in ℝ³. Is Ax defined?
- Write 3x₁ − x₂ = 4 and x₁ + 2x₂ + 5x₃ = 0 as a matrix equation Ax = b.
- Write x₁(1, 2) + x₂(−3, 1) + x₃(0, 4) = (5, 6) as a matrix equation.
- Solve Ax = b for A with rows (1, −1) and (2, 1) and b = (1, 8).
- Solve Ax = b for A with rows (1, 2), (2, 4) and (0, 1) and b = (3, 6, 1).
- For A with rows (1, 3) and (−2, −6), describe all b for which Ax = b is consistent.
- Is Ax = b consistent for every b in ℝ³ when A has rows (1, 0, 2), (0, 1, −1) and (2, 1, 4)?
Show answers
1.
4\begin{bmatrix} 2 \\ 0 \end{bmatrix} + 1\begin{bmatrix} -1 \\ 3 \end{bmatrix} = \begin{bmatrix} 8 \\ 0 \end{bmatrix} + \begin{bmatrix} -1 \\ 3 \end{bmatrix}Multiply each column by its weight.
\begin{bmatrix} 8 - 1 \\ 0 + 3 \end{bmatrix} = \begin{bmatrix} 7 \\ 3 \end{bmatrix}Add entry by entry.
Answer: Ax = (7, 3).
2.
(1)(2) + (0)(5) + (2)(-1) = 2 + 0 - 2 = 0
Row 1 dotted with x.
(3)(2) + (-1)(5) + (1)(-1) = 6 - 5 - 1 = 0
Row 2 dotted with x.
Answer: Ax = (0, 0), the zero vector.
3.
(1)(-1) + (4)(2) = -1 + 8 = 7
Row 1 dotted with x.
(-2)(-1) + (0)(2) = 2 + 0 = 2
Row 2 dotted with x.
(3)(-1) + (1)(2) = -3 + 2 = -1
Row 3 dotted with x.
Answer: Ax = (7, 2, −1).
4.
No. A has 2 columns, so x must have 2 entries. A vector in ℝ³ has 3.
5.
\begin{bmatrix} 3 & -1 & 0 \\ 1 & 2 & 5 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} 4 \\ 0 \end{bmatrix}Each equation is a row of A; the first equation has no x₃, so its entry is 0.
6.
\begin{bmatrix} 1 & -3 & 0 \\ 2 & 1 & 4 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} 5 \\ 6 \end{bmatrix}The three vectors become the columns of A.
7.
\left[\begin{array}{rr|r} 1 & -1 & 1 \\ 2 & 1 & 8 \end{array}\right]Augmented matrix [A | b].
\left[\begin{array}{rr|r} 1 & -1 & 1 \\ 0 & 3 & 6 \end{array}\right]R₂ − 2R₁ → R₂: 1 + 2 = 3 and 8 − 2 = 6.
x_2 = 2
Row 2: 3x₂ = 6, so divide both sides by 3.
x_1 - 2 = 1
Row 1 with x₂ = 2.
x_1 = 3
Add 2 to both sides.
Answer: x = (3, 2). Check: 3 − 2 = 1 and 6 + 2 = 8.
8.
\left[\begin{array}{rr|r} 1 & 2 & 3 \\ 2 & 4 & 6 \\ 0 & 1 & 1 \end{array}\right]Augmented matrix [A | b].
\left[\begin{array}{rr|r} 1 & 2 & 3 \\ 0 & 0 & 0 \\ 0 & 1 & 1 \end{array}\right]R₂ − 2R₁ → R₂: 4 − 4 = 0 and 6 − 6 = 0.
\left[\begin{array}{rr|r} 1 & 2 & 3 \\ 0 & 1 & 1 \\ 0 & 0 & 0 \end{array}\right]R₂ ↔ R₃.
x_2 = 1
Row 2.
x_1 + 2(1) = 3
Row 1 with x₂ = 1.
x_1 = 1
Subtract 2 from both sides.
Answer: x = (1, 1). Check: (1 + 2, 2 + 4, 0 + 1) = (3, 6, 1).
9.
\left[\begin{array}{rr|c} 1 & 3 & b_1 \\ -2 & -6 & b_2 \end{array}\right]Augmented matrix with a general b.
\left[\begin{array}{rr|c} 1 & 3 & b_1 \\ 0 & 0 & b_2 + 2b_1 \end{array}\right]R₂ + 2R₁ → R₂: −2 + 2 = 0 and −6 + 6 = 0.
2b_1 + b_2 = 0
The last right side must be 0.
Answer: Ax = b is consistent exactly when 2b₁ + b₂ = 0, that is, when b lies on the line y = −2x.
10.
\begin{bmatrix} 1 & 0 & 2 \\ 0 & 1 & -1 \\ 2 & 1 & 4 \end{bmatrix}The coefficient matrix A.
\begin{bmatrix} 1 & 0 & 2 \\ 0 & 1 & -1 \\ 0 & 1 & 0 \end{bmatrix}R₃ − 2R₁ → R₃: 1 − 0 = 1 and 4 − 4 = 0.
\begin{bmatrix} 1 & 0 & 2 \\ 0 & 1 & -1 \\ 0 & 0 & 1 \end{bmatrix}R₃ − R₂ → R₃: 0 + 1 = 1.
Answer: yes. A has a pivot in every row, so its columns span ℝ³ and Ax = b has a solution for every b.
Matrix equation Ax = b FAQ
What does Ax = b mean in linear algebra?
It is a linear system written with a coefficient matrix A, a vector of unknowns x and a vector of constants b. Solving it means finding the weights x that combine the columns of A into b.
How do you multiply a matrix by a vector?
Multiply each column of A by the matching entry of x and add the results. By hand, it is often faster to take the dot product of each row of A with x.
When does Ax = b have a solution?
When b is in the span of the columns of A. For every b at once, A must have a pivot in every row.
Is Ax = b the same as an augmented matrix?
They describe the same system. The augmented matrix [A | b] is the tool you row reduce to solve Ax = b.
Summary
- Ax is the combination x₁a₁ + ⋯ + xₙaₙ of the columns of A, with the entries of x as weights.
- Ax is defined only when x has one entry per column of A; by hand, use the row-vector rule.
- A linear system, a vector equation and Ax = b have the same solutions, found by row reducing [A | b].
- Ax = b has a solution exactly when b is in the span of the columns of A.
- Ax = b is consistent for every b exactly when A has a pivot in every row.
Previous lesson: Span of Vectors
Next lesson: Homogeneous Systems
Back to the Linear Algebra Index