Matrix multiplication in Excel vba?

What is Matrix Multiplication on Excel?

In Excel, we have an inbuilt function for matrix multiplication. This is a MMULT function. It takes two arrays as an argument and returns the product of the two arrays, given that both arrays must have the same number of rows and columns. How to do Matrix Multiplication in excel VBA?

Finding a matrix product AB

Suppose A is an n × m matrix and B is an m × p matrix. The order of AB is then n × p.
To find AB in Excel, simply enter the numbers in the matrices anywhere on your spreadsheet. Perform the following steps:

• Select an empty n × p block of cells in your spreadsheet(if you know your matrix product is an n × p matrix).
• Press the “F2” key.
• Press the “=” sign.
• Type in “MMULT(”.
• Select the cells containing A and enter a comma (,).
• Select the cells containing B.
• Close the bracket “)”.
• Hold down the keys “Ctrl” and “Shift” at the same time and press the “Enter” key while holding down the other two.

Matrix multiplication in Excel vba?

b) We multiply Row by Column and the first matrix has 2 rows and the second has 2 columns, so the resulting matrix will have 2 rows by 2 columns.. Highlight the cells where you want to place the resulting matrix E:

What is Matrix multiplication in Excel vba?
Matrix multiplication in Excel vba?

c) Once you have highlighted the resulting matrix, and while it is still highlighted, enter the following formula:

=MMULT(B2:D3,G2:H4)

d) When the formula is entered, press the Ctrl key and the Shift key simultaneously, then press the Enter key. This will change the formula you just wrote to:

{=MMULT(B2:D3,G2:H4)}

If you don’t press these keys simultaneously (holding down Shift and Ctrl then press Return), the result will appear only in one cell or, you will get some error message).

e) The resulting matrix will be:

What is Matrix multiplication in Excel vba?
Matrix multiplication in Excel vba?
What is Matrix multiplication in Excel vba?
Matrix multiplication in Excel vba?

How to subtract matrices

  1. Enter the data of each matrix.
  2. Highlight another section of the worksheet (near the given matrices) that has the same dimensions as the answer matrix. Let’s say that we wish to find: [A] – [B] Since we are subtracting two 3 x 3 matrices, the difference matrix will also be 3 x 3.
What is Matrix multiplication in Excel vba?
Matrix multiplication in Excel vba?
  1. Type: =(A2:C4)–(E2:G4) (This will appear in the formula bar.)
  2. Since this answer will result in an array (matrix), you will need to: CTRL+SHIFT+ENTER

How to find the transpose of a matrix

  1. Enter the elements of the given matrix.
  2. Highlight another section of the worksheet (near the given matrix) that has the same dimensions as the answer matrix.

Since we are finding the transpose of a 2 x 3 matrix, the answer will be a 3 x 2 matrix.

What is Matrix multiplication in Excel vba?
Matrix multiplication in Excel vba?
  1. Type: = TRANSPOSE(A2:C3) (This will appear in the formula bar.)
  2. Since this answer will result in an array (matrix), you will need to: CTRL+SHIFT+ENTER

How to multiply a matrix by a scalar (real number)

  1. Enter the elements of the given matrix.
  2. Highlight another section of the worksheet (near the given matrix) that has the same dimensions as the answer matrix.

Let’s say that we wish to multiply the given matrix of a scalar of three (3). Since we are multiplying a 4 x 3 matrix by the scalar, our result will also be a 4 x 3 matrix.

What is Matrix multiplication in Excel vba?
Matrix multiplication in Excel vba?
  1. Type: = 3*(A3:C6) (This will appear in the formula bar.)
  2. Since this answer will result in an array (matrix), you will need to: CTRL+SHIFT+ENTER

How to find the inverse of a square matrix

  1. Enter the square matrix that is to be inverted.
  2. Highlight another section of the worksheet (near the given matrix) that has the same dimensions as the given square matrix.
    Since we were given a 3 x 3 matrix, its inverse will also be a 3 x 3 matrix.
What is Matrix multiplication in Excel vba?
Matrix multiplication in Excel vba?
  1. Type: = MINVERSE(A2:C4) (This will appear in the formula bar.)
  2. Since this answer will result in an array (matrix), you will need to: CTRL+SHIFT+ENTER

How to find the determinant of a square matrix

  1. Enter the given square matrix.
  2. Highlight a cell of the worksheet (near the given matrix) where you wish the answer to appear.
    In the diagram at the right, the answer will appear in cell
    G2.
What is Matrix multiplication in Excel vba?
Matrix multiplication in Excel vba?
  1. Type: = MDETERM(A2:C4) (This will appear in the formula bar.)
  2. Since this answer will NOT result in an array (matrix) of more than one answer, you may just press ENTER

My name is Megha, A computer science student with a passion for digital marketing and SEO, enjoys helping beginners build impressive WordPress websites.

Leave a Comment