Matrices are fundamental tools in many professional fields across Kenya, including finance, healthcare, agriculture, and administration. They provide an efficient way to organize and process data such as resource allocation, scheduling, or statistical analysis. Mastery of matrix operations enables professionals to solve complex problems involving multiple variables systematically. This chapter focuses on understanding matrix dimensions, types, and performing essential operations like addition, subtraction, and multiplication, with practical examples drawn from diverse Kenyan sectors.
A matrix is a rectangular arrangement of numbers in rows and columns, and its order states exactly how many of each it has. In software development, matrices store tables of numbers such as test results, pixel values, usage counts and links between network nodes. Knowing the order of a matrix before you process it tells you how to declare a two-dimensional array, how to write nested loops over it, and whether an operation on two matrices is possible at all.
The dimension, or order, of a matrix is the number of rows and the number of columns it contains. It is written m × n, read "m by n", where m is the number of rows and n is the number of columns. Rows are always stated first. A 2 × 3 matrix is therefore not the same as a 3 × 2 matrix, just as an array declared with 2 rows and 3 columns differs from one with 3 rows and 2 columns. The total number of elements is m × n, and the dimension decides whether operations such as addition, subtraction and multiplication can be carried out.
Formula:
Dimension = m × n
Number of elements = m × n
An element in row i and column j is written a(i,j). In a 3 × 4 matrix, i runs from 1 to 3 and j runs from 1 to 4.
Example 1: A test report records the number of failed tests for 3 test suites over 4 sprints, one suite per row and one sprint per column. Find the dimension.
Given: 3 rows (test suites), 4 columns (sprints)
Dimension = rows × columns
Dimension = 3 × 4
Answer: 3 × 4, which holds 12 elements
Example 2: A project dashboard stores the number of code commits for 5 software modules across 6 releases. Determine the matrix dimension.
Given: 5 rows (modules), 6 columns (releases)
Dimension = 5 × 6
Answer: 5 × 6, which holds 30 elements
Example 3: A monitoring script records the uptime percentage of 7 servers for each of 30 days. Find its dimension.
Given: 7 rows (servers), 30 columns (days)
Dimension = 7 × 30
Answer: 7 × 30, which holds 210 elements
Example 4: A software team keeps a matrix of the hours logged by 20 developers over 22 working days. Find the matrix dimension.
Given: 20 rows (developers), 22 columns (days)
Dimension = 20 × 22
Answer: 20 × 22, which holds 440 elements
Example 5: A product owner tracks the number of downloads of 8 app features across 12 months. Determine the dimension.
Given: 8 rows (features), 12 columns (months)
Dimension = 8 × 12
Answer: 8 × 12, which holds 96 elements
Matrices are classified by their dimensions and by the values of their elements. The four types covered here are the row matrix, the column matrix, the square matrix and the zero matrix. Recognising the type from the order or the entries lets a programmer choose a suitable data structure, such as a one-dimensional array for a single row or column and a two-dimensional array for a square table.
A row matrix has exactly one row and any number of columns, so its dimension is 1 × n. It is stored in a program as a one-dimensional array that is read from left to right. For example, the colour of a pixel can be held as the row matrix [255 128 0] of dimension 1 × 3, giving the red, green and blue intensities.
Example matrix of dimension 1 × 4:
[ 12 7 9 15 ]
Worked example: A monitoring tool records the response time in milliseconds of 15 consecutive API calls in a single row. Identify the type of matrix.
Given: Dimension 1 × 15
The matrix has one row, so it is a row matrix.
Answer: Row matrix
A column matrix has exactly one column and any number of rows, so its dimension is m × 1. Each row holds one value for a different item, which suits a list of values such as the number of open bugs in each module of a system. A solution vector of unknowns, such as x and y, is also written as a column matrix.
Example matrix of dimension 4 × 1:
[ 6 ]
[ 2 ]
[ 0 ]
[ 9 ]
Worked example: A build report lists the number of open bugs for 4 modules, one module per row. Classify the matrix.
Given: Dimension 4 × 1
The matrix has one column, so it is a column matrix.
Answer: Column matrix
A square matrix has the same number of rows as columns, so its dimension is n × n. The entries a(1,1), a(2,2), a(3,3) and so on form the main diagonal, running from the top left to the bottom right. Square matrices are common in software, for example an adjacency matrix showing which of n network nodes are linked, where row i and column j record whether node i connects to node j.
Example matrix of dimension 3 × 3:
[ 0 1 1 ]
[ 1 0 0 ]
[ 1 0 0 ]
Worked example: A developer stores the links between 5 servers in a table with one row and one column per server. Identify the type of matrix.
Given: Rows = 5, columns = 5, dimension 5 × 5
The number of rows equals the number of columns, so it is a square matrix.
Answer: Square matrix of order 5
A zero matrix has every element equal to zero. It can have any dimension, so a 2 × 3 matrix of zeros and a 4 × 4 matrix of zeros are both zero matrices. Programmers often create a zero matrix to initialise a counter table before a program starts to fill it with values.
Example matrix of dimension 2 × 3:
[ 0 0 0 ]
[ 0 0 0 ]
Worked example: A program creates a 4 × 4 array to count how many times each of 4 error types occurs in each of 4 modules, and sets every cell to 0 before testing begins. Classify the matrix.
Given: Dimension 4 × 4, every element = 0
All elements are zero, so it is a zero matrix. Because it is also 4 × 4, it is square.
Answer: Zero matrix
Create a free account to open more of this chapter.
Free: practical guides, quick cards, workplace scenarios and more.
Create a free accountThis chapter explored the concept of matrix order by defining the dimension of a matrix and identifying various types such as row, column, square, and zero matrices. It then covered fundamental matrix operations including addition, multiplication, and subtraction, detailing how each operation is performed based on matrix dimensions. The transpose of a matrix was explained as the process of swapping rows and columns, and the chapter further discussed transpose operations involving sums and products of matrices. Identification of the adjoint of a square matrix was presented, followed by methods to identify the inverse of a square matrix. Applications of matrices were highlighted through the trace of a matrix and its uses in computer graphics, statistics, and solving systems of linear equations, demonstrating the practical relevance of matrix operations in various fields.
Given matrix \( A = \begin{bmatrix} 3 & 7 \end{bmatrix} \), find the order and dimension of matrix \( A \). (1 mark)
Identify the type of matrix \( B = \begin{bmatrix} 4 \\ 9 \\ 2 \end{bmatrix} \) and state its dimension. (1 mark)