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
 ⌈ ⌉ × ⌈ ⌉ = ⌈ ⌉ ⌊ ⌋ ⌊ ⌋ ⌊ ⌋

# Matrix Multiplication Calculator

By Maciej Kowalski, PhD candidate

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:

## 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 * B` is different from `B * 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 an,m, where `n` denotes the number of the row, and `m` denotes the column. This means that an entry of a2,4 would refer 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 we have

`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, we need to take the `n`-th row of the first matrix and the `m`-th column of the second matrix and multiply their elements in pairs one by one, and then sum it all up. 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 * B`. On the other hand, if we want to find `B * A`, then we would need to have `s = t`, to begin with. Otherwise, multiplying these matrices is not even possible. Secondly, the product `B * A` would have `s` rows and `s` columns, so it would clearly be different from `A * 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.

## Example: finding the matrix product

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

A =
 ⌈ 3 -1 ⌉ | 0 2 ｜ ⌊ 1 -1 ⌋
and
B =
 ⌈ 1 0 ⌉ ⌊ -1 4 ⌋

and 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 * B`, but the matrix product `B * 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:

`a₁ = 3`, `a₂ = -1`,

`b₁ = 0`, `b₂ = 2`,

`c₁ = 1`, `c₂ = -1`,

and for the second:

`x₁ = 1`, `x₂ = 0`,

`y₁ = -1`, `y₂ = 4`.

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:

 ⁞ ⌈ 1 0 ⌉ ⁞ ⌊ -1 4 ⌋ … … … … · … … … … ⌈ 3 -1 ⌉ ⁞ | 0 2 ｜ ⁞ ⌊ 1 -1 ⌋ ⁞

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:

`3 * 1 + (-1) * (-1) = 3 + 1 = 4`.

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

 ⁞ ⌈ 1 0 ⌉ ⁞ ⌊ -1 4 ⌋ … … … … · … … … … ⌈ 3 -1 ⌉ ⁞ ⌈ 4 ⌉ | 0 2 ｜ ⁞ | ｜ ⌊ 1 -1 ⌋ ⁞ ⌊ ⌋

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

 ⁞ ⌈ 1 0 ⌉ ⁞ ⌊ -1 4 ⌋ … … … … · … … … … ⌈ 3 -1 ⌉ ⁞ ⌈ 4 -4 ⌉ | 0 2 ｜ ⁞ | -2 8 ｜ ⌊ 1 -1 ⌋ ⁞ ⌊ 2 -4 ⌋

All in all, the result of our array multiplication is

A * B =
 ⌈ 4 -4 ⌉ | -2 8 ｜ ⌊ 2 -4 ⌋
Maciej Kowalski, PhD candidate

## Get the widget!

Matrix Multiplication Calculator can be embedded on your website to enrich the content you wrote and make it easier for your visitors to understand your message.

It is free, awesome and will keep people coming back!