Difference between revisions of "Matrix multiplication"

From MathTank
Jump to navigation Jump to search
m
m
 
(10 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
We start with a simple example showing a practical use of multiplying a matrix by numbers (scalars). Below is an example of a distance matrix between three cities, in kilometers:
 
We start with a simple example showing a practical use of multiplying a matrix by numbers (scalars). Below is an example of a distance matrix between three cities, in kilometers:
 +
 
[[File:Distance matrix.png|alt=Distance matrix|thumb|Distance matrix]]
 
[[File:Distance matrix.png|alt=Distance matrix|thumb|Distance matrix]]
  
Line 11: Line 12:
  
 
We can multiply this matrix by <math> 0.62 </math> to (approximately) convert it to distances in miles:
 
We can multiply this matrix by <math> 0.62 </math> to (approximately) convert it to distances in miles:
 +
  
 
<math> B =0.62\cdot A \begin{bmatrix}
 
<math> B =0.62\cdot A \begin{bmatrix}
Line 23: Line 25:
  
 
Next, we present two examples that can be used to introduce matrix multiplication.
 
Next, we present two examples that can be used to introduce matrix multiplication.
 +
  
 
'''Cost comparison'''
 
'''Cost comparison'''
Line 49: Line 52:
 
{\color{red} 2}\cdot {\color{blue} 2}  + {\color{red} 3}\cdot {\color{blue} 5} & {\color{red} 2}\cdot {\color{blue} 3} + {\color{red} 3}\cdot {\color{blue} 1}  
 
{\color{red} 2}\cdot {\color{blue} 2}  + {\color{red} 3}\cdot {\color{blue} 5} & {\color{red} 2}\cdot {\color{blue} 3} + {\color{red} 3}\cdot {\color{blue} 1}  
 
\end{bmatrix} </math>  
 
\end{bmatrix} </math>  
 +
 +
Therefore, Alice should make the purchase at the second store, and Bob at the first store.
  
  
 
'''System of linear equations'''
 
'''System of linear equations'''
 +
 +
One of the fundamental ideas in mathematics is that of change of variables (substitution), which in particular is extensively used in solving equations and systems of equations. In particular, we can use linear substitution in a system of linear equations as follows.
 +
 +
Consider a system of linear equations
 +
 +
<math>
 +
\begin{cases}
 +
a_{11} x_1 + a_{12}x_2= c_1 \\
 +
a_{21} x_1 + a_{22}x_2= c_2
 +
\end{cases}
 +
</math>
 +
 +
The matrix of the system is <math> A = \begin{bmatrix}
 +
a_{11} & a_{12} \\
 +
a_{21} & a_{22}
 +
\end{bmatrix}</math>
 +
 +
Let <math> B = \begin{bmatrix}
 +
b_{11} & b_{12} \\
 +
b_{21} & b_{22}
 +
\end{bmatrix}</math>
 +
be the matrix of coefficients.
 +
Use it to make substitution as follows:
 +
 +
<math>
 +
\begin{cases}
 +
x_1 = b_{11} y_1 + b_{12}y_2\\
 +
x_2 = b_{21} y_1 + b_{22}y_2
 +
\end{cases}
 +
</math>
 +
 +
The resulting system is
 +
 +
<math>
 +
\begin{cases}
 +
a_{11} (b_{11} y_1 + b_{12}y_2) + a_{12}(b_{21} y_1 + b_{22}y_2)= c_1 \\
 +
a_{21} (b_{11} y_1 + b_{12}y_2) + a_{22}(b_{21} y_1 + b_{22}y_2)= c_2
 +
\end{cases},
 +
</math>
 +
 +
or, in terms of <math> y_1\text{ and } y_2 </math>:
 +
 +
<math>
 +
\begin{cases}
 +
(a_{11}b_{11} +a_{12}b_{21} ) y_1 + (a_{11}b_{12}+a_{12}b_{22} )y_2 = c_1 \\
 +
(a_{21}b_{11} +a_{22} b_{21})y_1 + (a_{21}b_{12}+a_{22}b_{22})y_2= c_2
 +
\end{cases},
 +
</math>
 +
 +
The matrix of the last system is
 +
 +
<math>
 +
\begin{bmatrix}
 +
a_{11}b_{11} +a_{12}b_{21}  & a_{11}b_{12}+a_{12}b_{22}  \\
 +
a_{21}b_{11} +a_{22} b_{21} & a_{21}b_{12}+a_{22}b_{22}
 +
\end{bmatrix},
 +
</math>
 +
 +
which is the product of matrices <math> A </math> and <math> B </math>.

Latest revision as of 23:55, 27 November 2021

While matrix addition usually does not present motivational challenges (addition is defined in a straight-forward component-wise way), to introduce matrix multiplication it is desirable to explain why we do not use component-wise approach. Of course, the "most appropriate" way to explain the formula for matrix multiplication is via composition of linear transformation. However, matrices (and matrix operations) are usually introduced before the linear transformations, and, additionally, linear transformation require a higher level of abstraction. Below we present several alternative approaches.

We start with a simple example showing a practical use of multiplying a matrix by numbers (scalars). Below is an example of a distance matrix between three cities, in kilometers:

Distance matrix
Distance matrix

[math]\displaystyle{ A =\begin{bmatrix} 0 & 340 & 360 \\ 340 & 0 & 450 \\ 360 & 450 & 360 \end{bmatrix} }[/math]

We can multiply this matrix by [math]\displaystyle{ 0.62 }[/math] to (approximately) convert it to distances in miles:


[math]\displaystyle{ B =0.62\cdot A \begin{bmatrix} 0.62 \cdot 0 & 0.62\cdot 340 & 0.62 \cdot 360 \\ 0.62 \cdot 340 & 0.62\cdot 0 & 0.62\cdot 450 \\ 0.62 \cdot 360 & 0.62\cdot 450 & 0.62\cdot 360 \end{bmatrix} = \begin{bmatrix} 0 & 210.8 & 223.2 \\ 210.8 & 0 & 279 \\ 223.2 & 279 & 0 \end{bmatrix} }[/math]

Next, we present two examples that can be used to introduce matrix multiplication.


Cost comparison

Cost matrix
Price matrix

Alice and Bob need to buy some apples and pears. Alice needs 2 kg of apples and 5 kg of pears. Bob needs 3 kg of apples and 1 kg of pears. The first store in town offers apples for $1/kg and pears for $4/kg. The second store offers apples for $2/kg and pears for $3/kg. Assuming they will go only to one store each, which stores should Alice and Bob make their purchases at?

We can represent the information given above using two matrices: price matrix P and weight matrix W (see pictures on the right).

Weight matrix
Weight matrix

[math]\displaystyle{ P =\begin{bmatrix} 1 & 4 \\ 2 & 3 \end{bmatrix}\text{ and } W =\begin{bmatrix} 2 & 3 \\ 5 & 1 \end{bmatrix} }[/math]

If, for example, Alice buys fruits at the second store, her cost will be [math]\displaystyle{ {\color{red} 2}\cdot {\color{blue} 2} + {\color{red} 3}\cdot {\color{blue} 5} }[/math] , which is the dot product of the second row of [math]\displaystyle{ P }[/math] and first column of [math]\displaystyle{ W }[/math]. Repeating the same for all four person - store combinations, we get the cost matrix [math]\displaystyle{ C }[/math] as follows:

[math]\displaystyle{ C =\begin{bmatrix} {\color{red} 1} \cdot {\color{blue} 2} + {\color{red} 4} \cdot {\color{blue} 5} & {\color{red} 1}\cdot {\color{blue} 3} + {\color{red} 4}\cdot {\color{blue} 1} \\ {\color{red} 2}\cdot {\color{blue} 2} + {\color{red} 3}\cdot {\color{blue} 5} & {\color{red} 2}\cdot {\color{blue} 3} + {\color{red} 3}\cdot {\color{blue} 1} \end{bmatrix} }[/math]

Therefore, Alice should make the purchase at the second store, and Bob at the first store.


System of linear equations

One of the fundamental ideas in mathematics is that of change of variables (substitution), which in particular is extensively used in solving equations and systems of equations. In particular, we can use linear substitution in a system of linear equations as follows.

Consider a system of linear equations

[math]\displaystyle{ \begin{cases} a_{11} x_1 + a_{12}x_2= c_1 \\ a_{21} x_1 + a_{22}x_2= c_2 \end{cases} }[/math]

The matrix of the system is [math]\displaystyle{ A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix} }[/math]

Let [math]\displaystyle{ B = \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix} }[/math] be the matrix of coefficients. Use it to make substitution as follows:

[math]\displaystyle{ \begin{cases} x_1 = b_{11} y_1 + b_{12}y_2\\ x_2 = b_{21} y_1 + b_{22}y_2 \end{cases} }[/math]

The resulting system is

[math]\displaystyle{ \begin{cases} a_{11} (b_{11} y_1 + b_{12}y_2) + a_{12}(b_{21} y_1 + b_{22}y_2)= c_1 \\ a_{21} (b_{11} y_1 + b_{12}y_2) + a_{22}(b_{21} y_1 + b_{22}y_2)= c_2 \end{cases}, }[/math]

or, in terms of [math]\displaystyle{ y_1\text{ and } y_2 }[/math]:

[math]\displaystyle{ \begin{cases} (a_{11}b_{11} +a_{12}b_{21} ) y_1 + (a_{11}b_{12}+a_{12}b_{22} )y_2 = c_1 \\ (a_{21}b_{11} +a_{22} b_{21})y_1 + (a_{21}b_{12}+a_{22}b_{22})y_2= c_2 \end{cases}, }[/math]

The matrix of the last system is

[math]\displaystyle{ \begin{bmatrix} a_{11}b_{11} +a_{12}b_{21} & a_{11}b_{12}+a_{12}b_{22} \\ a_{21}b_{11} +a_{22} b_{21} & a_{21}b_{12}+a_{22}b_{22} \end{bmatrix}, }[/math]

which is the product of matrices [math]\displaystyle{ A }[/math] and [math]\displaystyle{ B }[/math].