# Matrix Multiplication Calculator

Created by Maciej Kowalski, PhD candidate
Reviewed by Bogna Szyk and Jack Bowater
Last updated: Nov 07, 2022

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 proves 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?

The answer to the above question is not, unfortunately, absolutely nothing. Before we start with the matrix multiplication calculator, let's think of a number. Don't worry, this is not the beginning of a magic trick. We leave those for when we want to impress our date. Anyway, 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 more information than a single value since... well, 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 time 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, then let us give you a taste by saying that every linear transformation, i.e., translation or 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, you have, in fact, used matrices. Or, to be precise, the motion could be translated into a matrix. Now that sounds like something you can tell at a party after a beer or two. We're sure your friends will be sufficiently impressed.

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?

As we said in the section above, matrices are generalizations of simple numbers, so it makes sense to multiply them. There are, however, a few matrix multiplication rules that we must follow, and, unfortunately, matrix product may not be as intuitive as 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\cdot B$ is different from $B\cdot A$ (we say that multiplying matrices is not commutative). Let's see the formula for array multiplication to see why it is so.

Say that $A$ has entries $a_{n,m}$, where $n$ denotes the number of the row, and $m$ denotes the column. This means that an entry of $a_{2,4}$ would refer to the number in the second row of the fourth column. Similarly, let $B$ have entries $b_{n,m}$. If the product $A\cdot B$ is a matrix with entries $c_{n,m}$, then we have

$\scriptsize c_{n,m} = a_{n,1}\times b_{1,m}+a_{n,2}\times b_{2,m}+a_{n,3}\times b_{3,m} + ...$

In other words, to obtain the entry in row $n$ and column $m$ of the matrix product, we need to take the $n^{\mathrm{th}}$ row of the first matrix and the** $m^{\mathrm{th}}$ column of the second matrix** and multiply their elements in pairs one by one, and then sum it all up, as we did in our dot product calculator, between vectors. Well, we did warn you that array multiplication is not as intuitive as the regular one. But don't you worry, we'll see a nice example of how to multiply matrices in the next section.

However, before we try multiplying matrices, let's take note of the few matrix multiplication rules that we've mentioned.

1. We can't multiply any pair of matrices. From the formula above, we see that every entry of the matrix product is obtained by pairing a row of the first matrix with a column of the second matrix and multiplying their entries one after another. This means that every row of array $A$ must have as many entries as every column of array $B$. This, in turn, translates to the first matrix having as many columns as the second matrix has rows. Observe that our matrix multiplication calculator won't work unless this criteria is met.

2. In general, the matrix product has a different shape than the factors. If the first matrix has $r$ rows and $s$ columns, and the second one has $s$ rows (remember that this number must be the same as the number of columns in the first array) and $t$ columns, then the result of multiplying these matrices will have $r$ rows and $t$ columns.

3. Array multiplication is not commutative. We've already mentioned this one, but now that we've learned how to multiply matrices, we see why this is the case. In the above point, we've said that a product of an $r$-row and $s$-column matrix $A$ with an $s$-row and $t$-column matrix $B$ is an $r$-row and $t$-column array $A\cdot B$. On the other hand, if we want to find $B\cdot A$, then we would need to have $s = t$, to begin with. Otherwise, multiplying these matrices is not even possible. Secondly, the product $B \cdot A$ would have $s$ rows and $s$ columns, so it would clearly be different from $A\cdot B$.

4. It indeed is a generalization of regular numbers. As the last of the matrix multiplication rules, we note that it all works nice and pretty in the most basic cases - when both factors are single-entry matrices. Then the matrix product is a single-entry matrix, which we obtain by multiplying the numbers from the two arrays. This operation is commutative and behaves just the way regular number multiplication does.

🙋 Hey, do you know that there are also other definitions of the matrix product? Check out our [Kronecker matrix tensor product calculator to learn more!

## Working backwards: decomposing matrices

Just as we can factorize a number into its factors (like $24 = 2\times12 = 4\times6$) we can factorize a matrix into matrices that will result in our original matrix when multiplied together as we've discussed above.
As matrices are a bit more complicated than singular numbers, these methods of factorization are trickier.
We described some popular decomposition methods in a very specific set of tools:

## Example: finding the matrix product

It's finally time to see how the matrix multiplication calculator works. Let's take

$\scriptsize A=\begin{pmatrix}3&-1\\0&2\\1&-1\end{pmatrix}$

And:

$\scriptsize B=\begin{pmatrix}1&0\\-1&4\end{pmatrix}$

Aand let's try multiplying these matrices.

First of all, observe that $A$ has three rows and two columns, while $B$ has two rows and two columns. Therefore, according to the matrix multiplication rules, we can safely find $A\cdot B$, but the matrix product $B \cdot A$ does not exist.

If you'd like the easy way out, feel free to use out matrix multiplication calculator to find the answer. To do this, we begin by inputting the number of rows and columns for both of the matrices. This will show us a symbolic picture above the calculator, complete with the notation we use. The first one (the one to the left) will be our $A$, and the second one (the right one) will be $B$. Compare the picture with the arrays we have and type the numbers into the matrix multiplication calculator under the correct labels. For the first matrix we have:

$\scriptsize \begin{split} a_1&=3\\ a_2&=-1 \end{split}$

Then:

$\scriptsize \begin{split} b_1&=0\\ b_2&=2 \end{split}$

And finally:

$\scriptsize \begin{split} c_1&=1\\ c_2&=-1 \end{split}$

And for the second:

$\scriptsize\begin{split} x_1&=1\\ x_2&=0 \end{split}$

And:

$\scriptsize\begin{split} y_1&=-1\\ y_2&=4 \end{split}$

Nevertheless, let's also see how the matrix multiplication calculator finds the answer. We start by introducing a useful trick that will help us with the array multiplication. We write the two matrices in a particular way separating them by a pair of dotted perpendicular lines:

$\scriptsize\begin{array}{c|c} &\begin{pmatrix}1&0\\-1&4\end{pmatrix} \\[1.em]\hline \\ \begin{pmatrix}3&-1\\0&2\\1&-1\end{pmatrix}& \end{array}$

The product of the two matrices must have three rows and two columns, so we will write it in the bottom right corner of the table above. Observe that the entry in the first row and first column will correspond to multiplying the first column of the first row of $A$ by the first row of the first column of $B$, multiplying the second column of the first row of $A$ by the second row of the first column of $B$, and summing the results. This gives:

$\scriptsize3 \times 1 + (-1) \times (-1) = 3 + 1 = 4$

Therefore, if we write it in the correct cell of our table like this

$\scriptsize\begin{array}{c|c} &\begin{pmatrix}1&0\\-1&4\end{pmatrix} \\[1.em]\hline \\ \begin{pmatrix}3&-1\\0&2\\1&-1\end{pmatrix}&\begin{pmatrix}4&?\\?&?\\?&?\end{pmatrix} \end{array}$

We put this new number where the column and row we used to calculate it intersect, so we know what we used to find it. If we continue this procedure, we get:

$\scriptsize\begin{array}{c|c} &\begin{pmatrix}1&0\\-1&4\end{pmatrix} \\[1.em]\hline \\ \begin{pmatrix}3&-1\\0&2\\1&-1\end{pmatrix}&\begin{pmatrix}4&-4\\-2&8\\2&-4\end{pmatrix} \end{array}$

All in all, the result of our array multiplication is:

$\scriptsize A\cdot B = \begin{pmatrix} 4&-4\\ -2&8\\ 2&-4\end{pmatrix}$
Maciej Kowalski, PhD candidate
First matrix size
Number of rows
2
Number of columns
2
Second matrix size
Number of rows
2
Number of columns
2
First matrix entries
a₁
a₂
b₁
b₂
Second matrix entries
x₁
x₂
y₁
y₂
Result
 ⌈ ⌉ × ⌈ ⌉ = ⌈ ⌉ ⌊ ⌋ ⌊ ⌋ ⌊ ⌋
People also viewed…

Addiction calculator tells you how much shorter your life would be if you were addicted to alcohol, cigarettes, cocaine, methamphetamine, methadone, or heroin.

### Alien civilization

The alien civilization calculator explores the existence of extraterrestrial civilizations by comparing two models: the Drake equation and the Astrobiological Copernican Limits👽

### Pi Experiments Calculator

3.141592... and then? Please celebrate with us Pi Approximation Day!