Matrix Multiplication Calculator
Welcome to the matrix multiplication calculator, where we'll go through the subject of multiplying matrices together and see what it is good for. Unfortunately, a matrix product is something slightly more complicated than a regular multiplication. But don't worry, it's not rocket science, and learning how to multiply matrices does prove useful in fields such as algebra, analysis, and — believe it or not — real life.
No time to waste; let's learn how to multiply matrices!
What is a matrix, and what is it good for?
Before we start, let's think of a number. Don't worry, this is not the beginning of a magic trick. The number that popped into your head can mean anything, from the number of books you've read in the past few months to the number of calories you're going to burn by reading this text. Infinitely many possibilities, right?
A matrix is a generalization of that. It is an array of elements (usually numbers) with a set number of rows and columns. In particular, a matrix with one row and one column contains only one element, so we can think of such an array as a single number. In general, however, it can store far more information than a single value since you can have as many rows and columns as you like. The numbers they contain could be your working hours and your wage, or the finish times of the first three marathon runners in each of the last ten Olympic Games.
And if you'd like an example of what mathematicians use matrices for, here's a taste: every linear transformation — a translation or a rotation of an element — can be described by a matrix. In other words, every summer that you've gone on a road trip and every Saturday morning that you've mixed ingredients for pancakes, the motion could be translated into a matrix.
Other scientific areas that rely heavily on matrices include:
- Systems of equations;
- Vectors and vector spaces;
- 3-dimensional geometry (e.g., the dot product and the cross product);
- Eigenvalues and eigenvectors; and
- Graph theory and discrete mathematics.
How to multiply matrices
Since matrices are generalizations of simple numbers, it makes sense to multiply them. There are, however, a few matrix multiplication rules that we must follow, and the matrix product may not be as intuitive as the regular number product.
First of all, we can't multiply any pair of matrices. Even worse, if we have a matrix A and a matrix B, then in general the matrix product A·B is different from B·A — we say that multiplying matrices is not commutative. Let's look at the formula to see why.
Say that A has entries an,m, where n denotes the row and m denotes the column. This means that a2,4 refers to the number in the second row of the fourth column. Similarly, let B have entries bn,m. If the product A·B is a matrix with entries cn,m, then:
cn,m = an,1×b1,m + an,2×b2,m + an,3×b3,m + …
In other words, to obtain the entry in row n and column m of the matrix product, take the n-th row of the first matrix and the m-th column of the second matrix, multiply their elements in pairs one by one, and sum it all up — exactly as you would in a dot product between two vectors.
The matrix multiplication rules
- We can't multiply any pair of matrices. Every entry of the product pairs a row of the first matrix with a column of the second. This means every row of A must have as many entries as every column of B — that is, the first matrix must have as many columns as the second matrix has rows. This calculator keeps that shared inner dimension s in a single selector, so your product is always well defined.
- The product usually has a different shape than the factors. If the first matrix is r×s and the second is s×t, then the result of multiplying them is r×t.
- Matrix multiplication is not commutative. For B·A to even exist we would need t = r to begin with. And even then, B·A would be s×s, so it would clearly differ from the r×t product A·B unless every dimension matches. The calculator computes B·A whenever it is defined and tells you whether the two products agree.
- It really is a generalization of regular numbers. When both factors are single-entry 1×1 matrices, the product is the single-entry matrix you get by multiplying the two numbers. That operation is commutative and behaves exactly like ordinary multiplication.
Working backwards: decomposing matrices
Just as we can factorize a number into its factors (like 24 = 2×12 = 4×6), we can factorize a matrix into matrices that give back the original when multiplied together. As matrices are a bit more complicated than single numbers, these methods of factorization are trickier. Popular decompositions include the LU decomposition, the Cholesky decomposition, and the singular value decomposition A = UΣVᵀ.
Example: finding the matrix product
It's finally time to see how the matrix multiplication calculator works. Take the 2×3 matrix A and the 3×2 matrix B that are loaded by default:
A = 1 2 3 B = 7 8
4 5 6 9 10
11 12
Matrix A has 3 columns and matrix B has 3 rows, so the product is defined, and the result is a 2×2 matrix. Each entry is the dot product of a row of A with a column of B:
c₁,₁ = 1×7 + 2×9 + 3×11 = 58 c₁,₂ = 1×8 + 2×10 + 3×12 = 64 c₂,₁ = 4×7 + 5×9 + 6×11 = 139 c₂,₂ = 4×8 + 5×10 + 6×12 = 154
A · B = 58 64
139 154
Enter your own numbers into the two grids on the left, pick the shape of each matrix (from 1×1 up to 4×4), and press Multiply matrices. The calculator instantly returns:
- the matrix product A·B and its shape;
- a step-by-step expansion of every entry as a row-by-column dot product;
- the reverse product B·A whenever it is defined, and whether A·B = B·A;
- the operation count and — for a square result — the trace.
You can work with pure abstract numbers, or attach a metric, US customary, or currency context (20 world currencies including the US dollar and the Russian ruble) when your matrix entries represent real-world quantities such as hours, prices, or distances.