Matrices and Matrix Operations
June 23, 2024 | by Bloom Code Studio
Learning Objectives
In this section, you will:
- Find the sum and difference of two matrices.
- Find scalar multiples of a matrix.
- Find the product of two matrices.
Figure 1 (credit: βSD Dirk,β Flickr)
Two club soccer teams, the Wildcats and the Mud Cats, are hoping to obtain new equipment for an upcoming season. Table 1 shows the needs of both teams.
| Wildcats | Mud Cats | |
|---|---|---|
| Goals | 6 | 10 |
| Balls | 30 | 24 |
| Jerseys | 14 | 20 |
A goal costs $300; a ball costs $10; and a jersey costs $30. How can we find the total cost for the equipment needed for each team? In this section, we discover a method in which the data in the soccer equipment table can be displayed and used for calculating other information. Then, we will be able to calculate the cost of the equipment.
Finding the Sum and Difference of Two Matrices
To solve a problem like the one described for the soccer teams, we can use a matrix, which is a rectangular array of numbers. A row in a matrix is a set of numbers that are aligned horizontally. A column in a matrix is a set of numbers that are aligned vertically. Each number is an entry, sometimes called an element, of the matrix. Matrices (plural) are enclosed in [ ] or ( ), and are usually named with capital letters. For example, three matrices named A,B,π΄,π΅, and CπΆ are shown below.
A=[1324],B=β‘β£β’1072β58762β€β¦β₯,C=β‘β£β’β103321β€β¦β₯π΄=[1234],π΅=[1270β56782],πΆ=[β103321]
Describing Matrices
A matrix is often referred to by its size or dimensions: mΓnπΓπ indicating mπ rows and nπ columns. Matrix entries are defined first by row and then by column. For example, to locate the entry in matrix Aπ΄ identified as aij,πππ, we look for the entry in row i,π, column j.π. In matrix A, βπ΄, β shown below, the entry in row 2, column 3 is a23.π23.
A=β‘β£β’a11a21a31a12a22a32a13a23a33β€β¦β₯π΄=[π11π12π13π21π22π23π31π32π33]
A square matrix is a matrix with dimensions nΓn,πΓπ, meaning that it has the same number of rows as columns. The 3Γ33Γ3 matrix above is an example of a square matrix.
A row matrix is a matrix consisting of one row with dimensions 1Γn.1Γπ.
[a11a12a13][π11π12π13]
A column matrix is a matrix consisting of one column with dimensions mΓ1.πΓ1.
β‘β£β’a11a21a31β€β¦β₯[π11π21π31]
A matrix may be used to represent a system of equations. In these cases, the numbers represent the coefficients of the variables in the system. Matrices often make solving systems of equations easier because they are not encumbered with variables. We will investigate this idea further in the next section, but first we will look at basic matrix operations.
MATRICES
A matrix is a rectangular array of numbers that is usually named by a capital letter: A,B,C,π΄,π΅,πΆ, and so on. Each entry in a matrix is referred to as aij,πππ, such that iπ represents the row and jπ represents the column. Matrices are often referred to by their dimensions: mΓnπΓπ indicating mπ rows and nπ columns.
EXAMPLE 1
Finding the Dimensions of the Given Matrix and Locating Entries
Given matrix A:π΄:
- βWhat are the dimensions of matrixΒ A?π΄?
- βWhat are the entries atΒ a31π31Β andΒ a22?π22?A=β‘β£β’22314107β2β€β¦β₯π΄=[21024731β2]
Solution
- βThe dimensions areΒ 3Γ33Γ3Β because there are three rows and three columns.
- βEntryΒ a31π31Β is the number at row 3, column 1, which is 3. The entryΒ a22π22Β is the number at row 2, column 2, which is 4. Remember, the row comes first, then the column.
Adding and Subtracting Matrices
We use matrices to list data or to represent systems. Because the entries are numbers, we can perform operations on matrices. We add or subtract matrices by adding or subtracting corresponding entries.
In order to do this, the entries must correspond. Therefore, addition and subtraction of matrices is only possible when the matrices have the same dimensions. We can add or subtract a 3Γ33Γ3 matrix and another 3Γ33Γ3 matrix, but we cannot add or subtract a 2Γ32Γ3 matrix and a 3Γ33Γ3 matrix because some entries in one matrix will not have a corresponding entry in the other matrix.
ADDING AND SUBTRACTING MATRICES
Given matrices Aπ΄ and Bπ΅ of like dimensions, addition and subtraction of Aπ΄ and Bπ΅ will produce matrix CπΆ or
matrix Dπ· of the same dimension.
A+B=Csuch that aij+bij=cijπ΄+π΅=πΆsuch that πππ+πππ=πππ
AβB=Dsuch that aijβbij=dijπ΄βπ΅=π·such that πππβπππ=πππ
Matrix addition is commutative.
A+B=B+Aπ΄+π΅=π΅+π΄
It is also associative.
(A+B)+C=A+(B+C)(π΄+π΅)+πΆ=π΄+(π΅+πΆ)
EXAMPLE 2
Finding the Sum of Matrices
Find the sum of Aπ΄ and B,π΅, given
A=[acbd] and B=[egfh]π΄=[ππππ] and π΅=[πππβ]
Solution
Add corresponding entries.
A+B=[acbd]+[egfh] =[a+ec+gb+fd+h]π΄+π΅=[ππππ]+[πππβ] =[π+ππ+ππ+ππ+β]
EXAMPLE 3
Adding Matrix A and Matrix B
Find the sum of Aπ΄ and B.π΅.
A=[4312] and B=[5097]π΄=[4132] and π΅=[5907]
Solution
Add corresponding entries. Add the entry in row 1, column 1, a11,π11, of matrix Aπ΄ to the entry in row 1, column 1, b11,π11, of B.π΅. Continue the pattern until all entries have been added.
A+B=[4312]+[5097] =[4+53+01+92+7] =[93109]π΄+π΅=[4132]+[5907] =[4+51+93+02+7] =[91039]
EXAMPLE 4
Finding the Difference of Two Matrices
Find the difference of Aπ΄ and B.π΅.
A=[β2031] and B=[8514]π΄=[β2301] and π΅=[8154]
Solution
We subtract the corresponding entries of each matrix.
AβB=[β2031]β[8514] =[β2β80β53β11β4] =[β10β52β3]π΄βπ΅=[β2301]β[8154] =[β2β83β10β51β4] =[β102β5β3]
EXAMPLE 5
Finding the Sum and Difference of Two 3 x 3 Matrices
Given Aπ΄ and B:π΅:
- βFind the sum.
- βFind the difference.
A=β‘β£β’2144β1012β2β2102β€β¦β₯and B=β‘β£β’60β510β122β2β4β2β€β¦β₯π΄=[2β10β21412104β22]and π΅=[610β20β12β4β52β2]
Solution
- βAdd the corresponding entries.A+B=β‘β£β’2144β1012β2β2102β€β¦β₯+β‘β£β’60β510β122β2β4β2β€β¦β₯=β‘β£β’2+614+04β5β10+1012β12β2+2β2β210β42β2β€β¦β₯=β‘β£β’814β1000β460β€β¦β₯π΄+π΅=[2β10β21412104β22]+[610β20β12β4β52β2]=[2+6β10+10β2β214+012β1210β44β5β2+22β2]=[80β41406β100]
- βSubtract the corresponding entries.AβB=β‘β£β’2144β1012β2β2102β€β¦β₯ββ‘β£β’60β510β122β2β4β2β€β¦β₯=β‘β£β’2β614β04+5β10β1012+12β2β2β2+210+42+2β€β¦β₯=β‘β£β’β4149β2024β40144β€β¦β₯π΄βπ΅=[2β10β21412104β22]β[610β20β12β4β52β2]=[2β6β10β10β2+214β012+1210+44+5β2β22+2]=[β4β2001424149β44]
TRY IT #1
Add matrix Aπ΄ and matrix B.π΅.
A=β‘β£β’21160β3β€β¦β₯ and B=β‘β£β’31β4β253β€β¦β₯π΄=[26101β3] and π΅=[3β215β43]
Finding Scalar Multiples of a Matrix
Besides adding and subtracting whole matrices, there are many situations in which we need to multiply a matrix by a constant called a scalar. Recall that a scalar is a real number quantity that has magnitude, but not direction. For example, time, temperature, and distance are scalar quantities. The process of scalar multiplication involves multiplying each entry in a matrix by a scalar. A scalar multiple is any entry of a matrix that results from scalar multiplication.
Consider a real-world scenario in which a university needs to add to its inventory of computers, computer tables, and chairs in two of the campus labs due to increased enrollment. They estimate that 15% more equipment is needed in both labs. The schoolβs current inventory is displayed in Table 2.
| Lab A | Lab B | |
|---|---|---|
| Computers | 15 | 27 |
| Computer Tables | 16 | 34 |
| Chairs | 16 | 34 |
Converting the data to a matrix, we have
C2013=β‘β£β’151616273434β€β¦β₯πΆ2013=[151616273434]
To calculate how much computer equipment will be needed, we multiply all entries in matrix CπΆ by 0.15.
(0.15)C2013=β‘β£β’(0.15)15(0.15)16(0.15)16(0.15)27(0.15)34(0.15)34β€β¦β₯=β‘β£β’2.252.42.44.055.15.1β€β¦β₯(0.15)πΆ2013=[(0.15)15(0.15)16(0.15)16(0.15)27(0.15)34(0.15)34]=[2.252.42.44.055.15.1]
We must round up to the next integer, so the amount of new equipment needed is
β‘β£β’333566β€β¦β₯[333566]
Adding the two matrices as shown below, we see the new inventory amounts.
β‘β£β’151616273434β€β¦β₯+β‘β£β’333566β€β¦β₯=β‘β£β’181919324040β€β¦β₯[151616273434]+[333566]=[181919324040]
This means
C2014=β‘β£β’181919324040β€β¦β₯πΆ2014=[181919324040]
Thus, Lab A will have 18 computers, 19 computer tables, and 19 chairs; Lab B will have 32 computers, 40 computer tables, and 40 chairs.
SCALAR MULTIPLICATION
Scalar multiplication involves finding the product of a constant by each entry in the matrix. Given
A=[a11a21a12a22]π΄=[π11π12π21π22]
the scalar multiple cAππ΄ is
cA=c[a11a21a12a22] =[ca11ca21ca12ca22]ππ΄=π[π11π12π21π22] =[ππ11ππ12ππ21ππ22]
Scalar multiplication is distributive. For the matrices A,B,π΄,π΅, and CπΆ with scalars aπ and b,π,
a(A+B)=aA+aB(a+b)A=aA+bAπ(π΄+π΅)=ππ΄+ππ΅(π+π)π΄=ππ΄+ππ΄
EXAMPLE 6
Multiplying the Matrix by a Scalar
Multiply matrix Aπ΄ by the scalar 3.
A=[8514]π΄=[8154]
Solution
Multiply each entry in Aπ΄ by the scalar 3.
3A=3[8514]= [3β 83β 53β 13β 4]= [2415312]3π΄=3[8154]= [3β 83β 13β 53β 4]= [2431512]
TRY IT #2
Given matrix B,π΅, find β2Bβ2π΅ where
B=[4312]π΅=[4132]
EXAMPLE 7
Finding the Sum of Scalar Multiples
Find the sum 3A+2B.3π΄+2π΅.
A=β‘β£β’104β2β1302β6β€β¦β₯and B=β‘β£β’β1002β3112β4β€β¦β₯π΄=[1β200β1243β6]and π΅=[β1210β3201β4]
Solution
First, find 3A,3π΄, then 2B.2π΅.
3A=β‘β£β’3β 13β 03β 43(β2)3(β1)3β 33β 03β 23(β6)β€β¦β₯=β‘β£β’3012β6β3906β18β€β¦β₯3π΄=[3β 13(β2)3β 03β 03(β1)3β 23β 43β 33(β6)]=[3β600β36129β18]
2B=β‘β£β’2(β1)2β 02β 02β 22(β3)2β 12β 12β 22(β4)β€β¦β₯=β‘β£β’β2004β6224β8β€β¦β₯2π΅=[2(β1)2β 22β 12β 02(β3)2β 22β 02β 12(β4)]=[β2420β6402β8]
Now, add 3A+2B.3π΄+2π΅.
3A+2B=β‘β£β’3012β6β3906β18β€β¦β₯+β‘β£β’β2004β6224β8β€β¦β₯ =β‘β£β’3β20+012+0β6+4β3β69+20+26+4β18β8β€β¦β₯ =β‘β£β’1012β2β911210β26β€β¦β₯3π΄+2π΅=[3β600β36129β18]+[β2420β6402β8] =[3β2β6+40+20+0β3β66+412+09+2β18β8] =[1β220β9101211β26]
Finding the Product of Two Matrices
In addition to multiplying a matrix by a scalar, we can multiply two matrices. Finding the product of two matrices is only possible when the inner dimensions are the same, meaning that the number of columns of the first matrix is equal to the number of rows of the second matrix. If Aπ΄ is an mΓrπΓπ matrix and Bπ΅ is an rΓnπΓπ matrix, then the product matrix ABπ΄π΅ is an mΓnπΓπ matrix. For example, the product ABπ΄π΅ is possible because the number of columns in Aπ΄ is the same as the number of rows in B.π΅. If the inner dimensions do not match, the product is not defined.
We multiply entries of Aπ΄ with entries of Bπ΅ according to a specific pattern as outlined below. The process of matrix multiplication becomes clearer when working a problem with real numbers.
To obtain the entries in row iπ of AB,π΄π΅, we multiply the entries in row iπ of Aπ΄ by column jπ in Bπ΅ and add. For example, given matrices Aπ΄ and B,π΅, where the dimensions of Aπ΄ are 2Γ32Γ3 and the dimensions of Bπ΅ are 3Γ3,3Γ3, the product of ABπ΄π΅ will be a 2Γ32Γ3 matrix.
A=[a11a21a12a22a13a23]and B=β‘β£β’b11b21b31b12b22b32b13b23b33β€β¦β₯π΄=[π11π12π13π21π22π23]and π΅=[π11π12π13π21π22π23π31π32π33]
Multiply and add as follows to obtain the first entry of the product matrix AB.π΄π΅.
- To obtain the entry in row 1, column 1 ofΒ AB,π΄π΅,Β multiply the first row inΒ Aπ΄Β by the first column inΒ B,π΅,Β and add.[a11a12a13]β‘β£β’b11b21b31β€β¦β₯=a11β b11+a12β b21+a13β b31[π11π12π13][π11π21π31]=π11β π11+π12β π21+π13β π31
- To obtain the entry in row 1, column 2 ofΒ AB,π΄π΅,Β multiply the first row ofΒ Aπ΄Β by the second column inΒ B,π΅,Β and add.[a11a12a13]β‘β£β’b12b22b32β€β¦β₯=a11β b12+a12β b22+a13β b32[π11π12π13][π12π22π32]=π11β π12+π12β π22+π13β π32
- To obtain the entry in row 1, column 3 ofΒ AB,π΄π΅,Β multiply the first row ofΒ Aπ΄Β by the third column inΒ B,π΅,Β and add.[a11a12a13]β‘β£β’b13b23b33β€β¦β₯=a11β b13+a12β b23+a13β b33[π11π12π13][π13π23π33]=π11β π13+π12β π23+π13β π33
We proceed the same way to obtain the second row of AB.π΄π΅. In other words, row 2 of Aπ΄ times column 1 of B;π΅; row 2 of Aπ΄ times column 2 of B;π΅; row 2 of Aπ΄ times column 3 of B.π΅. When complete, the product matrix will be
AB=β‘β£β’a11β b11+a12β b21+a13β b31a21β b11+a22β b21+a23β b31a11β b12+a12β b22+a13β b32a21β b12+a22β b22+a23β b32a11β b13+a12β b23+a13β b33a21β b13+a22β b23+a23β b33β€β¦β₯π΄π΅=[π11β π11+π12β π21+π13β π31π21β π11+π22β π21+π23β π31π11β π12+π12β π22+π13β π32π21β π12+π22β π22+π23β π32π11β π13+π12β π23+π13β π33π21β π13+π22β π23+π23β π33]
PROPERTIES OF MATRIX MULTIPLICATION
For the matrices A,B,π΄,π΅, and CπΆ the following properties hold.
- Matrix multiplication is associative:Β (AB)C=A(BC).(π΄π΅)πΆ=π΄(π΅πΆ).
- Matrix multiplication is distributive:Β C(A+B)=CA+CB,(A+B)C=AC+BC.πΆ(π΄+π΅)=πΆπ΄+πΆπ΅,(π΄+π΅)πΆ=π΄πΆ+π΅πΆ.
Note that matrix multiplication is not commutative.
EXAMPLE 8
Multiplying Two Matrices
Multiply matrix Aπ΄ and matrix B.π΅.
A=[1324] and B=[5768]π΄=[1234] and π΅=[5678]
Solution
First, we check the dimensions of the matrices. Matrix Aπ΄ has dimensions 2Γ22Γ2 and matrix Bπ΅ has dimensions 2Γ2.2Γ2. The inner dimensions are the same so we can perform the multiplication. The product will have the dimensions 2Γ2.2Γ2.
We perform the operations outlined previously.
EXAMPLE 9
Multiplying Two Matrices
Given Aπ΄ and B:π΅:
- βΒ FindΒ AB.π΄π΅.
- βΒ FindΒ BA.π΅π΄.
A=[β123405]and B=β‘β£β’5β42β103β€β¦β₯π΄=[β123405]and π΅=[5β42β103]
Solution
- βAs the dimensions ofΒ Aπ΄Β areΒ 2Γ32Γ3Β and the dimensions ofΒ Bπ΅Β areΒ 3Γ2,3Γ2,Β these matrices can be multiplied together because the number of columns inΒ Aπ΄Β matches the number of rows inΒ B.π΅.Β The resulting product will be aΒ 2Γ22Γ2Β matrix, the number of rows inΒ Aπ΄Β by the number of columns inΒ B.π΅.AB=[β142035]Β Β β‘β£β’5β42β103β€β¦β₯=[β1(5)+2(β4)+3(2)4(5)+0(β4)+5(2)β1(β1)+2(0)+3(3)4(β1)+0(0)+5(3)]=[β7301011]π΄π΅=[β123405]Β Β [5β1β4023]=[β1(5)+2(β4)+3(2)β1(β1)+2(0)+3(3)4(5)+0(β4)+5(2)4(β1)+0(0)+5(3)]=[β7103011]
- βThe dimensions ofΒ Bπ΅Β areΒ 3Γ23Γ2Β and the dimensions ofΒ Aπ΄Β areΒ 2Γ3.2Γ3.Β The inner dimensions match so the product is defined and will be aΒ 3Γ33Γ3Β matrix.BA=β‘β£β’5β42β103β€β¦β₯Β Β [β142035]=β‘β£β’5(β1)+β1(4)β4(β1)+0(4)2(β1)+3(4)5(2)+β1(0)β4(2)+0(0)2(2)+3(0)5(3)+β1(5)β4(3)+0(5)2(3)+3(5)β€β¦β₯=β‘β£β’β941010β8410β1221β€β¦β₯π΅π΄=[5β1β4023]Β Β [β123405]=[5(β1)+β1(4)5(2)+β1(0)5(3)+β1(5)β4(β1)+0(4)β4(2)+0(0)β4(3)+0(5)2(β1)+3(4)2(2)+3(0)2(3)+3(5)]=[β910104β8β1210421]
Analysis
Notice that the products ABπ΄π΅ and BAπ΅π΄ are not equal.
AB=[β7301011]β β‘β£β’β941010β8410β1221β€β¦β₯=BAπ΄π΅=[β7103011]β [β910104β8β1210421]=π΅π΄
This illustrates the fact that matrix multiplication is not commutative.
Q&A
Is it possible for AB to be defined but not BA?
Yes, consider a matrix A with dimensionΒ 3Γ43Γ4Β and matrix B with dimensionΒ 4Γ2.4Γ2.Β For the product AB the inner dimensions are 4 and the product is defined, but for the product BA the inner dimensions are 2 and 3 so the product is undefined.
EXAMPLE 10
Using Matrices in Real-World Problems
Letβs return to the problem presented at the opening of this section. We haveΒ Table 3, representing the equipment needs of two soccer teams.
| Wildcats | Mud Cats | |
|---|---|---|
| Goals | 6 | 10 |
| Balls | 30 | 24 |
| Jerseys | 14 | 20 |
We are also given the prices of the equipment, as shown inΒ Table 4.
| Goal | $300 |
| Ball | $10 |
| Jersey | $30 |
We will convert the data to matrices. Thus, the equipment need matrix is written as
E=β‘β£β’63014102420β€β¦β₯πΈ=[63014102420]
The cost matrix is written as
C=[3001030]πΆ=[3001030]
We perform matrix multiplication to obtain costs for the equipment.
CE=[3001030]β‘β£β’63014102420β€β¦β₯=[300(6)+10(30)+30(14)300(10)+10(24)+30(20)]=[2,5203,840]πΆπΈ=[3001030][61030241420]=[300(6)+10(30)+30(14)300(10)+10(24)+30(20)]=[2,5203,840]
The total cost for equipment for the Wildcats is $2,520, and the total cost for equipment for the Mud Cats is $3,840.
HOW TO
Given a matrix operation, evaluate using a calculator.
- Save each matrix as a matrix variableΒ [A],[B],[C],…[π΄],[π΅],[πΆ],…
- Enter the operation into the calculator, calling up each matrix variable as needed.
- If the operation is defined, the calculator will present the solution matrix; if the operation is undefined, it will display an error message.
EXAMPLE 11
Using a Calculator to Perform Matrix Operations
Find ABβCπ΄π΅βπΆ given
A=β‘β£β’β15411025β73432β28β2β€β¦β₯,B=β‘β£β’45β2462152β48β3719β31β€β¦β₯,and C=β‘β£β’β10025β67β89β5642β9874β75β€β¦β₯.π΄=[β15253241β7β281034β2],π΅=[4521β37β2452196β48β31],and πΆ=[β100β89β9825β5674β6742β75].
Solution
On the matrix page of the calculator, we enter matrix Aπ΄ above as the matrix variable [A],[π΄], matrix Bπ΅ above as the matrix variable [B],[π΅], and matrix CπΆ above as the matrix variable [C].[πΆ].
On the home screen of the calculator, we type in the problem and call up each matrix variable as needed.
[A][B]β[C][π΄][π΅]β[πΆ]
The calculator gives us the following matrix.
β‘β£β’β9831,820β311β4621,8972,032136β856413β€β¦β₯[β983β4621361,8201,897β856β3112,032413]
RELATED POSTS
View all