01 / 21

Matrix Operations
Add, Subtract, Multiply

Master the rules for matrix addition, subtraction, and multiplication: when they're defined, how to compute them, and where things go wrong.

Precalculus

What Is a Matrix?

A matrix is a rectangular array of numbers arranged in rows and columns. We describe its size as \( m \times n \): \( m \) rows and \( n \) columns.

2 5 -1 0 3 7 -4 1 6 Row 1 Row 2 Row 3 Col 1 Col 2 Col 3
\(3 \times 3\) matrix

Why Matrices Matter

Matrices are everywhere: computer graphics use them to rotate and scale images, data science stores datasets as matrices, and physics describes transformations with them.

Systems of Equations
Encode and solve linear systems compactly using matrix algebra.
Transformations
Rotations, reflections, and scaling in geometry all use matrix multiplication.
Data & Networks
Adjacency matrices model graphs; spreadsheets are matrices in disguise.

The Dimension Rule

Before performing any operation, check that the dimensions are compatible. Different operations have different requirements.

Add / Subtract
Both matrices must have the same dimensions: \( m \times n + m \times n \).
Multiply
Columns of the first must equal rows of the second: \( m \times \color{#4ade80}{n} \cdot \color{#4ade80}{n} \times p \).

Matrix Addition: The Rule

If \( A \) and \( B \) are both \( m \times n \) matrices, their sum \( A + B \) is the \( m \times n \) matrix where each entry is:

$$ (A + B)_{ij} = a_{ij} + b_{ij} $$
1 3 2 4 + 5 7 6 8 = 6 10 8 12 A B A + B

Matrix Subtraction: The Rule

Subtraction works the same way as addition: subtract corresponding entries. Both matrices must share the same dimensions.

$$ (A - B)_{ij} = a_{ij} - b_{ij} $$
9 4 3 7 - 2 1 5 3 = 7 3 -2 4 A B A - B

Matrix Multiplication: The Rule

If \( A \) is \( m \times n \) and \( B \) is \( n \times p \), the product \( AB \) is an \( m \times p \) matrix. Each entry is a dot product:

$$ (AB)_{ij} = \sum_{k=1}^{n} a_{ik} \cdot b_{kj} $$

Key Distinctions

Add / Subtract Multiply
Dimension rule Same \( m \times n \) Inner dims match: \( n = n \)
Result size \( m \times n \) \( m \times p \)
Entry formula \( a_{ij} \pm b_{ij} \) \( \sum a_{ik}b_{kj} \)
Commutative? Yes (Add), No (Sub) No
Associative? Yes (Add), No (Sub) Yes

Step-by-Step Approach

1
Read the dimensions. Write down the size of each matrix: \( m \times n \).
2
Check compatibility. Same size for \( +/\- \). Inner dimensions match for \( \times \).
3
Determine result size. Same for add/subtract. Outer dimensions for multiply.
4
Compute each entry. Add/subtract entry-by-entry, or dot-product row-by-column.
5
Double-check. Verify the result has the correct dimensions and re-check one entry.

Example 1: Addition

Compute \( A + B \) where:

$$ A = \begin{bmatrix} 3 & -1 \\ 0 & 5 \\ 2 & 4 \end{bmatrix}, \quad B = \begin{bmatrix} 1 & 6 \\ -2 & 3 \\ 4 & -1 \end{bmatrix} $$
$$ A + B = \begin{bmatrix} 3+1 & -1+6 \\ 0+(-2) & 5+3 \\ 2+4 & 4+(-1) \end{bmatrix} = \begin{bmatrix} 4 & 5 \\ -2 & 8 \\ 6 & 3 \end{bmatrix} $$

Example 2: Subtraction

Compute \( C - D \) where:

$$ C = \begin{bmatrix} 8 & 2 & -3 \\ 1 & 0 & 7 \end{bmatrix}, \quad D = \begin{bmatrix} 5 & -1 & 4 \\ 3 & 6 & 2 \end{bmatrix} $$
$$ C - D = \begin{bmatrix} 8-5 & 2-(-1) & -3-4 \\ 1-3 & 0-6 & 7-2 \end{bmatrix} = \begin{bmatrix} 3 & 3 & -7 \\ -2 & -6 & 5 \end{bmatrix} $$

Example 3: Multiplication

Compute \( AB \) where:

$$ A = \begin{bmatrix} 2 & 3 \\ 1 & -1 \end{bmatrix}, \quad B = \begin{bmatrix} 4 & 0 \\ -2 & 5 \end{bmatrix} $$
2 3 1 -1 4 0 -2 5 →
\((2)(4)+(3)(-2)\)
= 2
Row 1 · Col 1 gives entry (1,1)

Example 3: Full Computation

1,1
\( (2)(4) + (3)(-2) = 8 - 6 = \) \( 2 \)
1,2
\( (2)(0) + (3)(5) = 0 + 15 = \) \( 15 \)
2,1
\( (1)(4) + (-1)(-2) = 4 + 2 = \) \( 6 \)
2,2
\( (1)(0) + (-1)(5) = 0 - 5 = \) \( -5 \)
$$ AB = \begin{bmatrix} 2 & 15 \\ 6 & -5 \end{bmatrix} $$

Example 4: Non-Square Multiply

Compute \( PQ \) where \( P \) is \( 2 \times 3 \) and \( Q \) is \( 3 \times 1 \):

$$ P = \begin{bmatrix} 1 & 0 & 2 \\ 3 & -1 & 4 \end{bmatrix}, \quad Q = \begin{bmatrix} 5 \\ 1 \\ -2 \end{bmatrix} $$
$$ PQ = \begin{bmatrix} 1 \cdot 5 + 0 \cdot 1 + 2 \cdot (-2) \\ 3 \cdot 5 + (-1) \cdot 1 + 4 \cdot (-2) \end{bmatrix} = \begin{bmatrix} 5 + 0 - 4 \\ 15 - 1 - 8 \end{bmatrix} = \begin{bmatrix} 1 \\ 6 \end{bmatrix} $$

Common Mistakes

✕ Wrong Dimensions
Adding a \( 2 \times 3 \) to a \( 3 \times 2 \). They look similar but have different shapes: undefined.
✕ Entry-wise Multiply
Multiplying \( a_{ij} \cdot b_{ij} \) instead of using dot products. That's the Hadamard product, not matrix multiplication.
✕ Assuming \( AB = BA \)
Matrix multiplication is not commutative. Even when both products exist, they typically differ.

Summary of Operations

Property Addition Subtraction Multiplication
Dimension Rule Same \( m \times n \) Same \( m \times n \) \( m \times n, n \times p \)
Result Size \( m \times n \) \( m \times n \) \( m \times p \)
Method Entry + Entry Entry - Entry Dot Product
Commutative? Yes No No
Associative? Yes No Yes

Question 1 of 5

If \( A \) is a \( 3 \times 4 \) matrix and \( B \) is a \( 3 \times 4 \) matrix, what are the dimensions of \( A + B \)?

Question 2 of 5

Compute: \( \begin{bmatrix} 5 & -2 \\ 1 & 3 \end{bmatrix} - \begin{bmatrix} 3 & 4 \\ -1 & 7 \end{bmatrix} \)

Question 3 of 5

If \( A \) is \( 2 \times 3 \) and \( B \) is \( 3 \times 5 \), what are the dimensions of \( AB \)?

Question 4 of 5

Compute entry \( (1,2) \) of the product: \( \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} \)

Question 5 of 5

Which statement about matrix multiplication is true?