# Multiplying a Vector by a Matrix

To multiply a row vector by a column vector, the row vector must have as many columns as the column vector has rows.

Let us define the multiplication between a matrix $\text{A}$ and a vector $\text{x}$ in which the number of columns in $\text{A}$ equals the number of rows in $\text{x}$ .

So, if $\text{A}$ is an $m×n$ matrix, then the product $\text{A}\text{x}$ is defined for $n×1$ column vectors $\text{x}$ . If we let $\text{A}\text{x}=\text{b}$ , then $\text{b}$ is an $m×1$ column vector. In other words, the number of rows in $\text{A}$ determines the number of rows in the product $\text{b}$ .

The general formula for a matrix-vector product is

$\text{A}\text{x}=\left[\begin{array}{cccc}{a}_{11}& {a}_{12}& \cdots & {a}_{1n}\\ {a}_{21}& {a}_{22}& \cdots & {a}_{2n}\\ ⋮& ⋮& ⋮& ⋮\\ {a}_{m1}& {a}_{m2}& \cdots & {a}_{mn}\end{array}\right]\left[\begin{array}{c}{x}_{1}\\ {x}_{2}\\ ⋮\\ {x}_{n}\end{array}\right]=\left[\begin{array}{c}{a}_{11}{x}_{1}+{a}_{12}{x}_{2}+\cdots +{a}_{1n}{x}_{n}\\ {a}_{21}{x}_{1}+{a}_{22}{x}_{2}+\cdots +{a}_{2n}{x}_{n}\\ ⋮\\ {a}_{m1}{x}_{1}+{a}_{m2}{x}_{2}+\cdots +{a}_{mn}{x}_{n}\end{array}\right]$

Example :

Find $\text{A}\text{y}$ where $\text{y}=\left[\begin{array}{c}2\\ 1\\ 3\end{array}\right]$ and $\text{A}=\left[\begin{array}{ccc}1& 2& 3\\ 4& 5& 6\\ 7& 8& 9\end{array}\right]$ .

By the definition, number of columns in $\text{A}$ equals the number of rows in $\text{y}$ .

$\text{A}\text{y}=\left[\begin{array}{ccc}1& 2& 3\\ 4& 5& 6\\ 7& 8& 9\end{array}\right]\left[\begin{array}{c}2\\ 1\\ 3\end{array}\right]$

First, multiply Row $1$ of the matrix by Column $1$ of the vector.

$\left[\begin{array}{ccc}1& 2& 3\end{array}\right]\left[\begin{array}{c}2\\ 1\\ 3\end{array}\right]=\left[1\cdot 2+2\cdot 1+3\cdot 3\right]=13$

Next, multiply Row $2$ of the matrix by Column $1$ of the vector.

$\left[\begin{array}{ccc}4& 5& 6\end{array}\right]\left[\begin{array}{c}2\\ 1\\ 3\end{array}\right]=\left[4\cdot 2+5\cdot 1+6\cdot 3\right]=31$

Finally multiply Row $3$ of the matrix by Column $1$ of the vector.

$\left[\begin{array}{ccc}7& 8& 9\end{array}\right]\left[\begin{array}{c}2\\ 1\\ 3\end{array}\right]=\left[7\cdot 2+8\cdot 1+9\cdot 3\right]=49$

Writing the matrix-vector product, we get:

$\text{A}\text{y}=\left[\begin{array}{c}13\\ 31\\ 49\end{array}\right]$