Free degree-level computing lessons for careful independent study.

Degree Level Programmes · Formal Computing Foundations · Lesson 12

Matrix Operations and Computing Applications

Use matrix operations in computing contexts such as graphics, data and networks.

Lesson overview

Use matrix operations in computing contexts such as graphics, data and networks.

CourseFundamentals of Computing
Topic strandVectors and matrices
Assessment styleDigital exam practice
EvidenceWorked answer plus justification

Starter: make the model explicit

Before reading the worked example, write down the objects involved, the claim being made and the notation you expect to use. This prevents the common error of calculating before modelling.

Learning objectives

  • Add compatible matrices.
  • Multiply matrices where dimensions permit.
  • Connect matrix operations to a computing application.

Learning outcomes

  • By the end of this lesson, you can add compatible matrices.
  • By the end of this lesson, you can multiply matrices where dimensions permit.
  • By the end of this lesson, you can connect matrix operations to a computing application.

Key vocabulary

matrix additionmatrix multiplicationdimensioncompatibility

What this lesson is about

Matrix operations include addition, scalar multiplication and matrix multiplication. Each operation has dimension rules that decide whether it is valid.

In computing, matrices can store images, graphs, transformations, transition systems and datasets. For an adjacency matrix A, entries of A² can count or reveal two-step paths through a graph, so multiplication has a structural meaning beyond arithmetic.

Understanding the operation means understanding both the calculation and the model it represents.

Terms, acronyms and named methods

These are the phrases and named techniques used in this lesson. Read this section before the worked example so the notation and examples have a clear meaning.

Matrix additionNamed operation. Adding matrices entry by entry. It is only defined when the matrices have the same dimensions.
Matrix multiplicationNamed operation. Combining rows of the first matrix with columns of the second. It is only defined when the inner dimensions match.
Adjacency matrixPhrase. A matrix representation of a graph where an entry records whether a connection exists between two vertices.
CommutativePhrase. An operation is commutative when changing the order does not change the result. Ordinary addition is commutative; matrix multiplication usually is not.

Formal notation and definitions

Matrix addition requires equal dimensions.AB is defined when columns(A) = rows(B).In general, AB ≠ BA.

How to read the symbols

A+BA+BMatrix addition: add corresponding entries, only when dimensions match.
ABABMatrix multiplication: rows of A combine with columns of B.
aija_{ij}The entry in row i and column j of matrix A.

Use matrix dimension rules to decide which operations are valid. The model should explain what the rows and columns represent.

Degree-level reasoning

Vectors and matrices encode structure. The dimensions, units and component meanings are part of the model, not incidental presentation.

A correct matrix calculation should also say what the transformed vector or product represents.

Do not stop at a correct-looking answer. State why the method is valid, whether the result depends on a hidden assumption, and what would count as a counterexample.

Worked formal model

This section shows the model, notation, calculation and interpretation as one worked answer. The notation is part of the reasoning, not decoration.

1. Context and objects

An adjacency matrix stores graph connections, and matrix reasoning can reveal paths through a network.

Objects: matrices A and B, their dimensions, corresponding entries for addition, rows/columns for multiplication, and adjacency-matrix entries for path counts.

Model cue: Use an adjacency matrix for a small directed graph. Rows represent starting vertices and columns represent destination vertices.

2. Mathematical working

A=[1201],B=[3142]A = \begin{bmatrix}1 & 2 \\ 0 & 1\end{bmatrix},\quad B = \begin{bmatrix}3 & 1 \\ 4 & 2\end{bmatrix}A+B=[1+32+10+41+2]=[4343]A + B = \begin{bmatrix}1+3 & 2+1 \\ 0+4 & 1+2\end{bmatrix} = \begin{bmatrix}4 & 3 \\ 4 & 3\end{bmatrix}AB=[13+2411+2203+1401+12]=[11542]AB = \begin{bmatrix}1\cdot3+2\cdot4 & 1\cdot1+2\cdot2 \\ 0\cdot3+1\cdot4 & 0\cdot1+1\cdot2\end{bmatrix} = \begin{bmatrix}11 & 5 \\ 4 & 2\end{bmatrix}C=[011001000](C2)1,3=1 two-step routeC=\begin{bmatrix}0&1&1\\0&0&1\\0&0&0\end{bmatrix}\quad\Rightarrow\quad (C^2)_{1,3}=1\text{ two-step route}
Plain text version
A = [[1, 2], [0, 1]], B = [[3, 1], [4, 2]]
A + B = [[4, 3], [4, 3]]
AB = [[11, 5], [4, 2]]
Adjacency C = [[0,1,1], [0,0,1], [0,0,0]] gives C^2[1,3] = 0*1 + 1*1 + 1*0 = 1 two-step route

3. How to read the working

  1. Check the dimensions first. Addition needs matrices of exactly the same size; multiplication needs the number of columns of the first matrix to equal the number of rows of the second.
  2. For addition, work entry by entry: the top-left entry of A + B is the top-left entry of A plus the top-left entry of B, and so on.
  3. For multiplication, use row-by-column products. The top-left entry of AB is row 1 of A dotted with column 1 of B.
  4. For an adjacency matrix C, read (C²)ij as a two-step path count from vertex i to vertex j. This is why multiplication has a computing meaning, not just an arithmetic procedure.
  5. Interpret the operation. Addition combines matching measurements; multiplication composes transformations or relationships.

4. Computing meaning and check

Matrix addition combines like-position data, while matrix multiplication composes relationships or transformations. The same numbers can support different computing meanings depending on the operation.

Now check: Add two compatible 2 by 2 matrices by entries. Then use a small adjacency matrix to compute one entry of A^2 and interpret it as a two-step path count.

Worked example

From scenario to formal reasoning

Scenario: An adjacency matrix stores graph connections, and matrix reasoning can reveal paths through a network.

Method: Use the definitions and notation introduced above, then state what the result means in this computing scenario.

Reveal model answer

For matrix addition, add corresponding entries: [[1, 2], [0, 1]] + [[3, 1], [4, 2]] = [[4, 3], [4, 3]]. For multiplication, row-by-column gives [[1, 2], [0, 1]][[3, 1], [4, 2]] = [[11, 5], [4, 2]]. If A is an adjacency matrix, the entry (A^2)ij counts two-step routes from vertex i to vertex j, so multiplication composes relationships rather than simply combining matching entries.

Worked solution structure

How a strong answer should be written

  1. Define: State the domain and the objects under discussion. For this lesson, begin from Matrix addition requires equal dimensions.
  2. Apply: Use the relevant definition from vectors and matrices; do not rely on the diagram, wording or intuition alone.
  3. Check: Test a boundary case, counterexample candidate or representation limit.
  4. Conclude: Write one sentence that connects the formal result back to the computing scenario.

Common misconception

A common mistake is assuming matrix multiplication is commutative. In general, AB and BA are different or one may not even be defined.

Guided practice

  1. Add two compatible 2 by 2 matrices entry by entry and name what each entry represents.
  2. Multiply A = [[0,1],[1,0]] by itself and interpret the result as two-step movement in a two-node graph.
  3. Explain why AB and BA may answer different computing questions.
  4. Use an adjacency matrix to count whether there is a two-edge path between two vertices.

Quick checks

1. In an adjacency matrix, what can A² reveal?

2. Why is AB generally not the same as BA?

Digital exam practice

Example exam task

For adjacency matrix C = [[0,1,1],[0,0,1],[0,0,0]], calculate (C²)₁,₃ and explain how matrix multiplication reveals two-step paths. Contrast this with matrix addition.

Notation toolkit

A+BA+B

Means: entry-by-entry matrix addition

How to use: Use it only when matrices have the same dimensions.

ABAB

Means: matrix multiplication by row-column products

How to use: Use it to compose transformations or relationships.

(A2)ij(A^2)_{ij}

Means: the i,j entry of A squared

How to use: Use it for two-step path counts in an adjacency matrix.

What a good answer is expected to show

A strong answer for this lesson defines matrices A and B, their dimensions, corresponding entries for addition, rows/columns for multiplication, and adjacency-matrix entries for path counts, applies the vectors and matrices method with visible working, and finishes by interpreting the result in the computing scenario.

How to solve it

  1. Check the dimensions first. Addition needs matrices of exactly the same size; multiplication needs the number of columns of the first matrix to equal the number of rows of the second.
  2. For addition, work entry by entry: the top-left entry of A + B is the top-left entry of A plus the top-left entry of B, and so on.
  3. For multiplication, use row-by-column products. The top-left entry of AB is row 1 of A dotted with column 1 of B.
  4. For an adjacency matrix C, read (C²)ij as a two-step path count from vertex i to vertex j. This is why multiplication has a computing meaning, not just an arithmetic procedure.
  5. Interpret the operation. Addition combines matching measurements; multiplication composes transformations or relationships.

Model answer

Reveal model answer
C=[011001000]C=\begin{bmatrix}0&1&1\\0&0&1\\0&0&0\end{bmatrix}(C2)1,3=k=13C1,kCk,3=01+11+10=1(C^2)_{1,3}=\sum_{k=1}^{3}C_{1,k}C_{k,3}=0\cdot1+1\cdot1+1\cdot0=1

For C = [[0,1,1],[0,0,1],[0,0,0]], the entry (C²)₁,₃ is row 1 of C dotted with column 3 of C: 0·1 + 1·1 + 1·0 = 1. This means there is one two-step route from vertex 1 to vertex 3. Matrix addition would combine matching edge data; multiplication composes relationships.

Practise next

  1. Add two compatible 2 by 2 matrices entry by entry and name what each entry represents.
  2. Multiply A = [[0,1],[1,0]] by itself and interpret the result as two-step movement in a two-node graph.

Self-marking criteria

  • States what rows and columns represent.
  • Uses row-by-column multiplication.
  • Interprets an A² entry as a count or existence of two-step paths.
  • Explains why addition answers a different question.
  • Mentions that AB need not equal BA.

Extension

Change one assumption in the worked scenario and decide whether the same method still applies. If it does not, name the exact point where the reasoning breaks.

Study route

Save one clean worked answer from this lesson. Include the problem statement, notation, working, final answer and a short note explaining the computing meaning of the result.

Next lesson: Counting Principles and the Product Rule.