How to use the MMULT function
The MMULT function calculates the matrix product of two arrays, an array as the same number of rows as array1 and columns as array2.
Excel Function Syntax
MMULT(array1, array2)
Arguments
array1 | Required. The first array of numbers you want to multiply. |
array2 | Required. The second array of numbers you want to multiply. |
Comments
This function must be entered as an array formula.
Update January 2020
Microsoft Excel has recently released an update to Excel 365 subscribers which allows you to use a new feature called dynamic array that replaces a regular array formula.
The image above shows the MMULT function in cell B12, however, it has been entered as a regular formula. Excel "knows" that it returns multiple values and automatically expands the range.
This is called "spilled array behavior" meaning the formula expands across cells automatically in order to show all values.
There is a blue border around the values from a spilled array but it will disappear as soon as you press with left mouse button on a cell outside the blue border. It reappears again if you press with left mouse button on any cell in the spilled array.
The following examples demonstrate how the function works.
Cell ranges with an equal number of rows and columns
Array1 (B2:C3) has 2 rows and array2 (E2:F3) has 2 columns, the returning array has 2 rows and 2 columns. Cell range B2:C3 and E2:F3 show the cell labels.
Cell range H2:I3 shows the calculations for each value in the array using the labels in B2:C3 and E2:F3.
Array formula in cell range L8:M9:
Cell L8: a11*b11+a12*b21 becomes 0*0+1*1 and returns 1.
Cell L9: a21*b11+a22*b21 becomes 1*0+0*1 and returns 0.
Cell M8: a11*b12+a12*b22 becomes 0*1+1*0 and returns 0.
Cell M9: a21*b12+a22*b22 becomes 1*1+0*0 and returns 1.
Cell ranges with different number of rows and columns, example 1
Array1 (B2:C4) has 3 rows and array2 (E2:G3) has 3 columns, the returning array has 3 rows and 3 columns.
Array formula in cell range L8:M9:
Cell M8: a₁₁*b₁₁+a₁₂*b₂₁ becomes 0*1+1*4 and returns 4
Cell M9: a₂₁*b₁₁+a₂₂*b₂₁ becomes -4*1+0*4 and returns -4
Cell M10: a₃₁*b₁₁+a₃₂*b₂₁ becomes 3*1+1*4 and returns 7
Cell N8: a₁₁*b₁₂+a₁₂*b₂₂ becomes 0*2+1*-5 and returns -5
Cell N9: a₂₁*b₁₂+a₂₂*b₂₂ becomes -4*2+0*-5 and returns -8
Cell N10: a₃₁*b₁₂+a₃₂*b₂₂ becomes 3*2+1*-5 and returns 1
Cell O8: a₁₁*b₁₃+a₁₂*b₂₃ becomes 0*3+1*-6 and returns -6
Cell O9: a₂₁*b₁₃+a₂₂*b₂₃ becomes -4*3+0*-6 and returns -12
Cell O10: a₃₁*b₁₃+a₃₂*b₂₃ becomes 3*3+1*-6 and returns 3
This article shows you how to find a set of numbers which adds up to a sum you specify:
Excelxor is such a great website for inspiration, I am really impressed by this post Which numbers add up to […]
Cell ranges with different number of rows and columns, example 2
Array1 (B2:D3) has 2 rows and array2 (F2:G4) has 2 columns, the returning array has 2 rows and 2 columns.
Array formula in cell range L8:M9:
=MMULT(B8:D9,F8:G10)
Cell L8: a₁₁*b₁₁+a₁₂*b₂₁+a₁₃*b₃₁ becomes 1*0+2*-4+3*3 and returns 1
Cell L9: a₂₁*b₁₁+a₂₂*b₂₁+a₂₃*b₃₁ becomes 4*0+-5*-4+-6*3 and returns 2
Cell M8: a₁₁*b₁₂+a₁₂*b₂₂+a₁₃*b₃₂ becomes 1*1+2*0+3*1 and returns 4
Cell M9: a₂₁*b₁₂+a₂₂*b₂₂+a₂₃*b₃₂ becomes 4*1+-5*0+-6*1 and returns -2
Calculate totals row-wise
This array formula returns an array containing the total from each row in cell range C3:E7.
The number of columns in the first cell range or array must be equal to the number of rows in the second cell range or array.
Cell range C3:E7 has 3 columns and array {1; 1; 1} has three rows. The resulting array has the same number of rows as the cell range and the same number of columns as the array, in this case the array has 5 rows and 1 column. To be able to add all numbers in I use value 1 in the array.
You can also create an array that grows automatically based on the cell range, named range or an Excel defined Table.
This formula demonstrates how to create the array in the second argument using a cell range:
Let me explain this formula, the COLUMN function returns the corresponding column numbers from a cell range.
COLUMN(C3:E7) returns {3, 4, 5}.
COLUMN(C3:E7)^0
becomes
{3, 4, 5}^0
and returns {1, 1, 1}. Any number (except zero) to the power of 0 (zero) returns 1. This array has values distributed across columns, we need them transposed row-wise.
TRANSPOSE(COLUMN(C3:E7)^0)
becomes
TRANSPOSE({1, 1, 1}) and returns {1; 1; 1}.
This formula demonstrates how to create the array using a named range:
This formula demonstrates how to create the array using a reference to an Excel Table:
If you are an Excel 365 subscriber you can use the newly added SEQUENCE function:
This post demonstrates how to refresh a scoreboard instantly using the MMULT function:
This article demonstrates a scoreboard, displayed to the left, that sorts contestants based on total scores and refreshes instantly each […]
Calculate totals column-wise
=MMULT({1, 1, 1, 1, 1}, C3:E7)
This article demonstrates how to search a data set with multiple strings using the MMULT function:
Search each column for a string each and return multiple records – OR logic
RU asks: Can you please suggest if i want to find out the rows with fixed value in "First Name" […]
Search each column for a string each and return multiple records – OR logic
'MMULT' function examples
The following 26 articles have formulas containing the MMULT function.
The array formula in cell F3 counts cells in column B that contains at least one of the values in […]
This article describes a formula that counts values in two columns if they are duplicates on the same row. What's […]
This post demonstrates a formula in cell D16 that counts overlapping dates across multiple date ranges. The date ranges are […]
The MEDIAN function lets you count overlapping dates between two date ranges. If you have more than two date ranges […]
In the previous post I explained how to count overlapping dates comparing a single date range against multiple date ranges. […]
The formula in cell B17 counts rows in cell range B3:D17 when at least one cell per row contains data. […]
This article describes how to count unique distinct values. What are unique distinct values? They are all values but duplicates are […]
This article demonstrates a scoreboard, displayed to the left, that sorts contestants based on total scores and refreshes instantly each […]
Question: I second G's question: can this be done for more than 3? i.e. (Instead of last name, middle, first) […]
Sean asks: The good thing about this formula is that it is short and easy to remember. The main drawback […]
This article explains how to create a formula that returns the earliest (smallest) and the latest (largest) date of overlapping […]
Excelxor is such a great website for inspiration, I am really impressed by this post Which numbers add up to […]
The above picture shows you two formulas that extract names (column B) and date ranges (column C and D) based […]
This article demonstrates a formula that extracts unique values from a column also considering upper and lower characters (case sensitive). […]
This article describes a formula that returns all rows containing at least one digit 0 (zero) to 9. What's on […]
This article demonstrates how to solve simultaneous linear equations using formulas and Solver. The variables have the same value in […]
The worksheet above shows four different time ranges in column B and C, the formula in cell C10 counts the […]
This article demonstrates formulas that let you perform lookups using two or more conditions. The image above shows two conditions […]
Question: I want to search two columns with two search strings? The strings can be anywhere in these two columns […]
Question: Can expand this equation set into more than two colums of data, say if I had a first, middle […]
Jerome asks, in this blog post Search for multiple text strings in multiple cells in excel : If the list […]
RU asks: Can you please suggest if i want to find out the rows with fixed value in "First Name" […]
This article explains different techniques that filter rows/records that contain a given text string in any of the cell values […]
This article demonstrates a formula that filters unique distinct single digits from a cell range containing numbers. Cell range B3:B6 […]
In this article, I will demonstrate two techniques for counting per row. The first example is simple and straightforward. The […]
This article demonstrates formulas that calculate the number of overlapping ranges for all ranges, finds the most overlapped range and […]
Functions in 'Math and trigonometry' category
The MMULT function function is one of many functions in the 'Math and trigonometry' category.
4 Responses to “How to use the MMULT function”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
A great write-up as usual Oscar. Do you have any use cases to share? In 10 years of using Excel I can only think of one time where it occurred to me to use MMULT, and I can't put my finger on it now.
Hi Oscar,
Thanks for taking the request..
@ Andy.. & @Oscar
In addition.. to the previous discussion.. :)
Check the attached file.. there are few sample use of MMULT..
https://dl.dropboxusercontent.com/u/78831150/Excel/Sample%20use%20of%20MMULT.xlsx
https://dl.dropboxusercontent.com/u/78831150/Excel/Sample%20use%20of%20MMULT.jpg
https://postimg.org/image/tn0pfedvl/
Regards,
Deb
Andy,
Thank you. I have no examples to share, yet. I searched excelforum.com and found a few posts but nothing really sensational.
I googled "use of matrix multiplication" and found some practical examples in math and physics.
Deb,
Thank you for your contribution!
Formula #1
=SUM(MMULT(B2:C15;{1;-1}))
MMULT(B2:C15;{1;-1}) returns {29; 77; -1; 27; 69; 3; -3; 32; 54; -67; -65; -46; 21; -67}
equivalent to =B2:B15-C2:C15
So this formula does the same thing: =SUM(B2:B15-C2:C15)
Formula #2
=SUM(MMULT(B2:C15;{1;1})) sums of all values in B2:C15.
It is equivalent to this formula =SUM(B2:C15)
Good examples, I am beginning to understand. But I want to do someting creative and unique with the MMULT function, something that is not possible with other function or at least complicated to accomplish.
Thanks again for sharing!
[…] Mmult function […]