# Nakafa Learning Content

> For AI agents: use [llms.txt](https://nakafa.com/llms.txt) for the site index. Markdown versions are available by appending `.md` to content URLs or sending `Accept: text/markdown`.

URL: https://nakafa.com/en/subjects/mathematics/matrix/matrix-multiplication
Source: https://raw.githubusercontent.com/nakafaai/nakafa.com/refs/heads/main/packages/contents/material/lesson/mathematics/matrix/matrix-multiplication/en.mdx

Learn matrix multiplication rules, conditions, properties, and real-world applications through worked calculations.

---

## Understanding the Multiplication of Two Matrices

Matrix multiplication is a fundamental operation in linear algebra. Unlike matrix addition or subtraction where elements are operated on directly, matrix multiplication has its own specific rules.

### Condition for Matrix Multiplication

Two matrices, let's say matrix $$A$$ and matrix $$B$$, can be multiplied ($$A \times B$$) only if **the number of columns in matrix $$A$$ is equal to the number of rows in matrix $$B$$**.

Visible text: Two matrices, let's say matrix and matrix , can be multiplied () only if **the number of columns in matrix is equal to the number of rows in matrix **.

Suppose matrix $$A$$ has an order of $$m \times n$$ (meaning $$m$$ rows and $$n$$ columns) and matrix $$B$$ has an order of $$n \times p$$ (meaning $$n$$ rows and $$p$$ columns).

Visible text: Suppose matrix has an order of (meaning rows and columns) and matrix has an order of (meaning rows and columns).

Since the number of columns in matrix $$A$$ ($$n$$) is equal to the number of rows in matrix $$B$$ ($$n$$), then matrix $$A$$ and $$B$$ can be multiplied.

Visible text: Since the number of columns in matrix () is equal to the number of rows in matrix (), then matrix and can be multiplied.

The result of the multiplication, let's call it matrix $$C = AB$$, will have an order of $$m \times p$$.

Visible text: The result of the multiplication, let's call it matrix , will have an order of .

### How to Calculate the Elements of the Resultant Matrix

The element $$c_{ij}$$ in matrix $$C$$ (i.e., the element in the $$i$$-th row and $$j$$-th column) is calculated by multiplying each element in the $$i$$-th row of matrix $$A$$ by the corresponding element in the $$j$$-th column of matrix $$B$$, and then summing all these products.

Visible text: The element in matrix (i.e., the element in the -th row and -th column) is calculated by multiplying each element in the -th row of matrix by the corresponding element in the -th column of matrix , and then summing all these products.

Mathematically, if $$A = [a_{ik}]$$ and $$B = [b_{kj}]$$, then the element $$c_{ij}$$ of matrix $$C = AB$$ is:

Visible text: Mathematically, if and , then the element of matrix is:

```math
c_{ij} = \sum_{k=1}^{n} a_{ik}b_{kj} = a_{i1}b_{1j} + a_{i2}b_{2j} + \dots + a_{in}b_{nj}
```

The notation $$\sum$$ (sigma) means summation.

Visible text: The notation (sigma) means summation.

In the formula above, we sum the products $$a_{ik}b_{kj}$$ for all values of $$k$$ from $$1$$ to $$n$$.

Visible text: In the formula above, we sum the products for all values of from to .

## Steps to Multiply Matrices

Let's look at a simple example to understand the process.

Suppose we have matrices $$P = \begin{bmatrix} p_{11} & p_{12} \\ p_{21} & p_{22} \end{bmatrix}$$ and $$Q = \begin{bmatrix} q_{11} & q_{12} \\ q_{21} & q_{22} \end{bmatrix}$$.

Visible text: Suppose we have matrices and .

Matrix $$P$$ has an order of $$2 \times 2$$ and matrix $$Q$$ also has an order of $$2 \times 2$$. The number of columns in $$P$$ (which is $$2$$) is equal to the number of rows in $$Q$$ (which is $$2$$), so we can multiply them. The result, $$R = PQ$$, will have an order of $$2 \times 2$$.

Visible text: Matrix has an order of and matrix also has an order of . The number of columns in (which is ) is equal to the number of rows in (which is ), so we can multiply them. The result, , will have an order of .

```math
R = \begin{bmatrix} r_{11} & r_{12} \\ r_{21} & r_{22} \end{bmatrix}
```

The elements of matrix $$R$$ are calculated as follows:

Visible text: The elements of matrix are calculated as follows:

Component: MathContainer
Children:

```math
r_{11} = (\text{row 1 of } P) \cdot (\text{column 1 of } Q) = p_{11}q_{11} + p_{12}q_{21}
```

```math
r_{12} = (\text{row 1 of } P) \cdot (\text{column 2 of } Q) = p_{11}q_{12} + p_{12}q_{22}
```

```math
r_{21} = (\text{row 2 of } P) \cdot (\text{column 1 of } Q) = p_{21}q_{11} + p_{22}q_{21}
```

```math
r_{22} = (\text{row 2 of } P) \cdot (\text{column 2 of } Q) = p_{21}q_{12} + p_{22}q_{22}
```

## Example of Multiplying Two Matrices

Given two matrices:

Component: MathContainer
Children:

```math
A = \begin{bmatrix} -7 & 2 & -2 \\ 1 & 0 & -1 \\ 2 & 3 & -1 \end{bmatrix}
```

```math
B = \begin{bmatrix} 1 & 2 \\ -1 & 3 \\ 2 & 0 \end{bmatrix}
```

Matrix $$A$$ has an order of $$3 \times 3$$ and matrix $$B$$ has an order of $$3 \times 2$$.

Visible text: Matrix has an order of and matrix has an order of .

The number of columns in matrix $$A$$ (which is $$3$$) is equal to the number of rows in matrix $$B$$ (which is $$3$$).

Visible text: The number of columns in matrix (which is ) is equal to the number of rows in matrix (which is ).

So, $$AB$$ can be calculated and will result in a matrix of order $$3 \times 2$$.

Visible text: So, can be calculated and will result in a matrix of order .

Let's calculate $$C = AB$$:

Visible text: Let's calculate :

Component: MathContainer
Children:

```math
C = \begin{bmatrix} c_{11} & c_{12} \\ c_{21} & c_{22} \\ c_{31} & c_{32} \end{bmatrix}
```

```math
c_{11} = (-7)(1) + (2)(-1) + (-2)(2) = -7 - 2 - 4 = -13
```

```math
c_{12} = (-7)(2) + (2)(3) + (-2)(0) = -14 + 6 + 0 = -8
```

```math
c_{21} = (1)(1) + (0)(-1) + (-1)(2) = 1 + 0 - 2 = -1
```

```math
c_{22} = (1)(2) + (0)(3) + (-1)(0) = 2 + 0 + 0 = 2
```

```math
c_{31} = (2)(1) + (3)(-1) + (-1)(2) = 2 - 3 - 2 = -3
```

```math
c_{32} = (2)(2) + (3)(3) + (-1)(0) = 4 + 9 + 0 = 13
```

So, the result of the matrix multiplication $$AB$$ is:

Visible text: So, the result of the matrix multiplication is:

```math
AB = \begin{bmatrix} -13 & -8 \\ -1 & 2 \\ -3 & 13 \end{bmatrix}
```

Now, what about $$BA$$?

Visible text: Now, what about ?

Matrix $$B$$ has an order of $$3 \times 2$$ and matrix $$A$$ has an order of $$3 \times 3$$.

Visible text: Matrix has an order of and matrix has an order of .

The number of columns in matrix $$B$$ (which is $$2$$) is **not equal** to the number of rows in matrix $$A$$ (which is $$3$$).

Visible text: The number of columns in matrix (which is ) is **not equal** to the number of rows in matrix (which is ).

Therefore, the multiplication $$BA$$ is **undefined**. This illustrates one of the important properties of matrix multiplication.

Visible text: Therefore, the multiplication is **undefined**. This illustrates one of the important properties of matrix multiplication.

## Properties of Matrix Multiplication

Matrix multiplication has several important properties:

1.  **Generally Not Commutative**:

    This means $$AB \neq BA$$. We have already seen an example above where $$AB$$ is defined but $$BA$$ is not. Even if both are defined, the results are not necessarily the same.

2.  **Associative**:

    If the matrix multiplications $$A, B,$$ and $$C$$ are defined, then $$(AB)C = A(BC)$$ holds. This means the order of grouping the multiplication does not change the final result.

3.  **Distributive**:

    Matrix multiplication is distributive over matrix addition or subtraction:

    <MathContainer>
      
    
    ```math
    A(B + C) = AB + AC
    ```

      
    
    ```math
    (A + B)C = AC + BC
    ```

    </MathContainer>

    This holds if all involved addition and multiplication operations are defined.

4.  **Multiplication by Identity Matrix ($$I$$)**:

    If $$A$$ is a square matrix of order $$n \times n$$ and $$I$$ is the identity matrix of order $$n \times n$$, then:

    
    
    ```math
    AI = IA = A
    ```

    The identity matrix acts like the number $$1$$ in ordinary number multiplication.

5.  **Multiplication by a Scalar ($$k$$)**:

    If $$k$$ is a scalar (real number), then:

    
    
    ```math
    k(AB) = (kA)B = A(kB)
    ```

Visible text: 1. **Generally Not Commutative**:

 This means . We have already seen an example above where is defined but is not. Even if both are defined, the results are not necessarily the same.

2. **Associative**:

 If the matrix multiplications and are defined, then holds. This means the order of grouping the multiplication does not change the final result.

3. **Distributive**:

 Matrix multiplication is distributive over matrix addition or subtraction:

 <MathContainer>
 
 

 
 

 </MathContainer>

 This holds if all involved addition and multiplication operations are defined.

4. **Multiplication by Identity Matrix ()**:

 If is a square matrix of order and is the identity matrix of order , then:

 
 

 The identity matrix acts like the number in ordinary number multiplication.

5. **Multiplication by a Scalar ()**:

 If is a scalar (real number), then:

## Calculating Revenue

Matrix multiplication is very useful in various fields, one of which is for managing data and calculating aggregate values.

Imagine a home industry produces three types of food: tempeh chips, banana chips, and potato chips.

These foods are marketed in three places: Place A, Place B, and Place C.

The number of chips (in jars) sold in each place is presented in matrix $$P$$. The columns in matrix $$P$$ respectively represent Place A, Place B, and Place C, while the rows respectively represent tempeh chips, banana chips, and potato chips.

Visible text: The number of chips (in jars) sold in each place is presented in matrix . The columns in matrix respectively represent Place A, Place B, and Place C, while the rows respectively represent tempeh chips, banana chips, and potato chips.

```math
P = \begin{bmatrix} 15 & 12 & 20 \\ 25 & 10 & 15 \\ 15 & 15 & 20 \end{bmatrix} \begin{matrix} \text{Tempeh Chips} \\ \text{Banana Chips} \\ \text{Potato Chips} \end{matrix}
```

The first row ($$\begin{bmatrix} 15 & 12 & 20 \end{bmatrix}$$) means $$15$$ jars of tempeh chips were sold in Place A, $$12$$ in Place B, and $$20$$ in Place C.

Visible text: The first row () means jars of tempeh chips were sold in Place A, in Place B, and in Place C.

The price for each jar of chips (in rupiah) is stated in the column matrix $$Q$$ below:

Visible text: The price for each jar of chips (in rupiah) is stated in the column matrix below:

```math
Q = \begin{bmatrix} 20{,}000 \\ 15{,}000 \\ 30{,}000 \end{bmatrix} \begin{matrix} \text{Price of Tempeh Chips} \\ \text{Price of Banana Chips} \\ \text{Price of Potato Chips} \end{matrix}
```

To determine the total revenue from each type of chip across all places, we can multiply matrix $$P$$ by matrix $$Q$$.

Visible text: To determine the total revenue from each type of chip across all places, we can multiply matrix by matrix .

However, pay attention to the order of the matrices. Matrix $$P$$ has an order of $$3 \times 3$$ and matrix $$Q$$ has an order of $$3 \times 1$$. The number of columns in $$P$$ ($$3$$) is equal to the number of rows in $$Q$$ ($$3$$), so $$PQ$$ can be calculated and will result in a matrix $$R$$ of order $$3 \times 1$$.

Visible text: However, pay attention to the order of the matrices. Matrix has an order of and matrix has an order of . The number of columns in () is equal to the number of rows in (), so can be calculated and will result in a matrix of order .

Matrix $$R = PQ$$ will show the total revenue for each type of chip.

Visible text: Matrix will show the total revenue for each type of chip.

Component: MathContainer
Children:

```math
R = PQ = \begin{bmatrix} 15 & 12 & 20 \\ 25 & 10 & 15 \\ 15 & 15 & 20 \end{bmatrix} \begin{bmatrix} 20{,}000 \\ 15{,}000 \\ 30{,}000 \end{bmatrix}
```

```math
R = \begin{bmatrix} (15)(20{,}000) + (12)(15{,}000) + (20)(30{,}000) \\ (25)(20{,}000) + (10)(15{,}000) + (15)(30{,}000) \\ (15)(20{,}000) + (15)(15{,}000) + (20)(30{,}000) \end{bmatrix}
```

```math
R = \begin{bmatrix} 300{,}000 + 180{,}000 + 600{,}000 \\ 500{,}000 + 150{,}000 + 450{,}000 \\ 300{,}000 + 225{,}000 + 600{,}000 \end{bmatrix}
```

```math
R = \begin{bmatrix} 1{,}080{,}000 \\ 1{,}100{,}000 \\ 1{,}125{,}000 \end{bmatrix} \begin{matrix} \text{Total Revenue from Tempeh Chips} \\ \text{Total Revenue from Banana Chips} \\ \text{Total Revenue from Potato Chips} \end{matrix}
```

From matrix $$R$$, we can see that the total revenue from the sale of tempeh chips is $$\text{Rp}1{,}080{,}000$$, banana chips $$\text{Rp}1{,}100{,}000$$, and potato chips $$\text{Rp}1{,}125{,}000$$.

Visible text: From matrix , we can see that the total revenue from the sale of tempeh chips is , banana chips , and potato chips .

If the question is "determine the revenue matrix for each place", then we need to arrange the price matrix $$Q$$ differently or perform multiplication with the transpose of $$P$$.

Visible text: If the question is "determine the revenue matrix for each place", then we need to arrange the price matrix differently or perform multiplication with the transpose of .

Suppose we want to find the total revenue in Place A, Place B, and Place C. We can use the price matrix as a row matrix $$Q^T = \begin{bmatrix} 20{,}000 & 15{,}000 & 30{,}000 \end{bmatrix}$$ and multiply it by matrix $$P$$: $$S = Q^T P$$.

Visible text: Suppose we want to find the total revenue in Place A, Place B, and Place C. We can use the price matrix as a row matrix and multiply it by matrix : .

Matrix $$Q^T$$ has an order of $$1 \times 3$$ and $$P$$ has an order of $$3 \times 3$$. The result $$S$$ will have an order of $$1 \times 3$$.

Visible text: Matrix has an order of and has an order of . The result will have an order of .

Component: MathContainer
Children:

```math
S = \begin{bmatrix} 20{,}000 & 15{,}000 & 30{,}000 \end{bmatrix} \begin{bmatrix} 15 & 12 & 20 \\ 25 & 10 & 15 \\ 15 & 15 & 20 \end{bmatrix}
```

```math
s_{11} = (20{,}000)(15) + (15{,}000)(25) + (30{,}000)(15) = 300{,}000 + 375{,}000 + 450{,}000 = 1{,}125{,}000
```

```math
s_{12} = (20{,}000)(12) + (15{,}000)(10) + (30{,}000)(15) = 240{,}000 + 150{,}000 + 450{,}000 = 840{,}000
```

```math
s_{13} = (20{,}000)(20) + (15{,}000)(15) + (30{,}000)(20) = 400{,}000 + 225{,}000 + 600{,}000 = 1{,}225{,}000
```

Thus, $$S = \begin{bmatrix} 1{,}125{,}000 & 840{,}000 & 1{,}225{,}000 \end{bmatrix}$$.

Visible text: Thus, .

This means the total revenue from Place A is $$\text{Rp}1{,}125{,}000$$, from Place B is $$\text{Rp}840{,}000$$, and from Place C is $$\text{Rp}1{,}225{,}000$$.

Visible text: This means the total revenue from Place A is , from Place B is , and from Place C is .

The interpretation of the elements of the resulting matrix greatly depends on how the initial matrices are defined and how the multiplication is performed.

## Exercises

Given the following matrices:

Component: MathContainer
Children:

```math
C = \begin{bmatrix} 1 & -3 \\ 1 & 2 \end{bmatrix}
```

```math
D = \begin{bmatrix} 1 & -4 \\ 8 & 2 \end{bmatrix}
```

Determine the matrices $$CD$$ and $$DC$$.

Visible text: Determine the matrices and .

Is $$CD = DC$$?

Visible text: Is ?

### Answer Key

1.  Calculating $$CD$$:

    Matrix $$C$$ has an order of $$2 \times 2$$ and $$D$$ has an order of $$2 \times 2$$. The result will have an order of $$2 \times 2$$.

    <MathContainer>
      
    
    ```math
    CD = \begin{bmatrix} 1 & -3 \\ 1 & 2 \end{bmatrix} \begin{bmatrix} 1 & -4 \\ 8 & 2 \end{bmatrix}
    ```

      
    
    ```math
    CD = \begin{bmatrix} (1)(1) + (-3)(8) & (1)(-4) + (-3)(2) \\ (1)(1) + (2)(8) & (1)(-4) + (2)(2) \end{bmatrix}
    ```

      
    
    ```math
    CD = \begin{bmatrix} 1 - 24 & -4 - 6 \\ 1 + 16 & -4 + 4 \end{bmatrix}
    ```

      
    
    ```math
    CD = \begin{bmatrix} -23 & -10 \\ 17 & 0 \end{bmatrix}
    ```

    </MathContainer>

2.  Calculating $$DC$$:

    Matrix $$D$$ has an order of $$2 \times 2$$ and $$C$$ has an order of $$2 \times 2$$. The result will have an order of $$2 \times 2$$.

    <MathContainer>
      
    
    ```math
    DC = \begin{bmatrix} 1 & -4 \\ 8 & 2 \end{bmatrix} \begin{bmatrix} 1 & -3 \\ 1 & 2 \end{bmatrix}
    ```

      
    
    ```math
    DC = \begin{bmatrix} (1)(1) + (-4)(1) & (1)(-3) + (-4)(2) \\ (8)(1) + (2)(1) & (8)(-3) + (2)(2) \end{bmatrix}
    ```

      
    
    ```math
    DC = \begin{bmatrix} 1 - 4 & -3 - 8 \\ 8 + 2 & -24 + 4 \end{bmatrix}
    ```

      
    
    ```math
    DC = \begin{bmatrix} -3 & -11 \\ 10 & -20 \end{bmatrix}
    ```

    </MathContainer>

Visible text: 1. Calculating :

 Matrix has an order of and has an order of . The result will have an order of .

 <MathContainer>
 
 

 
 

 
 

 
 

 </MathContainer>

2. Calculating :

 Matrix has an order of and has an order of . The result will have an order of .

 <MathContainer>
 
 

 
 

 
 

 
 

 </MathContainer>

From the results above, it is clear that $$CD = \begin{bmatrix} -23 & -10 \\ 17 & 0 \end{bmatrix}$$ and $$DC = \begin{bmatrix} -3 & -11 \\ 10 & -20 \end{bmatrix}$$.

Visible text: From the results above, it is clear that and .

So, $$CD \neq DC$$. This is another example showing that matrix multiplication is generally not commutative.

Visible text: So, . This is another example showing that matrix multiplication is generally not commutative.