Excel Matrix Multiplication
Last Updated :
-
Blog Author :
Edited by :
Reviewed by :
Table Of Contents
What Is Matrix Multiplication In 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.
Let us consider the below image.
Then, the product of A*B is as follows:
Table of contents
- MMULT function in Excel multiplies two arrays and requires that they have the same number of rows and columns.
- For matrix multiplication to work, the number of columns in array1 and the number of rows in array2 must be the same. Use CTRL+SHIFT+ENTER to multiply arrays and avoid null elements and text in matrices to prevent errors.
- The product array size depends on the number of rows in the first array and columns in the second. Matrix multiplication of A*B and B*A are not equal. Multiplying a matrix with a unit matrix results in the same matrix (i.e., *=).
Explanation
Matrix multiplication is one of the useful features of excel 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.
We can use the already available MMULT function 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 excel.
The Excel formula used for multiplication 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 functions used in worksheets to perform calculations in a short time.
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. We can insert this as a formula or worksheet function in Excel calculations.
How To Do Matrix Multiplication In Excel?
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.
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. We can see the result as shown in the below image.
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 columns 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 Single Column And A Single Row
Matrix multiplication between arrays with a single row and single column. Let's consider the elements of matrices as follows:
Matrix A is 3×1, and matrix B is 1×3. The size of the product A*The B matrix is 3×3.
So, the answer will be:
Example #4 - Determining The Square Of A Matrix Using MMULT in Excel
The square of matrix A is determined by multiplying A with A.
We can see the result as shown in the below image.
Important Things To Note
- 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.
- We need to use CTRL+SHIFT+ENTER 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., *=).
Frequently Asked Questions
Consider the below example.
Matrix A is 1×3, and matrix B is 3×1. So the size of the product A*B matrix is 1×1. So, we must now insert the matrix multiplication formula in the cell.
So, the formula is =MMULT(B2:D2,B4:B6)
Press the "Enter" key to get the result.
The application of matrix operations in machine learning is a topic of significant importance. Linear Regression is one of the areas where we use this operation. Through matrix multiplication, optimal feature weights are calculated, which enable the minimization of the difference between predicted and actual values. This approach is a crucial aspect of machine learning, allowing for more accurate analysis and predictions in various domains.
In order to multiply two matrices, the number of columns in the first matrix (Matrix 1) should be equal to the number of rows in the second matrix (Matrix 2). If this condition is not satisfied, we will get a #VALUE! Error in Excel. This error occurs when the user enters an incorrect formula or uses the wrong data type, usually numerical data.
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: -