Excel Matrix Multiplication

Last Updated :

-

Blog Author :

Edited by :

Reviewed by :

Table Of Contents

arrow

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.

matrix multiplication explanation

Then, the product of A*B is as follows:

matrix multiplication explanation1

  • 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.

Excel Matrix Multiplication

Syntax

The required syntax that we should follow for the matrix multiplication is:

matrix multiplication syntax
  • 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.

  1. Firstly, we must enter data into the array.


    matrix multiplication example 1.1

  2. Then, we must select a scalar value that we need to multiply with an array, i.e., 3.


    matrix multiplication example 1.2

  3. Estimate the rows and columns of the resultant array. Here, the resultant array will be of size 3 x 3.

  4. 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.


    matrix multiplication example 1.3

  5. On entering the formula, we must press Ctrl + Shift + Enter. We can see the result as shown in the below image.


    matrix multiplication example 1.4

Example #2 - Matrix Multiplication Of Two Individual Arrays

  • Step 1: First, we should enter data into an array A size of 3×3.
matrix multiplication example 2.1
  • Step 2: Then, insert data into the second array called B size of 3×3.
matrix multiplication example 2.2
  • 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.
matrix multiplication example 2.3

Next, we must insert the values to calculate the product of A and B.

matrix multiplication example 2.4

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.

matrix multiplication example 2.5

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 multiplication example 3.1

Matrix A is 3×1, and matrix B is 1×3. The size of the product A*The B matrix is 3×3.

matrix multiplication example 3.2

So, the answer will be:

matrix multiplication example 3.3

Example #4 - Determining The Square Of A Matrix Using MMULT in Excel

example 5.1

The square of matrix A is determined by multiplying A with A.

example 5.2

We can see the result as shown in the below image.

example 5.3

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

1. Explain matrix multiplication with an example.

Consider the below example.

matrix multiplication example 3.1

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.

matrix multiplication example 3.3

2. Why is matrix multiplication important in machine learning?

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.

3. What is the value error in Excel matrix multiplication?

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.