Matrix Operations
Add, subtract, and multiply matrices by scalars and by other matrices. Understand the conditions for matrix multiplication (inner dimensions must match) and why matrix multiplication is not commutative.
A lesson of Algebra 2, in Systems, Matrices & Linear Programming, about 10 minutes.
By the end of this lesson, you will be able to add, subtract, and multiply matrices; identify matrix dimensions; apply scalar multiplication; and understand when matrix multiplication is defined and why it is not commutative.
The Big Idea
A matrix is a rectangular array of numbers — a powerful structure for organizing data and solving systems. Matrix operations are the language of linear algebra, used in economics, computer graphics, machine learning, physics, and statistics. The non-commutativity of matrix multiplication ($AB \neq BA$ in general) is a critical conceptual shift from number arithmetic.
Matrix Notation
An $m \times n$ matrix has $m$ rows and $n$ columns.
$$A = \begin{pmatrix} 2 & -1 & 3 \ 0 & 5 & -2 \end{pmatrix} \quad \text{is a } 2 \times 3 \text{ matrix}$$
Element $a_{ij}$ is in row $i$, column $j$.
Addition and Subtraction
Add (or subtract) corresponding elements. Matrices must have the same dimensions.
$$\begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix} + \begin{pmatrix} 5 & -1 \ 0 & 3 \end{pmatrix} = \begin{pmatrix} 6 & 1 \ 3 & 7 \end{pmatrix}$$
Scalar Multiplication
Multiply every element by the scalar.
$$3 \begin{pmatrix} 2 & -1 \ 4 & 0 \end{pmatrix} = \begin{pmatrix} 6 & -3 \ 12 & 0 \end{pmatrix}$$
Matrix Multiplication
$A \cdot B$ is defined only when columns of $A$ = rows of $B$.
If $A$ is $m \times n$ and $B$ is $n \times p$, then $AB$ is $m \times p$.
Element $(i, j)$ of $AB$: dot product of row $i$ of $A$ and column $j$ of $B$.
$$c_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj}$$
Example 1 — Matrix Multiplication
$$\begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix} \begin{pmatrix} 5 & 6 \ 7 & 8 \end{pmatrix}$$
$(1,1)$: $1(5) + 2(7) = 19$
$(1,2)$: $1(6) + 2(8) = 22$
$(2,1)$: $3(5) + 4(7) = 43$
$(2,2)$: $3(6) + 4(8) = 50$
Result: $\begin{pmatrix} 19 & 22 \ 43 & 50 \end{pmatrix}$
Non-Commutativity
$$AB \neq BA \text{ in general}$$
Example: $\begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix}\begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix} = \begin{pmatrix} 2 & 1 \ 4 & 3 \end{pmatrix}$
but
$\begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix}\begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix} = \begin{pmatrix} 3 & 4 \ 1 & 2 \end{pmatrix}$
Different results. Order matters.
Identity Matrix
The $n \times n$ identity matrix $I_n$ has 1s on the diagonal and 0s elsewhere:
$$I_2 = \begin{pmatrix} 1 & 0 \ 0 & 1 \end{pmatrix}$$