Matrices, order and notation
What a matrix is, how its order is written, how to name an element, and when two matrices count as equal.
Module contents
A matrix is a rectangular arrangement of numbers set inside square brackets. The numbers are called elements (or entries). Nothing more is claimed at this stage — a matrix is not a number and it does not have a value. It is a container that holds numbers in a fixed arrangement of rows and columns.
This matrix has horizontal lines (rows) and vertical lines (columns).
Order of a matrix
If a matrix has rows and columns, its order (or size, or dimension) is written
Rows first, always. The matrix above is of order . A matrix of order contains elements.
Exam habit. Whenever a question hands you a matrix, write its order beside it before doing anything else. Half the marks lost in matrix questions come from operating on matrices whose orders do not permit that operation.
Naming an element
The element sitting in the -th row and -th column of is written — row index first.
So in the matrix at the top, , , , and .
A whole matrix can be written compactly as
which reads: “ is the matrix whose general element is , of order by .”
Building a matrix from a rule
Questions often define a matrix by a formula rather than by listing it. To construct it, run over the rows and over the columns and evaluate.
Equality of matrices
Two matrices and are equal () when both of the following hold:
- They have the same order.
- Every corresponding element matches: for all and .
Order alone is not enough, and matching elements are meaningless if the orders differ. This gives a standard exam device: equate two matrices and read off a system of equations, one per position.
Why computer science cares
A matrix is the natural shape of anything indexed by two things at once, which is most of the data a program handles:
- A 2-D array in C or Java is stored exactly as a matrix;
a[i][j]is . - A greyscale image is a matrix of pixel intensities; a colour image is three of them.
- A graph on vertices is stored as an adjacency matrix.
- A transformation in 2-D or 3-D graphics — rotate, scale, translate — is applied by multiplying by a matrix.
- A system of linear equations collapses into the single statement .
The rules in this module are not arbitrary conventions. They are the rules that make those applications work.
Worked examples
3 solvedEvery step is shown, in the order you would write it in an answer book.
Reading order and elements
Question
For , state the order of , the number of elements, and the values of , and .
Count rows and columns
There are horizontal lines and vertical lines, so the order is .
Count elements
Number of elements .
Locate each element (row first, then column)
— row , column .
— row , column .
— row , column .
Answer
Order ; elements; , , .
NoteThe commonest slip is reading a₂₃ as column 2, row 3. Row index always comes first.
Constructing a matrix from a general element
Question
Construct the matrix where .
Set up the empty frame
runs (rows) and runs (columns):
Evaluate row 1 ()
Evaluate row 2 ()
Assemble
Answer
Using equality to find unknowns
Question
Find if
Check the orders match
Both are , so equality is possible and we may equate element by element.
Equate position (1,1)
Equate position (1,2), substituting
Equate position (2,1)
Equate position (2,2)
Answer
NoteWork the positions in an order that lets you substitute — here (1,1) must come before (1,2).
Practice problems
5 with solutionsWork each one on paper first. The full solution — not just the answer — is one click away.
A matrix has elements. List every possible order it can have. How many of these are square?
Show solutionHide solution
We need all factor pairs with positive integers:
That is possible orders (the number of divisors of ).
A square matrix needs , i.e. . Since is not a perfect square, no square order exists.
Construct the matrix with .
Show solutionHide solution
Run and .
Row 1: ,
Row 2: ,
Row 3: ,
Construct the matrix where
Show solutionHide solution
Decide for each cell whether (use ) or (use ).
Row 1 (): ; ;
Row 2 (): ; ;
Row 3 (): ; ;
Note the pattern: on and below the diagonal the rule is ; strictly above it, .
Find if
Show solutionHide solution
Both matrices are , so equate corresponding elements:
Subtract from :
From : .
From : .
From : .
Check in : ✓
If is of order with , find the sum of all elements of .
Show solutionHide solution
Rather than building the whole matrix, sum the general element over all and :
For the first part, each appears once for each of the columns:
For the second, each appears once for each of the rows:
Verification by construction. . Row sums: . Total ✓