Matrices

Matrices as rectangular arrays for data, systems, and transformations.

A matrix is a rectangular array of numbers. Matrices are everywhere in linear algebra because they can store data, organize equations, and describe how vectors move.

For example,

\[ A=\begin{bmatrix} 2 & -1 & 0\\ 4 & 3 & 5 \end{bmatrix} \]

has 2 rows and 3 columns, so its shape is \(2\times 3\).

What you should be able to do

By the end of this lesson, you should be able to:

  • identify rows, columns, entries, and matrix shape;
  • use row-column notation such as \(a_{ij}\);
  • recognize zero, identity, diagonal, and coefficient matrices;
  • explain why shape matters before any calculation;
  • represent small systems or data tables as matrices;
  • use edumath and SymPy to inspect matrix structure.

Rows, columns, and entries

A matrix entry is named by row first, column second. If

\[ A=\begin{bmatrix} 4 & 5\\ 7 & 8 \end{bmatrix}, \]

then \(a_{21}=7\) because row 2, column 1 contains 7.

NoteNotation reminder

The notation \(a_{ij}\) means the entry in row \(i\) and column \(j\). The row index comes first. This is like saying “go down to the correct row, then move across to the correct column.”

Shape: rows by columns

The shape of a matrix is always

\[ \text{number of rows} \times \text{number of columns}. \]

A \(3\times 2\) matrix has 3 rows and 2 columns:

\[ \begin{bmatrix} 1 & 2\\ 3 & 4\\ 5 & 6 \end{bmatrix}. \]

Shape is not a small detail. It decides what operations are possible. A matrix with 3 columns can multiply a vector with 3 entries, but not a vector with 2 entries.

Common special matrices

Zero matrix

A zero matrix has every entry equal to zero:

\[ \begin{bmatrix} 0 & 0\\ 0 & 0 \end{bmatrix}. \]

Identity matrix

The identity matrix is the matrix version of multiplying by 1:

\[ I_2=\begin{bmatrix} 1 & 0\\ 0 & 1 \end{bmatrix}. \]

It leaves vectors unchanged: \(I\mathbf{v}=\mathbf{v}\).

Diagonal matrix

A diagonal matrix has possible nonzero entries only on the main diagonal:

\[ \begin{bmatrix} 2 & 0\\ 0 & 5 \end{bmatrix}. \]

This matrix scales the first coordinate by 2 and the second coordinate by 5.

Coefficient matrix

The system

\[ \begin{aligned} 2x-y &= 3,\\ 4x+5y &= 7 \end{aligned} \]

has coefficient matrix

\[ \begin{bmatrix} 2 & -1\\ 4 & 5 \end{bmatrix}. \]

The constants on the right side form a separate vector \(\begin{bmatrix}3\\7\end{bmatrix}\).

Worked example: read a matrix carefully

Let

\[ B=\begin{bmatrix} 1 & -2 & 4\\ 0 & 3 & 5 \end{bmatrix}. \]

  1. It has 2 rows and 3 columns, so its shape is \(2\times 3\).
  2. The first row is \([1,-2,4]\).
  3. The second column is \(\begin{bmatrix}-2\\3\end{bmatrix}\).
  4. The entry \(b_{23}\) is 5 because it is in row 2, column 3.
WarningCommon pitfall

Do not reverse the order of shape. A matrix with 2 rows and 3 columns is \(2\times 3\), not \(3\times 2\).

Practice exercises

  1. What is the shape of \(\begin{bmatrix}1&2\\3&4\\5&6\end{bmatrix}\)?
  2. For \(A=\begin{bmatrix}9&8&7\\6&5&4\end{bmatrix}\), what is \(a_{12}\)?
  3. Write the \(3\times 3\) identity matrix.
  4. What coefficient matrix belongs to \(x+2y=5\) and \(3x-y=4\)?
  5. Why is the identity matrix useful?
  1. \(3\times 2\).
  2. \(a_{12}=8\).
  3. \(\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}\).
  4. \(\begin{bmatrix}1&2\\3&-1\end{bmatrix}\).
  5. It leaves vectors unchanged and acts like the number 1 for matrix multiplication.

Subtopic guided practice and checkpoints

Matrix questions are usually reading questions before they are calculation questions. First find the shape, then locate rows, columns, and entries.

Lab 1: find shape before anything else

Guess first. Is a matrix with 4 rows and 2 columns a \(4\times2\) matrix or a \(2\times4\) matrix?

Guided exercise.

For

\[ A=\begin{bmatrix} 1&0&3\\ -2&5&4 \end{bmatrix}, \]

count rows first and columns second:

  1. There are 2 horizontal rows.
  2. There are 3 vertical columns.
  3. The shape is \(2\times3\).

Checkpoint. Find the shape of \(\begin{bmatrix}1&2\\3&4\\5&6\\7&8\end{bmatrix}\).

Lab 2: locate entries with row first, column second

Guess first. In \(a_{23}\), do you look at row 2 or column 2 first?

Guided exercise.

Let

\[ B=\begin{bmatrix} 9&8&7\\ 6&5&4 \end{bmatrix}. \]

To find \(b_{23}\):

  1. Go to row 2: \([6,5,4]\).
  2. Move to column 3 in that row.
  3. The entry is \(4\).

Checkpoint. For the same matrix \(B\), find \(b_{11}\), \(b_{12}\), and \(b_{21}\).

Lab 3: recognize special matrices by their action

Guess first. Which matrix should leave every vector unchanged: zero, identity, or diagonal?

Guided exercise.

The identity matrix

\[ I_2=\begin{bmatrix}1&0\\0&1\end{bmatrix} \]

leaves vectors unchanged:

\[ I_2\begin{bmatrix}a\\b\end{bmatrix}=\begin{bmatrix}a\\b\end{bmatrix}. \]

A zero matrix sends every vector to the zero vector. A diagonal matrix scales coordinates separately.

Checkpoint. Describe what \(\begin{bmatrix}4&0\\0&-1\end{bmatrix}\) does to \(\begin{bmatrix}x\\y\end{bmatrix}\).

Lab 4: build a coefficient matrix from equations

Guess first. Where does the constant term go when you build a coefficient matrix?

Guided exercise.

For

\[ \begin{aligned} 3x-2y&=7,\\ -x+5y&=4, \end{aligned} \]

the coefficients form

\[ A=\begin{bmatrix}3&-2\\-1&5\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}7\\4\end{bmatrix}. \]

The constants are not part of the coefficient matrix. They belong in the right-hand-side vector.

Checkpoint. Write the coefficient matrix and right-hand-side vector for \(2x+3y=10\) and \(4x-y=-1\).

  1. The shape is \(4\times2\).
  2. \(b_{11}=9\), \(b_{12}=8\), and \(b_{21}=6\).
  3. \(\begin{bmatrix}4&0\\0&-1\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}= \begin{bmatrix}4x\\-y\end{bmatrix}\), so it stretches the horizontal coordinate by 4 and flips the vertical coordinate.
  4. \(A=\begin{bmatrix}2&3\\4&-1\end{bmatrix}\) and \(\mathbf{b}=\begin{bmatrix}10\\-1\end{bmatrix}\).

Matrix guessing game

This checkpoint asks about shapes, entries, and special matrices.

Using this lesson with edumath and SymPy

Use these examples to inspect matrices with Python. SymPy is especially nice when you want exact entries such as fractions.

from edumath.linear_algebra import identity_matrix, matrix_shape

A = [[1, -2, 4], [0, 3, 5]]
print(matrix_shape(A))
print(identity_matrix(3))
(2, 3)
[[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]
import sympy as sp

B = sp.Matrix([[1, -2, 4], [0, 3, 5]])
print(B.shape)
print(B[1, 2])  # Python uses zero-based indexing: row 1 means the second row.
(2, 3)
5