Skip to main content

Matrices and Matrix Operations

A matrix is, at first glance, just a rectangular grid of numbers. But that plain description hides one of the most powerful ideas in all of mathematics: a single matrix can encode an entire transformation — a rule that takes vectors and reshapes them, rotates them, stretches them, or collapses them. Once you see matrices this way, their strange multiplication rule stops looking arbitrary and starts looking inevitable.

In this page we build matrices from the ground up: how to write them, how to add and scale them, and — the crucial part — how and why we multiply them the way we do. Matrix operations are the language behind computer graphics, machine learning, physics simulations, economics, and the solution of linear systems. Master them here and the rest of linear algebra opens up.

Learning Objectives

  • Read and write matrix notation, including dimensions, entries, and indexing conventions.
  • Perform matrix addition, subtraction, and scalar multiplication fluently.
  • Compute matrix products by hand and state exactly when a product is defined.
  • Explain why matrix multiplication uses the row-by-column rule rather than entrywise multiplication.
  • Recognize the identity matrix and understand what a matrix inverse is and when it exists.
  • Connect matrix operations to the composition of linear transformations.

Quick Answer

A matrix is a rectangular array of numbers with mm rows and nn columns, written as an m×nm \times n matrix. You add or subtract two matrices of the same size entry by entry, and you multiply a matrix by a scalar by scaling every entry. Matrix multiplication is different: to multiply an m×nm \times n matrix by an n×pn \times p matrix, each entry of the product is the dot product of a row from the first with a column from the second — so the inner dimensions must match, and the result is m×pm \times p. The identity matrix II acts like the number 1 (it leaves matrices unchanged), and the inverse A1A^{-1}, when it exists, satisfies AA1=IA A^{-1} = I. Matrix multiplication is defined this way because it exactly captures the composition of linear transformations.

Where It Came From

Matrices were born from a very practical need: solving systems of linear equations. For centuries, mathematicians manipulated the coefficients of equations directly, and the arrays of numbers that appeared were treated as bookkeeping, not as objects in their own right. Chinese mathematicians in the Nine Chapters on the Mathematical Art (around 200 BCE) already used grid arrangements of coefficients and something very close to Gaussian elimination — but they had no notion of a matrix as a single algebraic thing.

The decisive leap came in the mid-nineteenth century in England. James Joseph Sylvester coined the word matrix in 1850 (from the Latin for "womb," because he saw it as the array from which determinants — minors — are "born"). His friend and collaborator Arthur Cayley then did something revolutionary: in his 1858 Memoir on the Theory of Matrices, he treated matrices as objects you can add, subtract, and — crucially — multiply, with their own algebra. Cayley noticed that when you substitute one linear change of variables into another, the resulting coefficients combine by exactly the row-by-column rule. In other words, he defined matrix multiplication so that it would represent the composition of two linear substitutions. This is the whole reason matrix multiplication looks the way it does; it was reverse-engineered to match how transformations chain together. Cayley also observed that a matrix satisfies its own characteristic equation (the Cayley–Hamilton theorem), cementing matrices as genuine algebraic objects. Later, quantum mechanics (Heisenberg's 1925 "matrix mechanics") and modern computing turned this once-abstract theory into an everyday tool.

Matrix Notation and Basic Structure

A matrix is a rectangular array of numbers arranged in rows and columns. We usually name matrices with capital letters. The matrix

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

has 2 rows and 3 columns, so we say AA is a 2×3 2 \times 3 matrix (rows always come first). The individual numbers are called entries or elements. We refer to the entry in row ii and column jj as aija_{ij}. For the matrix above, a12=1a_{12} = -1 (row 1, column 2) and a23=4a_{23} = 4 (row 2, column 3).

Some special shapes get their own names:

  • A square matrix has the same number of rows and columns (n×nn \times n).
  • A row vector is a 1×n 1 \times n matrix; a column vector is an m×1m \times 1 matrix.
  • The main diagonal of a square matrix consists of the entries a11,a22,a33,a_{11}, a_{22}, a_{33}, \dots

Two matrices are equal only if they have the same dimensions and every corresponding entry matches.

Addition, Subtraction, and Scalar Multiplication

These operations are the "easy" ones because they work entry by entry.

To add (or subtract) two matrices, they must be the same size, and you simply combine corresponding entries:

[1234]+[5678]=[681012] \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} = \begin{bmatrix} 6 & 8 \\ 10 & 12 \end{bmatrix}

Here 1+5=6 1+5 = 6, 2+6=8 2+6 = 8, 3+7=10 3+7 = 10, and 4+8=12 4+8 = 12. If the sizes differ, the sum is simply undefined — there is no meaningful way to line the entries up.

Scalar multiplication means multiplying every entry by the same number (a "scalar"):

3[2104]=[63012] 3 \cdot \begin{bmatrix} 2 & -1 \\ 0 & 4 \end{bmatrix} = \begin{bmatrix} 6 & -3 \\ 0 & 12 \end{bmatrix}

Each entry is tripled. Subtraction is just adding a scalar multiple of 1-1: AB=A+(1)BA - B = A + (-1)B.

These operations obey the comfortable rules you already expect from ordinary numbers: addition is commutative (A+B=B+AA + B = B + A) and associative, and scalar multiplication distributes over addition (k(A+B)=kA+kBk(A+B) = kA + kB).

Matrix Multiplication: The Row-by-Column Rule

Here the story gets interesting. To multiply matrix AA by matrix BB, the number of columns of AA must equal the number of rows of BB. If AA is m×nm \times n and BB is n×pn \times p, then the product ABAB is m×pm \times p. The inner dimensions (nn and nn) must match and then vanish; the outer dimensions (mm and pp) survive.

The entry in row ii, column jj of ABAB is the dot product of row ii of AA with column jj of BB:

(AB)ij=k=1naikbkj (AB)_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj}

Worked example. Let

A=[1234],B=[5678] A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}, \qquad B = \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix}

Both are 2×2 2 \times 2, so ABAB is 2×2 2 \times 2. Compute each entry:

  • Row 1 · Column 1: (1)(5)+(2)(7)=5+14=19(1)(5) + (2)(7) = 5 + 14 = 19
  • Row 1 · Column 2: (1)(6)+(2)(8)=6+16=22(1)(6) + (2)(8) = 6 + 16 = 22
  • Row 2 · Column 1: (3)(5)+(4)(7)=15+28=43(3)(5) + (4)(7) = 15 + 28 = 43
  • Row 2 · Column 2: (3)(6)+(4)(8)=18+32=50(3)(6) + (4)(8) = 18 + 32 = 50

AB=[19224350] AB = \begin{bmatrix} 19 & 22 \\ 43 & 50 \end{bmatrix}

A critical warning: matrix multiplication is not commutative. In general ABBAAB \neq BA. For the matrices above,

BA=[23343146] BA = \begin{bmatrix} 23 & 34 \\ 31 & 46 \end{bmatrix}

which is completely different from ABAB. The order matters, always.

Why Multiplication Is Defined This Way

The row-by-column rule feels bizarre until you know its purpose. A matrix represents a linear transformation — a function that takes an input vector x\mathbf{x} and produces an output vector AxA\mathbf{x}. For example, applying AA to the column vector [xy]\begin{bmatrix} x \\ y \end{bmatrix} produces a new vector whose components are linear combinations of xx and yy.

Now suppose you apply transformation BB first, then transformation AA. The combined effect on a vector x\mathbf{x} is A(Bx)A(B\mathbf{x}). The remarkable fact is that this composition is itself a linear transformation, and the single matrix representing it is exactly the product ABAB. Cayley defined multiplication precisely so that "do BB, then do AA" equals "do ABAB."

This also explains, at a stroke, two things that puzzle beginners. First, why the inner dimensions must match: the output of BB must have the right number of components to feed into AA. Second, why order matters: putting on your socks then your shoes is not the same as shoes then socks — composing transformations depends on which you do first. If multiplication were merely entrywise, it would carry none of this meaning and would be useless for the problems matrices were invented to solve.

The Identity Matrix and the Inverse

Among square matrices, one plays the role that the number 1 plays for ordinary numbers. The identity matrix InI_n is the n×nn \times n matrix with 1s on the main diagonal and 0s everywhere else:

I3=[100010001] I_3 = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

For any compatible matrix AA, we have AI=AAI = A and IA=AIA = A. The identity represents the transformation that does nothing — it leaves every vector where it is.

The inverse of a square matrix AA is the matrix A1A^{-1} that "undoes" it:

AA1=A1A=I A A^{-1} = A^{-1} A = I

Not every matrix has an inverse. A matrix is invertible (or nonsingular) exactly when its determinant is nonzero; if the determinant is zero, the transformation collapses space in a way that cannot be reversed. For a 2×2 2 \times 2 matrix there is a clean formula:

A=[abcd]    A1=1adbc[dbca] A = \begin{bmatrix} a & b \\ c & d \end{bmatrix} \implies A^{-1} = \frac{1}{ad - bc} \begin{bmatrix} d & -b \\ -c & a \end{bmatrix}

Worked example. Let A=[4726]A = \begin{bmatrix} 4 & 7 \\ 2 & 6 \end{bmatrix}. The determinant is adbc=(4)(6)(7)(2)=2414=10ad - bc = (4)(6) - (7)(2) = 24 - 14 = 10. Since this is nonzero, AA is invertible:

A1=110[6724]=[0.60.70.20.4] A^{-1} = \frac{1}{10} \begin{bmatrix} 6 & -7 \\ -2 & 4 \end{bmatrix} = \begin{bmatrix} 0.6 & -0.7 \\ -0.2 & 0.4 \end{bmatrix}

Check: AA1=[(4)(0.6)+(7)(0.2)(4)(0.7)+(7)(0.4)(2)(0.6)+(6)(0.2)(2)(0.7)+(6)(0.4)]=[2.41.42.8+2.81.21.21.4+2.4]=[1001]A A^{-1} = \begin{bmatrix} (4)(0.6)+(7)(-0.2) & (4)(-0.7)+(7)(0.4) \\ (2)(0.6)+(6)(-0.2) & (2)(-0.7)+(6)(0.4) \end{bmatrix} = \begin{bmatrix} 2.4 - 1.4 & -2.8 + 2.8 \\ 1.2 - 1.2 & -1.4 + 2.4 \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}. It works.

Real-World Applications

  • Computer graphics and games. Every rotation, scaling, and translation of a 3D model is a matrix. Composing them by multiplication lets a GPU transform millions of vertices per frame.
  • Machine learning and neural networks. A layer of a neural network multiplies an input vector by a weight matrix; training adjusts those entries. The heaviest computation in deep learning is matrix multiplication.
  • Solving linear systems. A system Ax=bA\mathbf{x} = \mathbf{b} is solved (when possible) by x=A1b\mathbf{x} = A^{-1}\mathbf{b}, or more practically by elimination — used in engineering, circuit analysis, and economics.
  • Google's PageRank and networks. The link structure of the web is a giant matrix; repeated multiplication reveals which pages are most central.
  • Cryptography and error correction. Hill ciphers and coding schemes encode messages by multiplying blocks of data by matrices.

Common Mistakes

Mistake 1: Multiplying matrices entrywise. Students often try to compute ABAB by multiplying corresponding entries (like addition). Why it's wrong: that operation (the Hadamard product) exists but is not the standard matrix product and does not represent composition of transformations. Correction: always use the row-by-column dot-product rule.

Mistake 2: Assuming AB=BAAB = BA. Because ordinary numbers commute, beginners expect matrices to as well. Why it's wrong: matrix multiplication represents ordered composition, and order changes the result; often one product isn't even defined while the other is. Correction: preserve order carefully and never swap factors.

Mistake 3: Thinking every square matrix has an inverse. Why it's wrong: if the determinant is zero (a singular matrix), the transformation loses information — like projecting 3D onto a plane — and cannot be undone. Correction: always check that adbc0ad - bc \neq 0 (or the determinant more generally) before inverting, and remember non-square matrices never have a two-sided inverse.

Comparison and Connections

Matrix multiplication behaves very differently from ordinary number multiplication, and keeping the differences straight prevents most errors.

PropertyReal numbersMatrix multiplication
CommutativeYes: ab=baab = baNo: usually ABBAAB \neq BA
AssociativeYesYes: (AB)C=A(BC)(AB)C = A(BC)
Identity elementThe number 1The identity matrix II
Inverse always exists?Yes, except 0No — only if determinant 0\neq 0
XY=0X=0XY = 0 \Rightarrow X=0 or Y=0Y=0?YesNo — nonzero matrices can multiply to zero

Matrix addition, by contrast, behaves just like number addition (commutative and associative). Matrices also connect directly to vectors (which are just single-row or single-column matrices), to determinants (which measure how a matrix scales area or volume and detect invertibility), and to linear transformations (the geometric meaning behind every operation on this page).

Practice Questions

Recall

What are the dimensions of a matrix with 4 rows and 2 columns, and what condition must two matrices satisfy to be added?

Answer: It is a 4×2 4 \times 2 matrix. Two matrices can be added only if they have identical dimensions (same number of rows and same number of columns).

Understanding

If AA is 3×5 3 \times 5 and BB is 5×2 5 \times 2, is ABAB defined? What about BABA? Give the sizes of any defined products.

Answer: ABAB is defined because the inner dimensions match (5 = 5), giving a 3×2 3 \times 2 matrix. BABA is not defined, because the inner dimensions (2 and 3) do not match.

Application

Compute CDCD where C=[2013]C = \begin{bmatrix} 2 & 0 \\ 1 & 3 \end{bmatrix} and D=[1425]D = \begin{bmatrix} 1 & 4 \\ 2 & 5 \end{bmatrix}.

Answer: Row 1: (2)(1)+(0)(2)=2(2)(1)+(0)(2)=2 and (2)(4)+(0)(5)=8(2)(4)+(0)(5)=8. Row 2: (1)(1)+(3)(2)=7(1)(1)+(3)(2)=7 and (1)(4)+(3)(5)=19(1)(4)+(3)(5)=19. So CD=[28719]CD = \begin{bmatrix} 2 & 8 \\ 7 & 19 \end{bmatrix}.

Analysis

Explain, using the idea of transformations, why the inverse of a matrix with determinant 0 cannot exist.

Answer: A determinant of 0 means the transformation squashes space into a lower dimension (for example, mapping a plane onto a line). Multiple distinct inputs then map to the same output, so there is no way to recover the original input uniquely. An inverse would have to reverse the map, but reversing a many-to-one collapse is impossible, so no inverse exists.

FAQ

Is a vector just a special matrix? Yes. A column vector is an m×1m \times 1 matrix and a row vector is a 1×n 1 \times n matrix. Everything you learn about matrix operations applies directly to vectors.

Why does the order of multiplication matter so much? Because ABAB means "apply BB first, then AA." Composing transformations in a different order generally gives a different result — just as rotating then reflecting differs from reflecting then rotating.

Can I multiply a 2×3 2 \times 3 matrix by another 2×3 2 \times 3 matrix? Not with standard multiplication — the columns of the first (3) do not match the rows of the second (2). You could multiply a 2×3 2 \times 3 by a 3×2 3 \times 2, though.

What is the difference between the inverse and the transpose? The transpose ATA^T flips a matrix across its diagonal (rows become columns) and always exists. The inverse A1A^{-1} undoes the transformation and exists only for invertible square matrices. They are unrelated in general.

Do I always need the inverse to solve Ax=bA\mathbf{x} = \mathbf{b}? No, and usually you shouldn't compute it. Gaussian elimination is faster and more numerically stable. The inverse is mainly a conceptual tool and is useful when you must apply the same "undo" to many different vectors.

Quick Revision

  • An m×nm \times n matrix has mm rows, nn columns; entry aija_{ij} is row ii, column jj.
  • Add/subtract: same size only, entry by entry. Scalar multiply: scale every entry.
  • Multiply Am×nBn×p=Cm×pA_{m\times n} B_{n\times p} = C_{m\times p}: inner dims must match; (AB)ij=kaikbkj(AB)_{ij} = \sum_k a_{ik}b_{kj} (row · column).
  • Matrix multiplication is associative but not commutative (ABBAAB \neq BA in general).
  • Identity II: 1s on the diagonal, acts like the number 1: AI=IA=AAI = IA = A.
  • Inverse A1A^{-1}: satisfies AA1=IAA^{-1} = I; exists only when determinant 0\neq 0.
  • 2×2 2 \times 2 inverse: 1adbc[dbca]\frac{1}{ad-bc}\begin{bmatrix} d & -b \\ -c & a \end{bmatrix}.
  • Multiplication is defined by the row-by-column rule because it represents composition of linear transformations (Cayley, 1858).

Prerequisites

  • Vectors and vector operations
  • Determinants and their geometric meaning
  • Linear transformations

Next Topics

  • Systems of linear equations and Gaussian elimination
  • Eigenvalues and eigenvectors