Omni Calculator logo

Matrix Multiplication Calculator

Created by Maciej Kowalski, PhD candidate
Reviewed by Bogna Szyk and Jack Bowater
Last updated: Sep 29, 2023


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?

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?

Matrix meme

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 AA and a matrix BB, then in general, the matrix product ABA\cdot B is different from BAB\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 AA has entries an,ma_{n,m}, where nn denotes the number of the row, and mm denotes the column. This means that an entry of a2,4a_{2,4} would refer to the number in the second row of the fourth column. Similarly, let BB have entries bn,mb_{n,m}. If the product ABA\cdot B is a matrix with entries cn,mc_{n,m}, then we have:

cn,m= an,1×b1,m+an,2×b2,m+an,3×b3,m+...\footnotesize \begin{split} c_{n,m} =\ &a_{n,1}\times b_{1,m}+a_{n,2}\times b_{2,m}\\&+a_{n,3}\times b_{3,m} + ... \end{split}

In other words, to obtain the entry in row nn and column mm of the matrix product, we need to take the nthn^{\mathrm{th}} row of the first matrix and the mthm^{\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 AA must have as many entries as every column of array BB. 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 these criteria is met.

  2. In general, the matrix product has a different shape than the factors. If the first matrix has rr rows and ss columns, and the second one has ss rows (remember that this number must be the same as the number of columns in the first array) and tt columns, then the result of multiplying these matrices will have rr rows and tt 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 rr-row and ss-column matrix AA with an ss-row and tt-column matrix BB is an rr-row and tt-column array ABA\cdot B. On the other hand, if we want to find BAB\cdot A, then we would need to have s=ts = t to begin with. Otherwise, multiplying these matrices is not even possible. Secondly, the product BAB \cdot A would have ss rows and ss columns, so it would clearly be different from ABA\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×12=4×624 = 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

A=(310211)\scriptsize A=\begin{pmatrix}3&-1\\0&2\\1&-1\end{pmatrix}

And:

B=(1014)\scriptsize B=\begin{pmatrix}1&0\\-1&4\end{pmatrix}

And let's try multiplying these matrices.

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

If you'd like the easy way out, feel free to use our 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 AA, and the second one (the right one) will be BB. 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:

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

Then:

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

And finally:

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

And for the second:

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

And:

y1=1y2=4\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:

(1014)(310211)\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 the first column will correspond to multiplying the first column of the first row of AA by the first row of the first column of BB, multiplying the second column of the first row of AA by the second row of the first column of BB, and summing the results. This gives:

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

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

(1014)(310211)(4?????)\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:

(1014)(310211)(442824)\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:

AB=(442824)\scriptsize A\cdot B = \begin{pmatrix} 4&-4\\ -2&8\\ 2&-4\end{pmatrix}
Maciej Kowalski, PhD candidate
The product of two matrices.
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
×=
Check out 35 similar linear algebra calculators 🔢
Adjoint matrixCharacteristic polynomialCholesky decomposition… 32 more
People also viewed…

Discount

The discount calculator uses a product's original price and discount percentage to find the final price and the amount you save.

Length of a rectangle

The length of a rectangle calculator can take two dimensions of your rectangle (width, area, diagonal, or perimeter) and work out the length of your rectangle.

Plastic footprint

Find out how much plastic you use throughout the year with this plastic footprint calculator. Rethink your habits, reduce your plastic waste, and make your life a little greener.

Power of 2

The Power of 2 Calculator helps you find the result of 2 raised to a positive or negative exponent.
Copyright by Omni Calculator sp. z o.o.
Privacy, Cookies & Terms of Service