Matrix-Vector Multiplication¶

1. What is Matrix-Vector Multiplication?¶

  • Matrix-vector multiplication involves multiplying a matrix (a 2-dimensional array of numbers) by a vector (a 1-dimensional array of numbers).
  • The result of this multiplication is another vector.
  • This operation is widely used in various fields such as computer graphics, machine learning, and physics.

2. Understanding the Dimensions¶

  • For matrix-vector multiplication, the number of columns in the matrix must equal the number of elements in the vector.
  • If the matrix has dimensions $m \times n$ (where $m$ is the number of rows and $n$ is the number of columns), the vector must have $n$ elements.
  • The resulting vector will have $m$ elements.

3. The Step-by-Step Process of Matrix-Vector Multiplication¶

Given:

  • A matrix $A$ of size $m \times n$: $$ A = \begin{bmatrix} a_{11} & a_{12} & \dots & a_{1n} \\ a_{21} & a_{22} & \dots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \dots & a_{mn} \end{bmatrix} $$
  • A vector $\mathbf{v}$ with $n$ elements: $$ \mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{bmatrix} $$

The result of multiplying matrix $A$ by vector $\mathbf{v}$ is a new vector $\mathbf{b}$ with $m$ elements: $$ \mathbf{b} = A \mathbf{v} = \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_m \end{bmatrix} $$

  • Each element $b_i$ of the resulting vector $\mathbf{b}$ is calculated as: $$ b_i = a_{i1} \times v_1 + a_{i2} \times v_2 + \dots + a_{in} \times v_n $$ This means each element of the resulting vector is the dot product of the corresponding row of the matrix with the vector.

4. Summary of the Process¶

  1. Take each row of the matrix.
  2. Multiply each element of the row by the corresponding element of the vector.
  3. Add up all these products to get a single number (this becomes an element of the resulting vector).
  4. Repeat for each row in the matrix.

4. Step-by-Step Examples¶

Let’s break down some examples to illustrate this process.

Key Points to Remember¶

  1. The number of columns in the matrix must equal the number of elements in the vector.
  2. The resulting vector has as many elements as there are rows in the matrix.
  3. Each element of the resulting vector is the dot product of a row in the matrix with the vector.

Example 1¶

Matrix and Vector:¶

$$ A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}, \quad \mathbf{v} = \begin{bmatrix} 5 \\ 6 \end{bmatrix} $$

Step-by-Step Multiplication:¶

  1. The matrix $A$ has 2 rows and 2 columns ($2 \times 2$ matrix).
  2. The vector $\mathbf{v}$ has 2 elements, so it can be multiplied by the matrix $A$.
  3. The resulting vector $\mathbf{b}$ will have 2 elements.

Calculate each element of $\mathbf{b}$:

  1. First element ($b_1$): $$ b_1 = (1 \times 5) + (2 \times 6) = 5 + 12 = 17 $$
  2. Second element ($b_2$): $$ b_2 = (3 \times 5) + (4 \times 6) = 15 + 24 = 39 $$

Result:¶

$$ \mathbf{b} = \begin{bmatrix} 17 \\ 39 \end{bmatrix} $$

Example 2¶

Matrix and Vector:¶

$$ A = \begin{bmatrix} 2 & 0 & -1 \\ 1 & 3 & 4 \end{bmatrix}, \quad \mathbf{v} = \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix} $$

Step-by-Step Multiplication:¶

  1. The matrix $A$ has 2 rows and 3 columns ($2 \times 3$ matrix).
  2. The vector $\mathbf{v}$ has 3 elements, so it can be multiplied by the matrix $A$.
  3. The resulting vector $\mathbf{b}$ will have 2 elements.

Calculate each element of $\mathbf{b}$:

  1. First element ($b_1$): $$ b_1 = (2 \times 1) + (0 \times 2) + (-1 \times 3) = 2 + 0 - 3 = -1 $$
  2. Second element ($b_2$): $$ b_2 = (1 \times 1) + (3 \times 2) + (4 \times 3) = 1 + 6 + 12 = 19 $$

Result:¶

$$ \mathbf{b} = \begin{bmatrix} -1 \\ 19 \end{bmatrix} $$

Example 3¶

Matrix and Vector:¶

$$ A = \begin{bmatrix} 0 & 1 & 2 \\ -1 & 3 & 1 \\ 4 & 0 & -2 \end{bmatrix}, \quad \mathbf{v} = \begin{bmatrix} 2 \\ 1 \\ 0 \end{bmatrix} $$

Step-by-Step Multiplication:¶

  1. The matrix $A$ has 3 rows and 3 columns ($3 \times 3$ matrix).
  2. The vector $\mathbf{v}$ has 3 elements, so it can be multiplied by the matrix $A$.
  3. The resulting vector $\mathbf{b}$ will have 3 elements.

Calculate each element of $\mathbf{b}$:

  1. First element ($b_1$): $$ b_1 = (0 \times 2) + (1 \times 1) + (2 \times 0) = 0 + 1 + 0 = 1 $$
  2. Second element ($b_2$): $$ b_2 = (-1 \times 2) + (3 \times 1) + (1 \times 0) = -2 + 3 + 0 = 1 $$
  3. Third element ($b_3$): $$ b_3 = (4 \times 2) + (0 \times 1) + (-2 \times 0) = 8 + 0 + 0 = 8 $$

Result:¶

$$ \mathbf{b} = \begin{bmatrix} 1 \\ 1 \\ 8 \end{bmatrix} $$

Matrix-Matrix Multiplication¶

1. What is Matrix-Matrix Multiplication?¶

  • Matrix-matrix multiplication involves multiplying two matrices together to produce a new matrix.
  • If you have two matrices $A$ and $B$, the product $C = A \times B$ results in a new matrix $C$.
  • This operation is fundamental in linear algebra, computer graphics, machine learning, and many other areas.

2. Conditions for Matrix-Matrix Multiplication¶

  • If matrix $A$ has dimensions $m \times n$ (with $m$ rows and $n$ columns) and matrix $B$ has dimensions $n \times p$ (with $n$ rows and $p$ columns), the number of columns in $A$ must equal the number of rows in $B$.
  • The resulting matrix $C$ will have dimensions $m \times p$.

3. The Step-by-Step Process of Matrix-Matrix Multiplication¶

Given:

  • Matrix $A$ of size $m \times n$: $$ A = \begin{bmatrix} a_{11} & a_{12} & \dots & a_{1n} \\ a_{21} & a_{22} & \dots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \dots & a_{mn} \end{bmatrix} $$
  • Matrix $B$ of size $n \times p$: $$ B = \begin{bmatrix} b_{11} & b_{12} & \dots & b_{1p} \\ b_{21} & b_{22} & \dots & b_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ b_{n1} & b_{n2} & \dots & b_{np} \end{bmatrix} $$

The resulting matrix $C = A \times B$ will have dimensions $m \times p$, where each element $c_{ij}$ is calculated as: $$ c_{ij} = a_{i1} \times b_{1j} + a_{i2} \times b_{2j} + \dots + a_{in} \times b_{nj} $$

  • In other words, each element of the resulting matrix $C$ is the dot product of the $i$-th row of matrix $A$ with the $j$-th column of matrix $B$.

Key Points to Remember¶

  1. The number of columns in the first matrix must equal the number of rows in the second matrix for multiplication to be possible.
  2. The resulting matrix will have the dimensions of the rows of the first matrix by the columns of the second matrix.
  3. Each element of the resulting matrix is the dot product of the corresponding row in the first matrix and the corresponding column in the second matrix.

4. Step-by-Step Examples¶

Let’s break down some examples to illustrate this process.

Example 1¶

Matrices:¶

$$ A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}, \quad B = \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} $$

Step-by-Step Multiplication:¶

  1. Matrix $A$ has dimensions $2 \times 2$ and matrix $B$ has dimensions $2 \times 2$. Since the number of columns in $A$ equals the number of rows in $B$, we can multiply them.
  2. The resulting matrix $C$ will have dimensions $2 \times 2$.

Calculate each element of $C$:

  1. First row, first column ($c_{11}$): $$ c_{11} = (1 \times 5) + (2 \times 7) = 5 + 14 = 19 $$
  2. First row, second column ($c_{12}$): $$ c_{12} = (1 \times 6) + (2 \times 8) = 6 + 16 = 22 $$
  3. Second row, first column ($c_{21}$): $$ c_{21} = (3 \times 5) + (4 \times 7) = 15 + 28 = 43 $$
  4. Second row, second column ($c_{22}$): $$ c_{22} = (3 \times 6) + (4 \times 8) = 18 + 32 = 50 $$

Result:¶

$$ C = \begin{bmatrix} 19 & 22 \\ 43 & 50 \end{bmatrix} $$

Example 2¶

Matrices:¶

$$ A = \begin{bmatrix} 2 & 0 & -1 \\ 1 & 3 & 4 \end{bmatrix}, \quad B = \begin{bmatrix} 1 & 2 \\ 0 & 1 \\ 4 & 0 \end{bmatrix} $$

Step-by-Step Multiplication:¶

  1. Matrix $A$ has dimensions $2 \times 3$ and matrix $B$ has dimensions $3 \times 2$. Since the number of columns in $A$ equals the number of rows in $B$, we can multiply them.
  2. The resulting matrix $C$ will have dimensions $2 \times 2$.

Calculate each element of $C$:

  1. First row, first column ($c_{11}$): $$ c_{11} = (2 \times 1) + (0 \times 0) + (-1 \times 4) = 2 + 0 - 4 = -2 $$
  2. First row, second column ($c_{12}$): $$ c_{12} = (2 \times 2) + (0 \times 1) + (-1 \times 0) = 4 + 0 + 0 = 4 $$
  3. Second row, first column ($c_{21}$): $$ c_{21} = (1 \times 1) + (3 \times 0) + (4 \times 4) = 1 + 0 + 16 = 17 $$
  4. Second row, second column ($c_{22}$): $$ c_{22} = (1 \times 2) + (3 \times 1) + (4 \times 0) = 2 + 3 + 0 = 5 $$

Result:¶

$$ C = \begin{bmatrix} -2 & 4 \\ 17 & 5 \end{bmatrix} $$

Example 3¶

Matrices:¶

$$ A = \begin{bmatrix} 3 & -1 & 2 \\ 0 & 4 & 1 \end{bmatrix}, \quad B = \begin{bmatrix} 1 & 2 \\ -2 & 0 \\ 3 & -1 \end{bmatrix} $$

Step-by-Step Multiplication:¶

  1. Matrix $A$ has dimensions $2 \times 3$ and matrix $B$ has dimensions $3 \times 2$. Since the number of columns in $A$ equals the number of rows in $B$, we can multiply them.
  2. The resulting matrix $C$ will have dimensions $2 \times 2$.

Calculate each element of $C$:

  1. First row, first column ($c_{11}$): $$ c_{11} = (3 \times 1) + (-1 \times -2) + (2 \times 3) = 3 + 2 + 6 = 11 $$
  2. First row, second column ($c_{12}$): $$ c_{12} = (3 \times 2) + (-1 \times 0) + (2 \times -1) = 6 + 0 - 2 = 4 $$
  3. Second row, first column ($c_{21}$): $$ c_{21} = (0 \times 1) + (4 \times -2) + (1 \times 3) = 0 - 8 + 3 = -5 $$
  4. Second row, second column ($c_{22}$): $$ c_{22} = (0 \times 2) + (4 \times 0) + (1 \times -1) = 0 + 0 - 1 = -1 $$

Result:¶

$$ C = \begin{bmatrix} 11 & 4 \\ -5 & -1 \end{bmatrix} $$