Linear Algebra
Matrix Basics: A Beginner's Guide to Matrices
By MathSolver Pro Editorial Team · Published
A matrix is a rectangular grid of numbers arranged in rows and columns. Matrices store data compactly and, more importantly, represent linear transformations and systems of equations. This guide covers the notation and the core operations, with special attention to matrix multiplication.
What a matrix is
A matrix is a rectangular array of numbers, called entries, arranged in rows and columns. A matrix with rows and columns has size , read as m by n, with rows always stated first. The entry in row and column of matrix is written . For example:
A matrix with a single column is a column vector, and one with a single row is a row vector. A square matrix has the same number of rows and columns; square matrices are the ones that can have determinants and inverses. Two matrices are equal only when they have the same size and every corresponding entry matches.
Adding matrices and multiplying by a scalar
Matrices of the same size are added entry by entry: the entry in row , column of is . Subtraction works the same way. Matrices of different sizes cannot be added at all, because there is no sensible way to pair their entries.
Multiplying a matrix by a scalar, meaning an ordinary number, multiplies every entry by that number. These operations behave exactly like ordinary arithmetic: addition is commutative and associative, and .
Example 1: a linear combination
- Let and .
- .
- .
Matrix multiplication: row times column
Matrix multiplication is not done entry by entry. Instead, each entry of the product is the dot product of a row of with a column of :
This requires the number of columns of to equal the number of rows of . If is and is , the product is . A quick way to check is to write the sizes side by side: the inner numbers must match, and the outer numbers give the size of the result. A matrix times a matrix gives a matrix, but a matrix times another matrix is undefined.
Example 2: multiplying two 2 by 2 matrices
- Let and .
- Row 1 of with column 1 of : .
- Row 1 with column 2: .
- Row 2 with column 1: . Row 2 with column 2: .
- So .
Order matters: AB is usually not BA
Reversing the order in the example above gives , which is a different matrix. Matrix multiplication is not commutative. For non-square matrices it can be even worse: one order may be defined and the other not, or the two products may have different sizes.
Other familiar rules do survive. Multiplication is associative, , and it distributes over addition, . Two warnings are worth remembering, though. The product of two nonzero matrices can be the zero matrix, and does not let you cancel unless is invertible. Algebra with matrices therefore needs a little more care than algebra with numbers.
When you expand expressions such as , keep the order: the result is , not .
The identity matrix and the transpose
The identity matrix is the square matrix with ones on the main diagonal and zeros elsewhere. It plays the role that the number 1 plays in ordinary arithmetic: for any square matrix of matching size. The zero matrix, with every entry zero, plays the role of 0.
The transpose swaps rows and columns, so the entry in row , column of is . A matrix becomes . A useful rule is that transposing a product reverses the order:
A matrix equal to its own transpose is called symmetric. Symmetric matrices appear throughout statistics and physics, and they have especially well-behaved eigenvalues, which are always real numbers.
Matrices and systems of equations
One of the most important uses of matrices is to write a system of linear equations compactly. The system and becomes:
Multiplying out the left side reproduces the two equations exactly, which is a good way to check that you have set up the matrix correctly. Its solution is , . Writing a system this way allows the same methods, row reduction or the inverse matrix, to solve two equations or two thousand. Our guide to solving systems of equations covers the hand methods, and the systems of equations calculator solves them step by step.
Where matrices are used
- Computer graphics: rotations, scaling and projections of 3D models are matrix multiplications applied to every vertex.
- Data science: a data set is a matrix with one row per observation and one column per variable, and techniques such as principal component analysis work directly with it.
- Networks: an adjacency matrix records which nodes are connected, and its powers count paths of a given length.
- Economics and engineering: input-output models and circuit analysis lead to large linear systems.
- Machine learning: the layers of a neural network are mostly matrix multiplications.
The matrix calculator adds, multiplies and transposes matrices of any compatible size and shows each row-times-column calculation, which makes it useful for checking homework.
Powers and diagonal matrices
A square matrix can be multiplied by itself, so powers such as and make sense. Non-square matrices have no powers, because the sizes would not match. Powers of a matrix appear whenever a process repeats: if a matrix describes how a population moves between regions in one year, its tenth power describes the movement over ten years.
Diagonal matrices, whose only nonzero entries lie on the main diagonal, are especially easy to work with. Multiplying two diagonal matrices just multiplies their diagonal entries, so raising a diagonal matrix to a power raises each diagonal entry to that power. For example, the square of the diagonal matrix with entries 2 and 3 is the diagonal matrix with entries 4 and 9. Much of advanced linear algebra is about rewriting a matrix in diagonal form so that calculations like these become simple.
Common mistakes with matrices
- Mixing up rows and columns when stating a size. Rows always come first.
- Multiplying entry by entry instead of row by column.
- Assuming , or reordering factors while simplifying an expression.
- Trying to add matrices of different sizes or multiply matrices whose inner dimensions do not match.
- Forgetting that the transpose of a product reverses the order of the factors.
A quick size check before any calculation catches most of these errors. Write the size under each matrix, confirm that the operation is defined, and predict the size of the answer before computing a single entry.
Frequently asked questions
How do I know if two matrices can be multiplied?
Write their sizes side by side, such as and . If the inner numbers match, the product exists and its size is given by the outer numbers, here .
Why isn't matrix multiplication done entry by entry?
Because the row-times-column rule makes the product represent doing one linear transformation after another. Entry-by-entry multiplication exists, called the Hadamard product, but it does not have that meaning.
Is the order of matrix multiplication important?
Yes. In general , and sometimes only one of the two products is defined. Always keep track of which matrix is on the left.
What does m by n mean for a matrix?
It gives the size: rows and columns, with rows listed first. A matrix has three rows and two columns.
Can the product of two nonzero matrices be zero?
Yes. For example, the matrix with first row 0, 1 and second row 0, 0 gives the zero matrix when multiplied by itself. This is one reason you cannot always cancel a matrix from both sides of an equation.