Uni-Sine
MathematicsVectors and matrices

What is a matrix?

R = [ 0  -1 ]      R × [ 3 ] = [ -1 ]
    [ 1   0 ]          [ 1 ]   [  3 ]

The plural is matrices. Here is a 2 × 3 matrix called A:

      [ 1   2   0 ]
A  =  [ 0   1   3 ]

Each number is an entry (or element). Its position is given by row first, then column: the entry in row 2, column 3 is written a23, and here it is 3. A handy way to remember the order is "rows before columns", the same order as the size, 2 × 3.

Try it

Matrix Calculator

Multiply, invert and find determinants and eigenvalues

Go to its page

Types of matrices

TypeWhat it looks likeExample
SquareSame number of rows and columns2 × 2, 3 × 3
Row matrixA single row[ 4 1 7 ], size 1 × 3
Column matrixA single column, also called a vector3 numbers stacked, size 3 × 1
Zero matrixEvery entry is 0[ 0 0 ; 0 0 ]
Identity matrix (I)1s on the main diagonal, 0s elsewhere[ 1 0 ; 0 1 ]
Diagonal matrixOnly the main diagonal can be non-zero[ 3 0 ; 0 5 ]
Symmetric matrixEqual to its own transpose: mirrored across the diagonal[ 2 7 ; 7 4 ]

In the table, a semicolon starts a new row. The main diagonal runs from top left to bottom right. The identity matrix acts like the number 1: multiplying any matrix by I leaves it unchanged.

Adding matrices and multiplying by a number

To add or subtract two matrices, they must be the same size. Add the entries in matching positions:

[ 1  2 ]   [  5  0 ]   [ 6  2 ]
[ 3  4 ] + [ -1  2 ] = [ 2  6 ]

To multiply a matrix by a number, called a scalar, multiply every entry by it. 3 times the matrix with rows (2, −1) and (0, 4) gives rows (6, −3) and (0, 12).

How to multiply matrices

Matrix multiplication isn't done entry by entry. Each entry of the answer comes from a row of the first matrix and a column of the second: multiply them pair by pair and add up.

[ 1  2 ]   [ 5  6 ]   [ 1×5 + 2×7   1×6 + 2×8 ]   [ 19  22 ]
[ 3  4 ] × [ 7  8 ] = [ 3×5 + 4×7   3×6 + 4×8 ] = [ 43  50 ]

The top-left entry uses row 1 and column 1: 1 × 5 + 2 × 7 = 19. The top-right uses row 1 and column 2: 1 × 6 + 2 × 8 = 22. And so on.

When can you multiply two matrices?

Only when the number of columns in the first equals the number of rows in the second. An m × n matrix times an n × p matrix gives an m × p matrix: the inside numbers must match, and the outside numbers give the size of the answer.

(2 × 3) times (3 × 2)  ->  inside 3 = 3, so it works, and the answer is 2 × 2
(2 × 3) times (2 × 3)  ->  inside 3 ≠ 2, so it can't be done

For example, multiply matrix A above, which is 2 × 3, by a 3 × 2 matrix B. The answer is 2 × 2. Check the bottom-left entry: row 2 of A is (0, 1, 3) and column 1 of B is (2, 1, 4), so 0 × 2 + 1 × 1 + 3 × 4 = 13.

[ 1  2  0 ]   [ 2  1 ]   [  4  1 ]
[ 0  1  3 ] × [ 1  0 ] = [ 13  3 ]
              [ 4  1 ]

Order matters

With ordinary numbers, 3 × 5 = 5 × 3. With matrices, AB and BA are usually different. Swap the two matrices in the example above and you get rows (23, 34) and (31, 46), not (19, 22) and (43, 50). Always multiply in the order written.

practice
Pick an answer, then check it.
A is a 3 × 2 matrix and B is a 2 × 4 matrix. What size is AB?

The determinant

Every square matrix has a single number called its determinant. Write a 2 × 2 matrix with a and b along the top and c and d along the bottom. Then:

\det A=ad-bcTop-left times bottom-right, minus top-right times bottom-left

For rows (3, 8) and (4, 6), the determinant is 3 × 6 − 8 × 4 = 18 − 32 = −14. The determinant has a geometric meaning: it is the factor by which the matrix scales areas. A determinant of −14 means areas grow 14 times and the shape is flipped over. A determinant of 0 squashes everything flat onto a line, and that matrix has no inverse.

The determinant of a 3 × 3 matrix

For a 3 × 3 matrix, go along the top row. Multiply each entry by the 2 × 2 determinant left when you cover its row and column, and combine them with the signs +, −, +.

    [ 2  0  1 ]
M = [ 1  3  2 ]
    [ 0  1  4 ]

det M = 2 × (3×4 − 2×1) − 0 × (1×4 − 2×0) + 1 × (1×1 − 3×0)
      = 2 × 10 − 0 + 1 × 1
      = 21

Choosing the row with a 0 in it saves work, because that term vanishes. Bigger matrices are done the same way or by computer.

The transpose

The transpose of a matrix, written AT, swaps its rows and columns: row 1 becomes column 1, and so on. A 2 × 3 matrix has a 3 × 2 transpose. A symmetric matrix is one that equals its own transpose.

The inverse of a matrix

The inverse of a square matrix A, written A−1, undoes it: A times A−1 gives the identity matrix. For a 2 × 2 matrix, swap a and d, change the signs of b and c, and divide everything by the determinant:

If A = [ a  b ]   then   A⁻¹ = 1/(ad − bc) × [  d  -b ]
       [ c  d ]                               [ -c   a ]

For rows (4, 7) and (2, 6), the determinant is 4 × 6 − 7 × 2 = 10. So the inverse is 1/10 times rows (6, −7) and (−2, 4), which is rows (0.6, −0.7) and (−0.2, 0.4). Check: multiplying the two gives the identity matrix. There is no matrix division. To "divide" by A, multiply by its inverse.

What are matrices used for?

Solving simultaneous equations

Take 2x + y = 5 and x + 3y = 10. Write the numbers in front of x and y as a matrix A, with rows (2, 1) and (1, 3), and the right-hand sides as a column (5, 10). The system becomes A × (x, y) = (5, 10), so (x, y) = A−1 × (5, 10).

  1. Determinant: 2 × 3 − 1 × 1 = 5.
  2. Inverse: 1/5 times rows (3, −1) and (−1, 2).
  3. Multiply: x = (3 × 5 − 1 × 10) ÷ 5 = 1, and y = (−1 × 5 + 2 × 10) ÷ 5 = 3.
  4. Check: 2(1) + 3 = 5 and 1 + 3(3) = 10.

For two equations, other methods are just as quick. The power of matrices is that the same method works for 3, 30 or 3,000 unknowns, and computers solve huge systems this way. The Simultaneous Equations Calculator shows each step.

Moving shapes in computer graphics

A 2 × 2 matrix can stretch, reflect or rotate every point of a shape at once. The rotation matrix R in the box below turns points 90° anticlockwise (counterclockwise in the US) about the origin. The point (3, 1) becomes (0 × 3 − 1 × 1, 1 × 3 + 0 × 1) = (−1, 3). Video games and 3D software do this to millions of points every frame, using 4 × 4 matrices for 3D.

AI and data

  • Neural networks store their learned weights in matrices, and running one is mostly matrix multiplication. Graphics cards are fast at AI because they are built to multiply matrices.
  • Spreadsheets and data tables are matrices: rows of records and columns of measurements, ready for statistics.
  • Networks and probabilities: a matrix can record which web pages link to which, or the chance of moving from one state to another in a Markov chain.
practice
Pick an answer, then check it.
A 2 × 2 matrix has 5 and 2 along its top row and 3 and 4 along its bottom row. What is its determinant?

Where do matrices come from?

Arrays of numbers for solving equations go back to ancient China, in the text known as the Nine Chapters on the Mathematical Art. The word matrix was introduced by James Joseph Sylvester in 1850, and Arthur Cayley set out the algebra of matrices, including multiplication and inverses, in 1858, according to the MacTutor history of mathematics.

Matrices at school and university

In the US, matrices appear in some Algebra 2 and precalculus courses, and the Common Core standards list matrix operations among their advanced high school topics. In the UK they are part of A-level Further Maths rather than A-level Maths. At university, they are the heart of linear algebra, which nearly every science, engineering and computing degree uses. Daily papers in College Linear Algebra give you short timed practice.

Common mistakes

  • Multiplying entry by entry. Matrix multiplication is rows times columns, added up.
  • Assuming AB = BA. The order usually changes the answer.
  • Mixing up the size order. A 2 × 3 matrix has 2 rows and 3 columns: rows first.
  • Multiplying matrices whose inside numbers don't match. Check the sizes before you start.
  • Forgetting the determinant in the inverse, or trying to invert a matrix whose determinant is 0.
  • Swapping the wrong entries for a 2 × 2 inverse. Swap a and d, and change the signs of b and c.

Common questions

What is a matrix in simple terms?
A grid of numbers in rows and columns that you treat as one object. You can add, multiply and invert matrices with their own rules.
What does 2 × 3 mean for a matrix?
It has 2 rows and 3 columns, so 6 entries. The size is always given as rows × columns.
Can you divide matrices?
Not directly. Instead you multiply by the inverse matrix, which only exists for square matrices whose determinant isn't 0.
What is the identity matrix?
A square matrix with 1s on the main diagonal and 0s everywhere else. It acts like the number 1: multiplying by it leaves a matrix unchanged.
Why is matrix multiplication done that way?
Because it matches combining transformations or substitutions. Doing one transformation and then another is the same as multiplying their matrices, and rows times columns is exactly what makes that work.
Is a vector a matrix?
A vector can be written as a matrix with one column (or one row). Multiplying a matrix by a column vector transforms the vector.

Revision cards

Say the answer first, then flip the card to check it.

Where to go next

  • Solve it

    Matrix Calculator

    Multiply, invert and find determinants and eigenvalues

    Open the tool
  • Test it

    College Linear Algebra

    A new exam-style paper every day, with instant marking and a mark scheme

    Start today's paper
Read next
Maths · Vectors and matricesHow to find the inverse of a matrix: 2x2 and 3x3 stepsHow to find the inverse of a matrix: the 2x2 formula, the 3x3 method with minors, cofactors and the adjugate, how to check it, and solving equations.