Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel Starter 2010 More…Less
The MMULT function returns the matrix product of two arrays. The result is an array with the same number of rows as array1 and the same number of columns as array2.
Note: If you have a current version of Microsoft 365, then you can simply enter the formula in the top-left-cell of the output range, then press ENTER to confirm the formula as a dynamic array formula. Otherwise, the formula must be entered as a legacy array formula by first selecting the output range, entering the formula in the top-left-cell of the output range, and then pressing CTRL+SHIFT+ENTER to confirm it. Excel inserts curly brackets at the beginning and end of the formula for you. For more information on array formulas, see Guidelines and examples of array formulas.
Syntax
MMULT(array1, array2)
The MMULT function syntax has the following arguments:
-
array1, array2 Required. The arrays you want to multiply.
Remarks
-
The number of columns in array1 must be the same as the number of rows in array2, and both arrays must contain only numbers.
-
Array1 and array2 can be given as cell ranges, array constants, or references.
-
MMULT returns the #VALUE! error when:
-
Any cells are empty or contain text.
-
The number of columns in array1 is different from the number of rows in array2.
-
-
The matrix product array a of two arrays b and c is:
where i is the row number, and j is the column number.
Examples
Example 1
Example 2
You must enter the above formulas as array formulas for it to work correctly. After you enter the formula, press Enter if you have a current Microsoft 365 subscription; otherwise press Ctrl+Shift+Enter. If the formula is not entered as an array formula, a single result is returned.
Need more help?
You can always ask an expert in the Excel Tech Community or get support in the Answers community.
Need more help?
Want more options?
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.
Since a worksheet is essentially a gigantic matrix, it’s no surprise that matrix multiplication in Excel is super easy – we just need to use the MMULT Excel function.
You can multiply matrices in Excel thanks to the MMULT function. This array function returns the product of two matrices entered in a worksheet.
The syntax for the function is:
MMULT(array1,array2)
where array1 and array2 are the arrays or matrices to be multiplied.
The result of the MMULT function is an array with a number of rows that’s the same as array1 and a number of columns that is the same as array2.
If you are using Excel 365, MMULT is a dynamic array function. This means that you can enter a formula using MMULT into a single cell, and Excel will automatically expand the range to fit the result of the function.
If you are NOT using Excel 365, MMULT must be entered as an array function by selecting the appropriate number of cells for the result array and typing CTRL+SHIFT+ENTER.
Matrix Multiplication Rules
To perform matrix multiplication in Excel effectively, it’s helpful to remember how matrix multiplication works in the first place. So, let’s say we have two matrices, A and B, as shown below:
The product of these two matrices (let’s call it C), is found by multiplying the entries in the first row of column A by the entries in the first column of B and summing them together. This is also known as the dot product. This single value becomes the entry in the first row and first column of matrix C.
We continue doing this until we’ve found the dot product for each row and column combination.
Since we multiply the rows of matrix A by the columns of matrix B, the resulting matrix C will have a size of 2 x 2. Or more generally, the matrix product has the same number of rows as matrix A, and the same number of columns as matrix B.
Because of the way matrix multiplication works, it’s also important to remember that we can only multiply two matrices if the number of rows in B matches the number of columns in A.
Got it?
If not, that’s ok. Hopefully a few examples will clear things up. 🙂
Excel Matrix Multiplication Examples
Matrix Multiplication as an Array Function (All Versions of Excel)
Let’s take the matrices from above and find the product using matrix multiplication in Excel with the MMULT function:
First, let’s find C, the product of AB.
Since MMULT is an array function, it will return values to more than one cell.
We know that the result is going to be a 2×2 matrix because the first matrix, A, has two rows and the second matrix, B, has two columns.
So, if we were working in Excel 365 or any previous version of Excel, we select an area on the worksheet 2 cells wide by 2 cells high:
Next, with the area still selected, type the array formula and select the arguments (I assigned names to the matrices A and B):
Finally, type CTRL+SHIFT+ENTER (because it’s an array formula) to return the resulting matrix product:
Matrix Multiplication as a Dynamic Array Function (Excel 365 Only)
In Excel 365, it’s not necessary to select the correct number of return cells or type CTRL+SHIFT+ENTER. Simply enter the array formula in the upper left most cell of the array and Excel will dynamically fill all the resulting values:
Other MMULT Examples in Excel
What if, instead of calculating matrix C, by multiplying matrix A times B, we calculated a different matrix D, by multiplying matrix B times A?
Since the first matrix, B, has 3 rows, and the second matrix, A, has 3 columns, matrix D would have 3 rows and 3 columns. So, we would start with a selection 3 cells wide and high:
Then, type in the formula for MMULT, selecting B as array1 and A as array2…
… and type CTRL+SHIFT+ENTER to obtain matrix D:
The MMULT function also works for multiplying a matrix (A) by an array (x). Of course, the rule still stands that the number of rows in x must match the number of columns in A.
The result is an array, F, that has 1 column and the same number of rows as A:
MMULT Excel Errors (Why is MMULT not working in Excel?)
There are a few different ways that you can get errors in Excel with the MMULT function:
MMULT #VALUE! Error
A #VALUE! error will occur when the number of columns in array 1 (A below) is not the same as the number of rows in array2 (x below).
To fix this would require that array x has three rows, so it probably means that one of the values from array x is missing.
If you are not using Excel 365 and MMULT is not entered as an array formula by typing CTRL+SHIFT+ENTER, it will also return a #VALUE! error to a single cell:
Finally, a #VALUE! Error will also occur if any of the elements in either array1 or array2 do not contain numbers.
MMULT Returns a Single Value
If you are not using Excel 365 and MMULT returns a single value, it’s because only a single cell was chosen for the resulting array. In earlier versions of Excel, it’s up to the user to select the appropriate number of cells for Excel to return a result to. If a single cell is selected, MMULT will perform the matrix multiplication and return the first value in the result array to that cell.
It’s also possible for this behavior to occur in Excel 365 if a single cell is selected for the result and the MMULT function is entered as an array formula by typing CTRL+SHIFT+ENTER.
MMULT Returns Too Many Values
Although not always an error, MMULT can return some surprising results when the output area for the function is larger than required.
Adding extra columns causes the results to be duplicated:
MMULT #N/A! Error
Adding extra rows to the MMULT array causes an #N/A! error to be displayed, although it’s only displayed in the extra cell:
Matrix Multiplication Limits in Excel
There are no software-imposed limits to the size of matrix that can be multiplied in current versions of Excel. Basically, you can multiply matrices as large as you want provided you have enough RAM in your computer.
However, if you’re still using Excel 2003 or earlier, you’ll be restricted to an output of 5046 cells when using the MMULT function (roughly a 71×71 matrix).
Even if you are in newer versions of Excel, there is one caveat: you cannot create an array that fills an entire column of a worksheet. Since there are 1,048,576 rows in a worksheet in Microsoft Excel 2007 and later, I guess this does constitute a limit on matrix multiplication in Excel.
This article from Microsoft support has some helpful information on the limitations of Excel when working with arrays.
What is Matrix Multiplication on Excel?
In Excel, we have an inbuilt function for matrix multiplication. It is an MMULT function. It takes two arrays as an argument and returns the product of two arrays, given that both the arrays should have the same number of rows and columns.
Explanation
Matrix multiplication is one of the useful features of excelThe top features of MS excel are — Shortcut keys, Summation of values, Data filtration, Paste special, Insert random numbers, Goal seek analysis tool, Insert serial numbers etc.
read more presented to do mathematical operations. It helps to gain the product of two matrices. The matrices that want to multiply have a certain number of rows and columns to present the data. The resulting matrix size is taken from the number of rows of the first array and the number of columns of the second array. However, there is a condition to matrix multiplication. The number of columns in the first matrix should equal the number of rows in the second matrix.
The predefined MMULT function presented in the Excel software is used to perform the matrix multiplication. Excel matrix multiplication reduces a lot of time incurred in manually calculating the product of matrices.
In general, we can do matrix multiplication in two ways. First, simple scalar multiplication is performed using the basic arithmetic operations. Second, advanced matrix multiplication is managed with the help of array function in excelArray formulas are extremely helpful and powerful formulas that are used in Excel to execute some of the most complex calculations. There are two types of array formulas: one that returns a single result and the other that returns multiple results.read more.
The Excel formula used for multiplicationMultiplication in excel is performed by entering the comparison operator “equal to” (=), followed by the first number, the “asterisk” (*), and the second number.read more is entered in two ways, including manually typing the MMULT function after the equal sign or selecting the Math and Trig function library presented under the “Formulas” tab. The mathematical function MMULT helps in returning the multiplication of two arrays. It is one of the predefined excel functionsExcel functions help the users to save time and maintain extensive worksheets. There are 100+ excel functions categorized as financial, logical, text, date and time, Lookup & Reference, Math, Statistical and Information functions.read more used in worksheets to perform calculations in a short time..
You are free to use this image on your website, templates, etc, Please provide us with an attribution linkArticle Link to be Hyperlinked
For eg:
Source: Excel Matrix Multiplication (wallstreetmojo.com)
Syntax
The required syntax that we should follow for the matrix multiplication is:
- Parameters: Array1 and array2 are the two required parameters to perform multiplication.
- Rule: Columns of array1 should be equal to rows of array2, and the size of the product must be equal to the number of rows in array1 and the number of columns in array2.
- Returns: The MMULT function generates the numbers in the product matrix. It is inserted as a formula or worksheet function in Excel calculations.
Let us consider the below image.
Then, the product of A*B is as follows:
How to do Matrix Multiplication in Excel? (with Examples)
Matrix multiplication in Excel has some real-time applications. There are two ways to do matrix multiplication. Below are some examples of Excel matrix multiplication.
You can download this Matrix Multiplication Excel Template here – Matrix Multiplication Excel Template
Example #1 – Multiplying a matrix with a scalar number.
Let us start.
- Firstly, we must enter data into the array.
- Then, we must select a scalar value that we need to multiply with an array, i.e., 3.
- Estimate the rows and columns of the resultant array. Here, the resultant array will be of size 3 x 3.
- After that, we must select the range of cells equal to the size of the resultant array to place the result and enter the normal multiplication formula.
- On entering the formula, we must press Ctrl + Shift + Enter. Consequently, the result will be obtained, as shown below.
Example #2 – Matrix Multiplication of Two Individual Arrays
- Step 1: First, we should enter data into an array A size of 3×3.
- Step 2: Then, insert data into the second array called B size of 3×3.
- Step 3: We need to ensure that columns of the first array are the same in size as rows of the second array.
- Step 4: Estimate the rows and columnsA cell is the intersection of rows and columns. Rows and columns make the software that is called excel. The area of excel worksheet is divided into rows and columns and at any point in time, if we want to refer a particular location of this area, we need to refer a cell.read more of the resultant array.
- Step 5: Select the range of cells equal to the size of the resultant array to place the result and enter the MMULT multiplication formula.
Next, we must insert the values to calculate the product of A and B.
Once we enter the formula, press Ctrl + Shift + Enter to get the result. The results we can obtain by multiplying two arrays are as follows. The size of the resultant array is 3X3.
Example #3
Matrix multiplication between arrays with a single row and single column. Let’s consider the elements of matrices as follows:
Matrix A is 1×3, and matrix B is 3×1. So the size of the product A*B [AB] matrix is 1×1. So, we must now insert the matrix multiplication formula in the cell.
Press the “Enter” key to get the result.
Example #4 – Matrix Multiplication Between Arrays with Single Column and a Single Row
Matrix A is 3×1, and matrix B is 1×3. The size of the product A*The B [AB] matrix is 3×3.
So, the answer will be:
Example #5 – Determining the square of a matrix using MMULT in ExcelMMULT is an in-built Math & Trigonometry function in Excel that performs matrix multiplication of 2 arrays where the columns of Array 1 are equivalent to the rows for Array 2. read more
The square of matrix A is determined by multiplying A with A.
The resulting matrix is obtained as:
Things to Remember
- The number of columns presented in array1 and the number of rows present in array2 must be equal to perform matrix multiplication.
- It is hard to change the part of an array since the array is a group of elements.
- While performing an array multiplication, CTRL+SHIFT+ENTER should be used to produce all elements of the result matrix. Otherwise, it may create only a single element.
- The elements of an array should not be null, and we should not use text in matrices to avoid errors.
- The size of the product array is equal to rows of the first array and columns of the second array.
- The multiplication of A*B is not equal to the B*A in matrix multiplication.
- Multiplying a matrix with unit matrix results in the same matrix (i.e., [A]*[Unit matrix]=[A]).
Recommended Articles
This article has been a guide to Excel Matrix Multiplication. Using the scalar method and MMULT() function with examples and a downloadable Excel template, we discussed matrix multiplication in Excel. You can learn more about Excel from the following articles: –
- Excel Inverse Matrix
- Using VBA Arrays
- Using SUMPRODUCT with Multiple Criteria
- COUNTIF with Multiple Criteria
You can work with a matrix in the Excel just like with a range. That is, a set of adjacent cells occupying a rectangular area.
The matrix address is the upper left and right lower cell of the range indicated by the colon.
Array formulas
Building a matrix of Excel tools in most cases requires the use of appropriate arrays. Their main difference is that the result is not one value but a data set (a range of numbers).
The procedure for applying the data set formula:
- Select the range where the result of the formula action should appear.
- Enter the formula (starting with the sign «=»).
- Press the kea combination Ctrl + Shift + Enter.
The data set formula in curly brackets is displayed in the formula bar.
Select the entire range and perform the appropriate actions to change or delete a data set formula. The same combination is used (Ctrl + Shift + Enter) to enter changes. Part of the data set cannot be changed.
Matrix operations in Excel
You can perform such operations with matrices in Excel as transposition, addition, multiplication by number/array; finding the inverse matrix and its determinant.
Transpose the matrices
Transposing the matrix is an act of changing the rows and columns in places.
First, note the empty range where we transpose the matrix. There are 4 lines in the original table and the range for the transposition should have 4 columns. For 5 columns there are should be five lines in an empty area, etc.
- Method #1. Select the original data array. Click «copy». Select an empty range. Expand the Paste button. Open the «Paste Special» menu (CTRL+ALT+V). Mark «Transpose» operation. Close the dialog by clicking OK.
- Method #2. Select the range B7:E11 with active cell B7 in the upper left corner of the empty range. Select function: «FORMULAS»-«Lookup and Reference»-«TRANSPOSE». The argument is a range with the original array data. Click OK. Now the function produces an error. Select the entire range where you want to transpose the matrix. Press the F2 (go to the formula editing mode). Press the key combination Ctrl + Shift + Enter.
The advantage of the second method: the transposed matrix automatically changes while making changes to the original.
Addition of a matrices
You can sum up matrices with the same number of elements. The number of rows and columns of the first range should be equal to the number of rows and columns of the second range.
In the first cell of the resulting matrix you need to enter a formula of the next form: = the first element of the first array + the first element of the second: (=A1+E1). Press Enter and stretch the formula to the full range.
Matrices multiplication in Excel
The task is next:
To multiply a matrix by a number you need to multiply each of its elements by this number. The formula in Excel: =A1*$E$3 ( a reference to a cell with a number must be absolute).
Let’s multiply the matrix with different ranges. It’s possible only to find the product of matrices if the number of columns of the first matrix is equal to the number of rows of the second one.
In the resulting matrix, the number of rows is equal to the number of rows of the first array, and the number of columns is equal to the number of columns of the second.
For convenience, we select the range where the multiplication results will be placed. We make the first cell of the resulting field active. Then select: «FORMULAS»-«Math and Trig»-«MMULT» We introduce the formula: = =MMULT(A1:C5,E1:H3). Enter as an array formula (CTRL+SHIFT+Enter).
The inverse matrices in Excel
It makes sense to find it if we are dealing with a square matrix (the number of rows and columns is the same).
The dimension of the inverse matrix corresponds to the size of the original. We use: «FORMULAS»-«Math and Trig»-«MINVERSE» function in Excel.
Select the first cell of the empty range for the inverse matrix. We introduce the formula «= MINVERSE(A1:D4)» as a data set function. The only argument is the range with the original. We got the inverse array in Excel:
Finding the matrices determinant
This is one single number that is found for a square matrix. We use: «FORMULAS»-«Math and Trig»-«MDETERM» function.
We put the cursor in any cell of the open sheet. Enter the formula: =MOPRED(A1:D4).
Thus, we performed actions with the matrixes using the built-in Excel features.
Purpose
Perform matrix multiplication
Return value
The matrix product of two arrays
Usage notes
The MMULT function returns the matrix product of two arrays, sometimes called the «dot product». The result from MMULT is an array that contains the same number of rows as array1 and the same number of columns as array2. The MMULT function appears in certain more advanced formulas that need to process multiple rows or columns. For example, you can use MMULT with XLOOKUP to match a value in any column.
The MMULT function takes two arguments, array1 and array2, both of which are required. The column count of array1 must equal the row count of array2. For example, you can multiply a 2 x 3 array by a 3 x 2 array to return a 2 x 2 array result. The MMULT function will return a #VALUE! error if array1 columns do not equal array2 rows.
Note: In Excel 365, which supports dynamic arrays, MMULT spills multiple values on the worksheet. In earlier versions, you will need to enter as a multi-cell array formula with control + shift + enter.
Example #1 — basic usage
In the example shown, the MMULT formula is evaluated like this:
=MMULT(B6:D7,F6:G8)
=MMULT({0,3,5;5,5,2},{3,4;3,-2;4,-2})
={29,-16;38,6}
Example #2 — count rows with specific value
In this example, the goal is to count rows that contain the number 90. The challenge is that the value might appear in any of several columns, and might appear in more than one column of the same row. The MMULT function is used to condense results from multiple columns into a single 1-column array that can then be summed with the SUM function. The formula in G5 is:
=SUM(--(MMULT(--(data=90),TRANSPOSE(COLUMN(data)))>0))
Read a detailed explanation here. See below for more examples.
Notes
- Arrays must contain numbers only.
- Columns in array1 must equal the rows in array2.
- Array1 and array2 can be provided as cell ranges, array constants, or references.
- MMULT returns #VALUE! if any cells in array1 and array2 are not numbers
- MMULT returns #VALUE! if array1 columns do not equal array2 rows.