MMULT function
The MMULT function in Excel is used to multiply two matrices. It returns the matrix product of two arrays, which is a fundamental operation in linear algebra.
Syntax
=MMULT(array1, array2)
Parameters
array1: The first matrix (or array) to multiply. This can be a range of cells that represent the first matrix.array2: The second matrix (or array) to multiply. This can be a range of cells that represent the second matrix.
Return Value
The function returns the matrix product of array1 and array2. If the dimensions of the two arrays are not compatible for matrix multiplication, Excel will return the #VALUE! error.
Matrix Multiplication Rule
Matrix multiplication is only possible if the number of columns in the first matrix (array1) matches the number of rows in the second matrix (array2).
For example:
- If array1 is a 2×3 matrix (2 rows, 3 columns), array2 must be a 3×2 matrix (3 rows, 2 columns) for the multiplication to be valid.
- The result will be a new matrix with dimensions 2×2 (the number of rows from array1 and the number of columns from array2).
How It Works
- The element in row i, column j of the resulting matrix is the sum of the product of the corresponding elements from row i of array1 and column j of array2.
For example: If matrix A is:
And matrix B is:
Then the result of A × B will be:
Example Usage
Example 1: 2×3 and 3×2 Matrix Multiplication
Let’s say we have two matrices:
- Matrix 1 (A1:C2):
| 1 | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
- Matrix 2 (D1:E3):
| 7 | 8 |
|---|---|
| 9 | 10 |
| 11 | 12 |
To multiply these two matrices, you would use the MMULT function like this:
=MMULT(A1:C2, D1:E3)
The result will be a 2×2 matrix:
Which simplifies to:
Example 2: Multiplying a 3×1 Matrix with a 1×3 Matrix (Vector Multiplication)
If you multiply a 3×1 matrix (a column vector) with a 1×3 matrix (a row vector), you get a 3×3 matrix.
- Matrix 1 (A1:A3): | 1 | |—| | 2 | | 3 |
- Matrix 2 (B1:D1): | 4 | 5 | 6 |
You can use the MMULT function to multiply these:
=MMULT(A1:A3, B1:D1)
The result will be:
Which simplifies to:
Important Notes
- The MMULT function in Excel requires that the dimensions of the matrices are compatible for multiplication (i.e., the number of columns in the first matrix equals the number of rows in the second matrix).
- The function will return a #VALUE! error if the matrices have incompatible dimensions.
- Array Formula: In some versions of Excel (especially older versions), you may need to enter the MMULT function as an array formula. To do this, after typing the formula, press Ctrl+Shift+Enter instead of just Enter.
Common Uses
- Financial Analysis: For portfolio analysis, matrix multiplication can be used to calculate the total return on a portfolio with multiple assets.
- Linear Algebra: Matrix multiplication is a fundamental operation in solving systems of equations, transformations, and more.
- Data Science: Used in statistical methods like regression and machine learning for operations involving covariance matrices or weight matrices.