Source codeVideos

Command Palette

Search for a command to run...

Matrix

Matrix Multiplication

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 AA and matrix BB, can be multiplied (A×BA \times B) only if the number of columns in matrix AA is equal to the number of rows in matrix BB.

Suppose matrix AA has an order of m×nm \times n (meaning mm rows and nn columns) and matrix BB has an order of n×pn \times p (meaning nn rows and pp columns).

Since the number of columns in matrix AA (nn) is equal to the number of rows in matrix BB (nn), then matrix AA and BB can be multiplied.

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

How to Calculate the Elements of the Resultant Matrix

The element cijc_{ij} in matrix CC (i.e., the element in the ii-th row and jj-th column) is calculated by multiplying each element in the ii-th row of matrix AA by the corresponding element in the jj-th column of matrix BB, and then summing all these products.

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

cij=k=1naikbkj=ai1b1j+ai2b2j++ainbnjc_{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.

In the formula above, we sum the products aikbkja_{ik}b_{kj} for all values of kk from 1 to nn.

Steps to Multiply Matrices

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

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

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

R=[r11r12r21r22]R = \begin{bmatrix} r_{11} & r_{12} \\ r_{21} & r_{22} \end{bmatrix}

The elements of matrix RR are calculated as follows:

r11=(row 1 of P)(column 1 of Q)=p11q11+p12q21r_{11} = (\text{row 1 of } P) \cdot (\text{column 1 of } Q) = p_{11}q_{11} + p_{12}q_{21}
r12=(row 1 of P)(column 2 of Q)=p11q12+p12q22r_{12} = (\text{row 1 of } P) \cdot (\text{column 2 of } Q) = p_{11}q_{12} + p_{12}q_{22}
r21=(row 2 of P)(column 1 of Q)=p21q11+p22q21r_{21} = (\text{row 2 of } P) \cdot (\text{column 1 of } Q) = p_{21}q_{11} + p_{22}q_{21}
r22=(row 2 of P)(column 2 of Q)=p21q12+p22q22r_{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:

A=[722101231]A = \begin{bmatrix} -7 & 2 & -2 \\ 1 & 0 & -1 \\ 2 & 3 & -1 \end{bmatrix}
B=[121320]B = \begin{bmatrix} 1 & 2 \\ -1 & 3 \\ 2 & 0 \end{bmatrix}

Matrix AA has an order of 3×33 \times 3 and matrix BB has an order of 3×23 \times 2.

The number of columns in matrix AA (which is 3) is equal to the number of rows in matrix BB (which is 3).

So, ABAB can be calculated and will result in a matrix of order 3×23 \times 2.

Let's calculate C=ABC = AB:

C=[c11c12c21c22c31c32]C = \begin{bmatrix} c_{11} & c_{12} \\ c_{21} & c_{22} \\ c_{31} & c_{32} \end{bmatrix}
c11=(7)(1)+(2)(1)+(2)(2)=724=13c_{11} = (-7)(1) + (2)(-1) + (-2)(2) = -7 - 2 - 4 = -13
c12=(7)(2)+(2)(3)+(2)(0)=14+6+0=8c_{12} = (-7)(2) + (2)(3) + (-2)(0) = -14 + 6 + 0 = -8
c21=(1)(1)+(0)(1)+(1)(2)=1+02=1c_{21} = (1)(1) + (0)(-1) + (-1)(2) = 1 + 0 - 2 = -1
c22=(1)(2)+(0)(3)+(1)(0)=2+0+0=2c_{22} = (1)(2) + (0)(3) + (-1)(0) = 2 + 0 + 0 = 2
c31=(2)(1)+(3)(1)+(1)(2)=232=3c_{31} = (2)(1) + (3)(-1) + (-1)(2) = 2 - 3 - 2 = -3
c32=(2)(2)+(3)(3)+(1)(0)=4+9+0=13c_{32} = (2)(2) + (3)(3) + (-1)(0) = 4 + 9 + 0 = 13

So, the result of the matrix multiplication ABAB is:

AB=[13812313]AB = \begin{bmatrix} -13 & -8 \\ -1 & 2 \\ -3 & 13 \end{bmatrix}

Now, what about BABA?

Matrix BB has an order of 3×23 \times 2 and matrix AA has an order of 3×33 \times 3.

The number of columns in matrix BB (which is 2) is not equal to the number of rows in matrix AA (which is 3).

Therefore, the multiplication BABA 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 ABBAAB \neq BA. We have already seen an example above where ABAB is defined but BABA is not. Even if both are defined, the results are not necessarily the same.

  2. Associative:

    If the matrix multiplications A,B,A, B, and CC are defined, then (AB)C=A(BC)(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:

    A(B+C)=AB+ACA(B + C) = AB + AC
    (A+B)C=AC+BC(A + B)C = AC + BC

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

  4. Multiplication by Identity Matrix (II):

    If AA is a square matrix of order n×nn \times n and II is the identity matrix of order n×nn \times n, then:

    AI=IA=AAI = IA = A

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

  5. Multiplication by a Scalar (kk):

    If kk is a scalar (real number), then:

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

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 PP. The columns in matrix PP respectively represent Place A, Place B, and Place C, while the rows respectively represent tempeh chips, banana chips, and potato chips.

P=[151220251015151520]Tempeh ChipsBanana ChipsPotato ChipsP = \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 ([151220]\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.

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

Q=[20,00015,00030,000]Price of Tempeh ChipsPrice of Banana ChipsPrice of Potato ChipsQ = \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 PP by matrix QQ.

However, pay attention to the order of the matrices. Matrix PP has an order of 3×33 \times 3 and matrix QQ has an order of 3×13 \times 1. The number of columns in PP (3) is equal to the number of rows in QQ (3), so PQPQ can be calculated and will result in a matrix RR of order 3×13 \times 1.

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

R=PQ=[151220251015151520][20,00015,00030,000]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}
R=[(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)]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}
R=[300,000+180,000+600,000500,000+150,000+450,000300,000+225,000+600,000]R = \begin{bmatrix} 300,000 + 180,000 + 600,000 \\ 500,000 + 150,000 + 450,000 \\ 300,000 + 225,000 + 600,000 \end{bmatrix}
R=[1,080,0001,100,0001,125,000]Total Revenue from Tempeh ChipsTotal Revenue from Banana ChipsTotal Revenue from Potato ChipsR = \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 RR, we can see that the total revenue from the sale of tempeh chips is Rp1,080,000, banana chips Rp1,100,000, and potato chips Rp1,125,000.

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

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 QT=[20,00015,00030,000]Q^T = \begin{bmatrix} 20,000 & 15,000 & 30,000 \end{bmatrix} and multiply it by matrix PP: S=QTPS = Q^T P.

Matrix QTQ^T has an order of 1×31 \times 3 and PP has an order of 3×33 \times 3. The result SS will have an order of 1×31 \times 3.

S=[20,00015,00030,000][151220251015151520]S = \begin{bmatrix} 20,000 & 15,000 & 30,000 \end{bmatrix} \begin{bmatrix} 15 & 12 & 20 \\ 25 & 10 & 15 \\ 15 & 15 & 20 \end{bmatrix}
s11=(20,000)(15)+(15,000)(25)+(30,000)(15)=300,000+375,000+450,000=1,125,000s_{11} = (20,000)(15) + (15,000)(25) + (30,000)(15) = 300,000 + 375,000 + 450,000 = 1,125,000
s12=(20,000)(12)+(15,000)(10)+(30,000)(15)=240,000+150,000+450,000=840,000s_{12} = (20,000)(12) + (15,000)(10) + (30,000)(15) = 240,000 + 150,000 + 450,000 = 840,000
s13=(20,000)(20)+(15,000)(15)+(30,000)(20)=400,000+225,000+600,000=1,225,000s_{13} = (20,000)(20) + (15,000)(15) + (30,000)(20) = 400,000 + 225,000 + 600,000 = 1,225,000

Thus, S=[1,125,000840,0001,225,000]S = \begin{bmatrix} 1,125,000 & 840,000 & 1,225,000 \end{bmatrix}.

This means the total revenue from Place A is Rp1,125,000, from Place B is Rp840,000, and from Place C is Rp1,225,000.

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:

C=[1312]C = \begin{bmatrix} 1 & -3 \\ 1 & 2 \end{bmatrix}
D=[1482]D = \begin{bmatrix} 1 & -4 \\ 8 & 2 \end{bmatrix}

Determine the matrices CDCD and DCDC.

Is CD=DCCD = DC?

Answer Key

  1. Calculating CDCD:

    Matrix CC has an order of 2×22 \times 2 and DD has an order of 2×22 \times 2. The result will have an order of 2×22 \times 2.

    CD=[1312][1482]CD = \begin{bmatrix} 1 & -3 \\ 1 & 2 \end{bmatrix} \begin{bmatrix} 1 & -4 \\ 8 & 2 \end{bmatrix}
    CD=[(1)(1)+(3)(8)(1)(4)+(3)(2)(1)(1)+(2)(8)(1)(4)+(2)(2)]CD = \begin{bmatrix} (1)(1) + (-3)(8) & (1)(-4) + (-3)(2) \\ (1)(1) + (2)(8) & (1)(-4) + (2)(2) \end{bmatrix}
    CD=[124461+164+4]CD = \begin{bmatrix} 1 - 24 & -4 - 6 \\ 1 + 16 & -4 + 4 \end{bmatrix}
    CD=[2310170]CD = \begin{bmatrix} -23 & -10 \\ 17 & 0 \end{bmatrix}
  2. Calculating DCDC:

    Matrix DD has an order of 2×22 \times 2 and CC has an order of 2×22 \times 2. The result will have an order of 2×22 \times 2.

    DC=[1482][1312]DC = \begin{bmatrix} 1 & -4 \\ 8 & 2 \end{bmatrix} \begin{bmatrix} 1 & -3 \\ 1 & 2 \end{bmatrix}
    DC=[(1)(1)+(4)(1)(1)(3)+(4)(2)(8)(1)+(2)(1)(8)(3)+(2)(2)]DC = \begin{bmatrix} (1)(1) + (-4)(1) & (1)(-3) + (-4)(2) \\ (8)(1) + (2)(1) & (8)(-3) + (2)(2) \end{bmatrix}
    DC=[14388+224+4]DC = \begin{bmatrix} 1 - 4 & -3 - 8 \\ 8 + 2 & -24 + 4 \end{bmatrix}
    DC=[3111020]DC = \begin{bmatrix} -3 & -11 \\ 10 & -20 \end{bmatrix}

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

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