Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

How to Multiply Matrices?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The knowledge of matrices is necessary for various branches of mathematics. Matrices are one of the most powerful tools in mathematics. In linear algebra, matrix multiplication is one of the binary operations that can be performed on matrices. The multiplication of any two matrices A and B is possible only if both matrices are compatible.  A “matrix” is referred to as a rectangular array of numbers that are arranged in rows and columns. The horizontal lines are said to be rows, while the vertical lines are said to be columns. If a matrix has “m” rows and “n” columns, then it is said to be an “m by n” matrix and is written as an “m × n” matrix. We can perform different binary operations on matrices, like addition, subtraction, multiplication, etc. In this article, we will learn about matrix multiplication in detail.

Multiplication of Matrices

Matrix multiplication is a very simple thing in mathematics. If do multiply with a number, then just multiply the number with all the elements present in the matrix. But if we multiply a matrix with another matrix then we must see some rules. The multiplication of any two matrices gives a single matrix, and it is possible only if the number of columns in the 1st matrix is equal to the number of rows in the 2nd matrix. If “A = [aij]m×n” and “B = [bij]n×p” are two matrices, then the product of A and B is denoted as AB, whose order is “m × p.” Usually, matrix multiplication is not commutative, i.e., AB ≠ BA, or, in simple words, the product of A and B matrices is AB but not BA.

Conditions for Multiplication of Matrices

Note that the multiplication of any two matrices is possible only if both matrices are compatible. We can multiply two matrices if the number of columns in the 1st matrix is equal to the number of rows in the 2nd matrix, otherwise, the given matrices cannot be multiplied.

  1. Let’s say a matrix of size 2×3 and another matrix of size 3×2, then we can apply the multiplication between those matrices because the number of columns and rows are the same in both the matrices. And the resultant matrix will be 2×2
  2. Let’s say a matrix of size 3×3 and another matrix of size 4×2, then we cannot apply the multiplication between those matrices because the number of columns and rows are not the same in both the matrices.

Multiplying Matrices by Matrices

Let’s consider 2 matrices of 3 × 3 have elements [aij] and [bij] respectively. The multiplication will be like the below image:

There is some rule,

  1. Take the first matrix’s 1st row and multiply the values with the second matrix’s 1st column. Don’t multiply the rows with the rows or columns with the columns.
  2. In 1st iteration, multiply the row value by the column value and sum those values. Here in this picture, [a00] is multiplying with [b00], then the 2nd value of the 1st column of 1st matrix [a10] is multiplying with the 2nd value of the 1st row of the 2nd matrix [b01].  Similarly, all the values are multiplying.
  3. Then after one iteration all the production values are summed up together and placed as the elements of the resultant matrix as the picture shows.

Matrix Multiplication formula for “2 × 2” Matrices

The process of multiplication is the same for matrices for any order. We must multiply each element of each row of the first matrix by the elements of each column in the second matrix and add all the products to obtain the resultant matrix. Let us consider two matrices “2 × 2” matrices A and B.

A = \left[\begin{array}{cc} a & b\\ c & d \end{array}\right] and B = \left[\begin{array}{cc} p & q\\ r & s \end{array}\right]

AB = \left[\begin{array}{cc} a & b\\ c & d \end{array}\right] \times \left[\begin{array}{cc} p & q\\ r & s \end{array}\right]

AB = \left[\begin{array}{cc} (ap+br) & (aq+bs)\\ (cp+dr) & (cq+ds) \end{array}\right]

Matrix Multiplication formula for “3 × 3” Matrices

Let us consider two matrices “3 × 3” matrices P and Q. Now, the matrix multiplication formula of “3 × 3” matrices are shown as follows:

X = \left[\begin{array}{ccc} x_{11} & x_{12} & x_{13}\\ x_{21} & x_{22} & x_{23}\\ x_{31} & x_{32} & x_{33} \end{array}\right]

Y = \left[\begin{array}{ccc} y_{11} & y_{12} & y_{13}\\ y_{21} & y_{22} & y_{23}\\ y_{31} & y_{32} & y_{33} \end{array}\right]

XY = \left[\begin{array}{ccc} (x_{11}y_{11}+x_{12}y_{21}+x_{13}y_{31}) & (x_{11}y_{12}+x_{12}y_{22}+x_{13}y_{32}) & (x_{11}y_{13}+x_{12}y_{23}+x_{13}y_{33})\\ (x_{21}y_{11}+x_{22}y_{21}+x_{23}y_{31}) & (x_{21}y_{12}+x_{22}y_{22}+x_{23}y_{32}) & (x_{21}y_{13}+x_{22}y_{23}+x_{23}y_{33})\\ (x_{31}y_{11}+x_{32}y_{21}+x_{33}y_{31}) & (x_{31}y_{12}+x_{32}y_{22}+x_{33}y_{32}) & (x_{31}y_{13}+x_{32}y_{23}+x_{33}y_{33}) \end{array}\right]

Example: Multiply the matrices given below.

\left[\begin{array}{ccc} 3 & -5 & 1\\ -2 & 0 & 4\\ -1 & 6 & 5 \end{array}\right]\left[\begin{array}{ccc} 7 & 2 & 4\\ 0 & 1 & -5\\ 1 & 3 & 2 \end{array}\right]

Solution: 

\left[\begin{array}{ccc} 3 & -5 & 1\\ -2 & 0 & 4\\ -1 & 6 & 5 \end{array}\right]\times\left[\begin{array}{ccc} 7 & 2 & 4\\ 0 & 1 & -5\\ 1 & 3 & 2 \end{array}\right]

=\left[\begin{array}{ccc} (21-0+1) & (6-5+3) & (12-25+2)\\ (-14+0+4) & (-4+0+12) & (-8-0+10)\\ (-7+0+5) & (-2+6+15) & (-4-30+10) \end{array}\right]

=\left[\begin{array}{ccc} 22 & 4 & -11\\ -10 & 8 & 2\\ -2 & 19 & -24 \end{array}\right]

Matrix multiplication by a Scalar Value

A matrix can be multiplied by a scalar value, which is called scalar multiplication, and also by a matrix, which is called matrix multiplication. Scalar multiplication is the multiplication of a matrix by a scalar value. When a matrix “A = [aij]” is multiplied by a scalar value “k,” every element of the given matrix is multiplied by the scalar value. The resultant matrix is expressed as kA, where kA = k[aij] = [kaij], for all the values of i and j.

Example: 

A = \left[\begin{array}{cc} a & b\\ c & d \end{array}\right]

kA = k \times\left[\begin{array}{cc} a & b\\ c & d \end{array}\right]= \left[\begin{array}{cc} ka & kb\\ kc & kd \end{array}\right]

Properties of Multiplication of Matrices

The following are some important properties of the multiplication of matrices:

  • Commutative Property: The matrix multiplication is usually not commutative. If A and B are two matrices, then AB ≠ BA. 
  • Associative Property: The matrix multiplication is associative in nature. If A, B, and C are three matrices, then A(BC) = (AB)C if the products A(BC) and (AB)C are defined.
  • Distributive Property: If A, B, and C are three matrices, then by applying the distributive property, we get A (B + C) = AB + BC, if and only if A, B, and C are compatible.
  • Product with a Scalar: If A and B are two matrices and AB is defined, then k(AB) = (kA)B = A(Bk), where k is a scalar value.
  • Determinant: If A and B are two matrices and AB is defined, then the determinant of the matrix “AB” is equal to the product of the determinants of matrices A and B, i.e., det (AB) = det A × det B.
  • Transpose: If A and B are two matrices and AB is defined, then (AB)T = BTAT, where T represents the transpose of a matrix. 
  • Complex Conjugate: If A and B are two complex matrices, then (AB)* = B*A*.
    The product of any two non-zero matrices may result in a zero matrix, i.e., if AB = O, then that doesn’t mean that A = O or B = O.

Solved Examples

Example 1. Let A =\begin{bmatrix} 1 & 8 & 3\\ 9 & 4 & 5 \\ 6 & 2 & 7 \end{bmatrix}   and B =\begin{bmatrix} 6 & 7 & 4\\ 1 & 3 & 2 \\ 5 & 9 & 8 \end{bmatrix}   Find A×B?

Solution: 

A \times B =\begin{bmatrix} 1 & 8 & 3\\ 9 & 4 & 5 \\ 6 & 2 & 7 \end{bmatrix} \times \begin{bmatrix} 6 & 7 & 4\\ 1 & 3 & 2 \\ 5 & 9 & 8 \end{bmatrix}       

=\begin{bmatrix} (1*6 + 8*1 + 3*5) & (1*7 + 8*3 + 3*9) & (1*4 + 8*2 + 3*8)\\ (9*6 + 4*1 + 5*5) & (9*7 + 4*3 + 5*9) & (9*4 + 4*2 + 5*8) \\ (6*6 + 2*1 + 7*5) & (6*7 + 2*3 + 7*9) & (6*4 + 2*2 + 7*8) \end{bmatrix}

=\begin{bmatrix} 29 & 58 & 44\\ 83 & 120 & 84 \\ 73 & 111 & 84 \end{bmatrix}

Example 2. Let  A =\begin{bmatrix} 1 & 5 & 4\\ 9 & 3 & 8 \end{bmatrix}   and B =\begin{bmatrix} 6 & 7 \\ 1 & 3   \\ 5 & 9 \end{bmatrix}  . Find A×B?

Solution:

A \times B =\begin{bmatrix} (1*6 + 5*1 + 4*5) & (1*7 + 5*3 + 4*9) \\ (9*6 + 3*1 + 8*5) & (9*7 + 3*3 + 8*9)\end{bmatrix}

 =\begin{bmatrix} 31 & 58 \\ 97 & 144\end{bmatrix}

Example 3. Let A=\begin{bmatrix} 2 & 0 & -3\\ 1 & 4 & 5 \end{bmatrix}  ,  B=\begin{bmatrix} 3 & 1\\ -1 & 0 \\ 4 & 2\end{bmatrix}    and C=\begin{bmatrix} 4 & 7\\ 2 & 1 \\ 1 & -1\end{bmatrix}  . Find (AB + AC)?

Solution:

A \times B = \begin{bmatrix} 2 & 0 & -3\\ 1 & 4 & 5 \end{bmatrix}\times \begin{bmatrix} 3 & 1\\ -1 & 0 \\ 4 & 2\end{bmatrix} \\ = \begin{bmatrix} (2*3 + 0*(-1) + (-3)*4) & (2*1 + 0*0 + (-3)*2) \\ (1*3 + 4*(-1) + 5*4) & (1*1 + 4*0 + 5*2)\end{bmatrix}

=\begin{bmatrix} -6 & -4 \\ 19 & 11\end{bmatrix}

A \times C = \begin{bmatrix} 2 & 0 & -3\\ 1 & 4 & 5 \end{bmatrix}\times \begin{bmatrix} 4 & 7\\ 2 & 1 \\ 1 & -1\end{bmatrix} \\ = \begin{bmatrix} (2*4 + 0*2 + (-3)*1) & (2*7 + 0*1 + (-3)*(-1)) \\ (1*4 + 4*2 + 5*1) & (1*7 + 4*1 + 5*(-1))\end{bmatrix}

=\begin{bmatrix} 5 & 17 \\ 17 & 6\end{bmatrix}

Now calculate (AB + AC)

= \begin{bmatrix} -6 & -4 \\ 19 & 11\end{bmatrix} + \begin{bmatrix} 5 & 17 \\ 17 & 6\end{bmatrix}

(AB +BC)= \begin{bmatrix} -1 & 13 \\ 36 & 17\end{bmatrix}

Example 4. Let A=\begin{bmatrix} 2  & -2\\ -2 & 2\end{bmatrix}   , and A^2=pA  , then find the value of p?

Solution:

First, calculate A2,

A^2 = A\times A=\begin{bmatrix} 2  & -2\\ -2 & 2\end{bmatrix} \times \begin{bmatrix} 2  & -2\\ -2 & 2\end{bmatrix}

=\begin{bmatrix} (2*2 + (-2)*(-2)) & ((2*(-2) + (-2)*2)  \\ ((-2)*2 + 2*(-2)) & ((-2)*(-2) + 2*2)\end{bmatrix}

=\begin{bmatrix} 8 & -8\\ -8 & 8\end{bmatrix}

Given A^2=pA

By placing the value of A2 in the equation, we get

\begin{bmatrix} 8 & -8\\ -8 & 8\end{bmatrix} = p\begin{bmatrix} 2 & -2\\ -2 & 2\end{bmatrix}

=\begin{bmatrix} 8 & -8\\ -8 & 8\end{bmatrix} = \begin{bmatrix} 2p & -2p\\ -2p & 2p\end{bmatrix}

Now, we can write, 

8 = 2p and, -8 = -2p

So, p = 4

The value of p is 4.

Example 5: Find the value of 3P if P = \left[\begin{array}{ccc} 2 & -3 & 4\\ 1 & 0 & 5\\ 7 & -4 & 6 \end{array}\right]   .

Solution:

3P = 3 \times\left[\begin{array}{ccc} 2 & -3 & 4\\ 1 & 0 & 5\\ 7 & -4 & 6 \end{array}\right]

3P = \left[\begin{array}{ccc} 3\times2 & 3\times-3 & 3\times4\\ 3\times1 & 3\times0 & 3\times5\\ 3\times7 & 3\times-4 & 3\times6 \end{array}\right]

3P = \left[\begin{array}{ccc} 6 & -9 & 12\\ 3 & 0 & 15\\ 21 & -12 & 18 \end{array}\right]

FAQs on Multiplication of Matrices

Question 1: What is matrix multiplication?

Answer:

In linear algebra, matrix multiplication is one of the binary operations that can be performed on matrices. The multiplication of any two matrices is possible only when the number of columns in the first matrix is equal to the number of rows in the second matrix.

Question 2: Can a “3 × 2” matrix be multiplied with a “3 × 3” matrix?

Answer:

The multiplication of any two matrices is possible only when the number of columns in the first matrix is equal to the number of rows in the second matrix. Here, the first matrix has 2 columns, while the second matrix has 3 rows. So, a “3 × 2” matrix cannot be multiplied with a “3 × 3” matrix as both are not compatible.

Question 3: How can we multiply two matrices?

Answer:

Before multiplying the given matrices, we need to check if the number of columns in the first matrix equals the number of rows in the second matrix. If the matrices satisfy the above requirement, then multiply each element of each row of the first matrix by the elements of each column in the second matrix and add all the products.


My Personal Notes arrow_drop_up
Last Updated : 18 Jan, 2023
Like Article
Save Article
Similar Reads
Related Tutorials