What is a matrix?
A matrix is a rectangular array of numbers arranged in rows and columns. We write it inside brackets. The size, or dimension, is given as rows × columns. This matrix is 2 × 3, meaning 2 rows and 3 columns:
Each number is an entry or element. The entry in row i and column j is written aᵢⱼ. In A above, a₁₂ = 4 (row 1, column 2) and a₂₃ = 5.
Matrices store tables of data, describe systems of equations, represent transformations like rotations and scaling, and sit behind computer graphics and machine learning. The matrix calculator does the arithmetic below for matrices of different sizes.
What are the common types of matrices?
- Square matrix: the same number of rows and columns, such as 3 × 3.
- Row matrix: one row, such as (2 5 7).
- Column matrix: one column. Also called a vector.
- Zero matrix: every entry is 0.
- Diagonal matrix: nonzero entries only on the main diagonal, which runs from top left to bottom right.
- Identity matrix (I): a diagonal matrix with 1s on the diagonal.
- Symmetric matrix: equal to its transpose, so aᵢⱼ = aⱼᵢ.
The 3 × 3 identity matrix is:
How do you add and subtract matrices?
Add or subtract matching entries. Both matrices must have the same size.
Subtraction works the same way: subtract each pair of matching entries. A 2 × 2 and a 2 × 3 matrix cannot be added, because some entries have no partner.
Addition is commutative (A + B = B + A) and associative, like ordinary addition.
How does scalar multiplication work?
Multiply every entry by the number. A scalar is just an ordinary number.
If you multiply by −1, every sign flips. Scalar multiplication lets you write subtraction as A − B = A + (−1)B.
How do you multiply two matrices?
Each entry of the product is the dot product of a row of the first matrix and a column of the second: multiply matching entries and add.
For an m × n matrix A and an n × p matrix B, the product AB is m × p. The inner dimensions (n and n) must match, and they disappear. The outer dimensions give the size of the result.
Example.
- Row 1 · column 1: 1·5 + 2·7 = 19.
- Row 1 · column 2: 1·6 + 2·8 = 22.
- Row 2 · column 1: 3·5 + 4·7 = 43.
- Row 2 · column 2: 3·6 + 4·8 = 50.
The product is
Example with different sizes. A 2 × 3 times a 3 × 1 gives a 2 × 1:
A helpful way to remember: go across the row, down the column.
Is matrix multiplication commutative?
No. For the matrices above, BA is
which is not the same as AB. Sometimes only one of the products exists. A 2 × 3 times a 3 × 2 is defined and is 2 × 2, while the reverse order is 3 × 2 times 2 × 3, which is 3 × 3.
Matrix multiplication is still associative, (AB)C = A(BC), and it distributes: A(B + C) = AB + AC. You just cannot swap the order of factors.
What does the identity matrix do?
Multiplying by the identity leaves a matrix unchanged: AI = IA = A when the sizes fit. It is the matrix version of the number 1.
The identity is also what you aim for in an inverse: a matrix times its inverse equals I. Our guide to determinants and inverses shows how.
What is the transpose?
The transpose of a matrix, written Aᵀ, flips it over its main diagonal. Rows become columns and columns become rows.
A 2 × 3 becomes a 3 × 2. Useful rules: (Aᵀ)ᵀ = A, (A + B)ᵀ = Aᵀ + Bᵀ, and (AB)ᵀ = BᵀAᵀ. Notice the order reverses for a product.
How are matrices used?
- Solving systems of equations. A system like 2x + y = 5, x − y = 1 can be written as AX = B.
- Computer graphics. Rotations, scaling and translations of points are done by multiplying coordinate vectors by matrices.
- Data and statistics. A spreadsheet of numbers is a matrix. Regression and covariance use matrix algebra.
- Networks. An adjacency matrix records which nodes connect.
- Economics and population models. Transition matrices describe how a system moves from one state to the next.
Example. A bakery sells muffins and cookies. Matrix P holds prices, and matrix Q holds quantities sold per day. Multiplying them gives daily revenue, and adding matrices from different days gives weekly totals.
What mistakes should you avoid?
- Adding matrices of different sizes.
- Multiplying entry by entry. That is not matrix multiplication. Use row-by-column dot products.
- Assuming AB = BA.
- Mismatched inner dimensions when multiplying. Check the sizes first.
- Forgetting to reverse the order in (AB)ᵀ = BᵀAᵀ.
- Misplacing the entries when transposing. Row 1 becomes column 1.
- Arithmetic slips. Keep a clear layout and check with the matrix calculator.
To practice, take two 2 × 2 matrices and compute A + B, 2A, AB and BA by hand. Then try a 2 × 3 and a 3 × 2. Verify each result, and write down the size of every answer before you start computing. That habit catches most errors early.
How do matrices transform points?
A 2×2 matrix can move points in the plane. Writing a point (x, y) as a column, multiplying by the matrix gives a new point. The matrix (2 0; 0 2) doubles both coordinates, which scales a shape to twice the size. The matrix (0 −1; 1 0) rotates a point 90° counterclockwise: (3, 1) becomes (−1, 3). The matrix (1 0; 0 −1) reflects points across the x-axis.
Applying two transformations in a row corresponds to multiplying their matrices, and the order matters, because rotating then scaling can differ from scaling then rotating when the scaling is not uniform. This is one concrete reason that matrix multiplication is not commutative, and it is the basis of animation and game graphics.