Operations with matrices 2023 - 1win aviator game

# Operations with matrices

To define the addition of two matrices $\mathbf{A}=[a_{ij}]$ and $\mathbf{B}=[b_{ij}]$, they must have equal dimensions. The result of addition of these two matrices is matrix $\mathbf{C}=[c_{ij}]$  which has the same dimensions and

$$a_{ij} + b_{ij} =c_{ij}, \forall i= 1, \ldots , m , \forall j = 1, \ldots , n$$

is valid.

$[a_{ij}] + [b_{ij}]$=

$\begin{bmatrix} a_{11} & a_{12} & a_{13} & \ldots & a_{1n} \\ a_{21} & a_{22} & a_{23} & \ldots & a_{2n} \\ a_{31} & a_{32} & a_{33} & \ldots & a_{3n} \\ \vdots & \vdots & \vdots & \ddots & \vdots\\ a_{m1} & a_{m2} & a_{m3} & \ldots & a_{mn} \end{bmatrix} + \begin{bmatrix} b_{11} & b_{12} & b_{13} & \ldots & b_{1n} \\ b_{21} & b_{22} & b_{23} & \ldots & b_{2n} \\ b_{31} & b_{32} & b_{33} & \ldots & b_{3n} \\ \vdots & \vdots & \vdots & \ddots & \vdots\\ b_{m1} & b_{m2} & b_{m3} & \ldots & b_{mn} \end{bmatrix}$

$=\begin{bmatrix} a_{11}+b_{11} & a_{12}+b_{12} & a_{13}+ b_{13} & \ldots & a_{12n}+ b_{1n} \\ a_{21} + b_{21} & a_{22} + b_{22} & a_{23} + b_{23} & \ldots & a_{2n}+ b_{2n} \\ a_{31}+b_{31} & a_{32}+ b_{32} & a_{33}+ b_{33} & \ldots & a_{3n}+ b_{3n} \\ \vdots & \vdots & \vdots & \ddots & \vdots\\ a_{m1}+b_{m1} & a_{m2}+b_{m2} & a_{m3}+b_{m3} & \ldots & a_{mn}+b_{mn} \end{bmatrix}=[c_{ij}].$

Example 1.

$$\mathbf{A} = \begin{bmatrix} 1 & 2 & -4 & 3 \\ -9 & 11 & 36 & -6 \\ 41 & -3 & 17 & 76 \end{bmatrix},$$

$$\mathbf{B} = \begin{bmatrix} 0 & -3 & 16 & -98 \\ 12 & -12 & -16 & 10 \\ -31 & 9 & 4 & -57 \end{bmatrix}.$$

Solution:

$$\mathbf{A} + \mathbf{B} =$$

\begin{bmatrix} 1 & 2 & -4 & 3 \\ -9 & 11 & 36 & -6 \\ 41 & -3 & 17 & 76 \end{bmatrix}+ \begin{bmatrix} 0 & -3 & 16 & -98 \\
12 & -12 & -16 & 10 \\ -31 & 9 & 4 & -57 \end{bmatrix}=

\begin{bmatrix} 1 + 0 & 2 +(-3)  & -4 +16 & 3 + (-98) \\ -9 +12 & 11 + (-12)  & 36 + (-16) & -6 +10 \\ 41 + (-31)  & -3 +9 & 17 +4 & 76 + (-57) \end{bmatrix} =

\begin{bmatrix} 1 & -1 & 12 & -95 \\ 3 & -1 & 20 & 4 \\ 10 & 6 & 21 & 19 \end{bmatrix}.

For every two matrices $\mathbf{A}=[a_{ij}], \mathbf{B} = [b_{ij}] \in \mathbb{R}^{m \times n}$  is valid:

$$\mathbf{A} + \mathbf{B} = \mathbf{B} + \mathbf{A},$$

that is, the addition of matrices is commutative.

For every three matrices $\mathbf{A}=[a_{ij}], \mathbf{B} = [b_{ij}], \mathbf{C} = [c_{ij}] \in \mathbb{R}^{m \times n}$  is valid:

$$(\mathbf{A} + \mathbf{B}) +\mathbf{C} = \mathbf{A} + (\mathbf{B} + \mathbf{C}),$$

that is, the addition of matrices is associative.

A zero matrix is a neutral element for addition of matrices.

Example 2.  Find the matrix $B$ such that $A + B = C$, where

$$\mathbf{A}=\begin{bmatrix}-2 & 0 \\ -1 & -5 \end{bmatrix}, \mathbf{C}=\begin{bmatrix}10 & 0 \\ -7 & 6 \end{bmatrix}$$

Solution:

If  $\mathbf{B}=\begin{bmatrix}b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix}$, then we have matrix equation

$A + B = C$, that is

$$\begin{bmatrix}-2 & 0 \\ -1 & -5 \end{bmatrix} + \begin{bmatrix}b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix} = \begin{bmatrix}10 & 0 \\ -7 & 6 \end{bmatrix}$$

$$\begin{bmatrix}-2 + b_{11} & 0 + b_{12} \\ -1 + b_{21} & -5 + b_{22}\end{bmatrix} = \begin{bmatrix}10 & 0 \\ -7 & 6 \end{bmatrix}.$$

We know that two matrices are equal if and only if their corresponding elements are equal, so we conclude:

$-2 + b_{11} = 10, 0 + b_{12} = 0, -1 + b_{21} = -7, -5 + b_{22} = 6$, that is, $b_{11}= 12, b_{12} = 0, b_{21} = -6, b_{22} = 11.$ Therefore,

$$\begin{bmatrix} 12 & 0 \\ -6 & 11 \end{bmatrix}.$$

If matrices $\mathbf{A}=[a_{ij}]$ and $\mathbf{B}=[b_{ij}]$ have equal dimensions, we can define matrix subtraction: Elements of matrix $A – B$ are elements that we get by subtracting elements of matrix $B$ from the corresponding elements of matrix $A$.

## Scalar multiplication

If $\alpha \in \mathbb{R}$ is a scalar and $\mathbf{A} \in \mathbb{R}^{m \times n}$ a matrix, then the multiplication a matrix $\mathbf{A}$ by a scalar $\alpha$ is defined as $\alpha \cdot \mathbf{A}$. This means that every element of a matrix $\mathbf{A}$ is multiplied by $\alpha$.

Example 3.

For the matrix $\mathbf{A} =\begin{bmatrix} 3 & -2 & 7 \\ -4 & 1 & 0 \\ 11 & -6 & 22 \end{bmatrix}$ calculate $3\cdot \mathbf{A}$ and $-2\cdot \mathbf{A}$.

Solution:

$$3 \cdot \mathbf{A} = 3 \cdot \begin{bmatrix} 3 & -2 & 7 \\ -4 & 1 & 0 \\ 11 & -6 & 22 \end{bmatrix} = \begin{bmatrix} 3 \cdot 3 & 3 \cdot (-2) & 3 \cdot 7 \\ 3 \cdot (-4) & 3 \cdot 1 & 3 \cdot 0 \\ 3 \cdot 11 & 3 \cdot (-6) & 3 \cdot 22 \end{bmatrix}= \begin{bmatrix} 9 & -6 & 21 \\ -12 & 3 & 0 \\ 33 & -18 & 66 \end{bmatrix}.$$

$$-2 \cdot \mathbf{A} = -2\cdot \begin{bmatrix} 3 & -2 & 7 \\ -4 & 1 & 0 \\ 11 & -6 & 22 \end{bmatrix}= \begin{bmatrix} -6 & 4 & -14 \\ 8 & -2 & 0 \\ -22 & 12 & -44 \end{bmatrix}.$$

If $\alpha = 0$ , then matrix $\mathbf{A}$ is equal to zero matrix.

If $\alpha = -1$ ,then $\mathbf{A} = \mathbf {-A}$.

$\mathbf {-A}$ is called  the opposite matrix of matrix $\mathbf{A}$.

## Multiplication of matrices

The product of two matrices is not defined for any two matrices, it is not even defined for two matrices of the same dimensions.

Firstly, consider the multiplication of row vector by column vector. Let the dimensions of vector $\mathbf{a}$ be $1 \times n$, and $n \times 1$ of vector $\mathbf{b}$. Then their product is:

$$\mathbf{a} \cdot \mathbf{b} = \begin{bmatrix} a_{1} & a_{2} & a_{3} & \ldots & a_{n} \end{bmatrix} \cdot \begin{bmatrix} b_{1} \\ b_{2} \\ b_{3} \\ \vdots \\ b_{n} \end{bmatrix} = a_{1}b_{1} +a_{2}b_{2} + a_{3}b_{3} + \ldots + a_{n}b_{n},$$

Their product is a scalar.

We will use previously on the example:

$$\begin{bmatrix} 2 & 4 & -1 & 3 \end{bmatrix} \cdot \begin{bmatrix} -1 \\ 6 \\ -2 \\ 0 \end{bmatrix} = 2 \cdot (-1) + 4\cdot 6 + (-1) \cdot (-2) + 3 \cdot 0 = -2 + 24 +2 +0 = 24.$$

Matrix $\mathbf{A}$  can be multiplied by matrix $\mathbf{B}$ if the number of rows of matrix $\mathbf{B}$ is equal to number of columns of matrix $\mathbf{A}$. The product $\mathbf{A} \mathbf{B}$  has the same number of rows as matrix $\mathbf{A}$ and the same number of columns as matrix $\mathbf{B}$.

The proper definition follows.

If $\mathbf{A} = [a_{ij}] \in \mathbb{R}^{m\times n}$ and $\mathbf{B} = [b_{ij}] \in \mathbb{R}^{n\times r}$ , then their product is defined as matrix $\mathbf{A} \mathbf{B} = [c_{ij}] \in \mathbb{R}^{m\times r}$, where $[c_{ij}] = a_{i1} b_{1j} +a_{i2} b_{2j} + a_{i3} b_{3j} + \ldots + a_{in} b_{nj}$.

This means that element $c_{ij}$ is the scalar product of elements that are located in $i$-th row of matrix $\mathbf{A}$ and in $j$-th column of matrix $\mathbf{B}$.

For example,

$c_{11} = a_{11}b_{11} + a_{12}b_{21} + a_{13}b_{31} + \ldots + a_{1n}b_{n1}$.

Example 4.

Multiply the following matrices:

$\mathbf{A}= \begin{bmatrix} 1 & -3 & -2 & -1 \\ 6 & 0 & 5 & 2 \\ -1 & 7 & 4 & 0 \end{bmatrix}$ and $\mathbf{B}= \begin{bmatrix} 2 & -1 \\ 0 & 3 \\ 7 & 1 \\ -1 & -8 \end{bmatrix}$.

Solution:

The dimensions of matrix $\mathbf{A}$ is $3 \times 4$ and of matrix $\mathbf{B}$ is $4 \times 2$. Therefore,  it is possible to multiply these two matrices.

$$\mathbf{A} \cdot \mathbf{B}=\begin{bmatrix} 1 & -3 & -2 & -1 \\ 6 & 0 & 5 & 2 \\ -1 & 7 & 4 & 0 \end{bmatrix} \cdot \begin{bmatrix} 2 & -1 \\ 0 & 3 \\ 7 & 1 \\ -1 & -8 \end{bmatrix} =$$

$$=\begin{bmatrix} 1\cdot 2 + (-3)\cdot 0 + (-2) \cdot 7 +(-1) \cdot (-1) & 1\cdot (-1) + (-3)\cdot 3 + (-2) \cdot 1 +(-1) \cdot (-8) \\ 6 \cdot 2 + 0 \cdot 0 + 5 \cdot 7 + 2 \cdot (-1) & 6 \cdot (-1) + 0 \cdot 3 + 5 \cdot 1 + 2 \cdot (-8) \\ -1 \cdot 2 + 7 \cdot 0 + 4 \cdot 7 + 0 \cdot (-1) & -1 \cdot (-1) + 7 \cdot 3 + 4 \cdot 1 + 0 \cdot (-8) \end{bmatrix} =$$

$$=\begin{bmatrix} 2 + 0 -14 +1 & -1 -9 -2 +8 \\ 12 + 0 +35 -2 & -6 + 0 +5 -16 \\ -2 + 0 +28 + 0 & 1 +21 +4 + 0 \end{bmatrix} =\begin{bmatrix} -11 & -4 \\ 45 & -17 \\ 26 & 26 \end{bmatrix}.$$

Multiplication of matrices is not commutative, as we can see from the previous example. The product $\mathbf{B} \mathbf{A}$ is not even defined, because matrix $\mathbf{B}$ has two columns and matrix $\mathbf{A}$ three rows.

The following properties are valid for the multiplication of matrices (if the specified products are well defined):

•  $\mathbf{A} (\mathbf{B} + \mathbf{C}) = \mathbf{A} \mathbf{B} + \mathbf{A} \mathbf{C}$  ( right distributivity)
• $(\mathbf{A} + \mathbf{B}) \mathbf{C} = \mathbf{A} \mathbf{C} + \mathbf{B} \mathbf{C}$  ( left distributivity)
• $(\alpha \mathbf{A}) \mathbf{B} = \mathbf{A} ( \alpha \mathbf{B}) = \alpha (\mathbf{A} \mathbf{B}) , \forall \alpha \in \mathbb{R}$  (quasi – associativity)
• $(\mathbf{A} \mathbf{B}) \mathbf{C} = \mathbf{A} (\mathbf{B} \mathbf{C})$ (associativity)
• $\mathbf{A} \mathbf{I} = \mathbf{A} , \mathbf{I} \mathbf{A} = \mathbf{A}$ (an identity matrix is a neutral element for multiplication)