Matrices: The Language of Linear Transformations
A matrix is a grid of numbers representing a linear transformation, like stretching or rotating space. It's used in graphics to move 3D models and in machine learning to hold data. The footgun: don't just see numbers; see the transformation it encodes.
WHY IT EXISTS Matrices were invented to provide a compact and efficient way to represent and manipulate systems of linear equations and linear transformations. Instead of writing out individual equations like ax + by = c and dx + ey = f for every operation, we can bundle the coefficients into a single object and operate on it directly.
THE MENTAL MODEL Think of a matrix not as a static grid of numbers, but as a machine that transforms vectors. When you multiply a vector by a matrix, you're feeding the vector into the machine and getting a new, transformed vector out. The matrix itself describes how space is stretched, rotated, or sheared. A 2x2 matrix, for example, is completely defined by where it sends the two basis vectors (1,0) and (0,1). The first column is the transformed (1,0), and the second column is the transformed (0,1).
HOW IT WORKS A matrix is a rectangular array of numbers arranged in rows and columns. An m x n matrix has m rows and n columns. Key operations include addition (element-wise, for matrices of the same size), scalar multiplication (multiplying every element by one number), and matrix multiplication. Matrix multiplication is the most important: multiplying matrix A by matrix B represents composing their two transformations. To do this, the number of columns in A must equal the number of rows in B. The resulting matrix C represents the effect of applying transformation B, then transformation A.
WHEN TO USE IT Matrices are the native language of linear systems. Use them in computer graphics to represent transformations (translation, rotation, scaling) of objects. Use them in machine learning to represent datasets (rows as samples, columns as features) and the weights of neural networks. They are also essential in solving systems of linear equations, network analysis, and quantum mechanics.
WHEN NOT TO USE IT For data that has no inherent grid-like or linear structure, a matrix can be an awkward and inefficient representation. Storing sparse data (mostly zeros) in a standard matrix is wasteful; use specialized sparse matrix formats instead. For simple, one-dimensional lists of data, a standard array is more appropriate.
ONE CANONICAL EXAMPLE In 2D graphics, to rotate a point (x, y) counter-clockwise by an angle θ, you multiply its vector by a rotation matrix. The rotation matrix is [cos(θ) -sin(θ); sin(θ) cos(θ)]. To rotate the point (1, 0) by 90 degrees, θ is 90, so cos(90) is 0 and sin(90) is 1. The matrix becomes [0 -1; 1 0]. Multiplying this by the vector for (1,0) gives the new vector (0, 1). The x-axis has been rotated onto the y-axis, as expected.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.