Multiplying matrices and vectors - Math Insight (2024)

Matrix-vector product

To define multiplication between a matrix $A$ and a vector $\vc{x}$(i.e., the matrix-vector product), we need to view the vectoras a column matrix.We define the matrix-vector product only for the case when the number ofcolumns in $A$ equals the number of rows in $\vc{x}$. So, if $A$ isan $m \times n$ matrix (i.e., with $n$ columns), then the product $A\vc{x}$ is defined for $n \times 1$ column vectors $\vc{x}$. If welet $A \vc{x} = \vc{b}$, then $\vc{b}$ is an $m \times 1$ columnvector. In other words, the number of rows in $A$ (which can beanything) determines the number of rows in the product $\vc{b}$.

The general formula for a matrix-vector product is\begin{align*} A\vc{x}= \left[ \begin{array}{cccc} a_{11} & a_{12} & \ldots & a_{1n}\\ a_{21} & a_{22} & \ldots & a_{2n}\\ \vdots & \vdots & \ddots & \vdots\\ a_{m1} & a_{m2} & \ldots & a_{mn} \end{array} \right] \left[ \begin{array}{c} x_1\\ x_2\\ \vdots\\ 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\\ \vdots\\ a_{m1}x_1+a_{m2}x_2 + \cdots + a_{mn} x_n\\ \end{array} \right].\end{align*}Although it may look confusing at first, the process of matrix-vectormultiplication is actually quite simple. One takes the dot product of$\vc{x}$ with each of the rows of $A$. (This is why the number ofcolumns in $A$ has to equal the number of components in $\vc{x}$.) Thefirst component of the matrix-vector product is the dot product of$\vc{x}$ with the first row of $A$, etc. In fact, if $A$ has only onerow, the matrix-vector product is really a dot product in disguise.

For example, if\begin{align*} A = \left[ \begin{array}{rrr} 1 & -1 & 2\\ 0 & -3 & 1 \end{array} \right]\end{align*}and $\vc{x} = (2,1,0)$, then\begin{align*} A \vc{x} &= \left[ \begin{array}{rrr} 1 & -1 & 2\\ 0 & -3 & 1 \end{array} \right] \left[ \begin{array}{l} 2\\1\\0 \end{array} \right]\\ &= \left[ \begin{array}{r} 2 \cdot 1 - 1\cdot 1 + 0 \cdot 2\\ 2 \cdot 0 - 1 \cdot 3 +0 \cdot 1 \end{array} \right] \\ &= \left[ \begin{array}{r} 1\\ -3 \end{array} \right].\end{align*}

Matrix-matrix product

Since we view vectors as column matrices, the matrix-vector product issimply a special case of the matrix-matrix product (i.e., a productbetween two matrices). Just like for the matrix-vector product, theproduct $AB$ between matrices $A$ and $B$ is defined only if thenumber of columns in $A$ equals the number of rowsin $B$. In math terms, we say we can multiply an $m \times n$ matrix$A$ by an $n \times p$ matrix $B$. (If $p$ happened to be 1, then $B$would be an $n\times 1$ column vector and we'd be back to thematrix-vector product.)

The product $AB$ is an $m \times p$ matrix which we'll call $C$, i.e.,$AB=C$. To calculate the product $B$, we view $B$ as a bunch of $n\times 1$ column vectors lined up next to each other:\begin{align*} \left[ \begin{array}{cccc} b_{11} & b_{12} & \ldots & b_{1p}\\ b_{21} & b_{22} & \ldots & b_{2p}\\ \vdots & \vdots & \vdots & \vdots\\ b_{n1} & b_{n2} & \ldots & b_{np} \end{array} \right] = \left[ \left[ \begin{array}{c} b_{11}\\ b_{21}\\ \vdots\\ b_{n1}\\ \end{array} \right] \left[ \begin{array}{c} b_{12}\\ b_{22}\\ \vdots\\ b_{n2}\\ \end{array} \right] \cdots \left[ \begin{array}{c} b_{1p}\\ b_{2p}\\ \vdots\\ b_{np}\\ \end{array} \right] \right]\end{align*}Then each column of $C$ is the matrix-vector product of $A$ withthe respective column of $B$. In other words, the component in the $i$throw and $j$th column of $C$ is the dot product between the $i$th rowof $A$ and the $j$th column of $B$. In math, we write this componentof $C$ as $c_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \cdots +a_{in}b_{nj}$.

An example help makes the process clear. Let $A$ be the $2 \times 3$matrix\begin{align*} A=\left[ \begin{array}{rrr} 0 & 4 & -2\\ -4 & -3 & 0 \end{array} \right] \end{align*}and $B$ be the $3 \times 2$ matrix\begin{align*} B= \left[ \begin{array}{rr} 0 &1\\ 1 & -1\\ 2 & 3 \end{array} \right].\end{align*}Then, \begin{align*} AB &=\left[ \begin{array}{rrr} 0 & 4 & -2\\ -4 & -3 & 0 \end{array} \right] \left[ \begin{array}{rr} 0 &1\\ 1 & -1\\ 2 & 3 \end{array} \right] \\ &= \left[ \begin{array}{rrr} 0 \cdot 0+4 \cdot 1-2\cdot 2 && 0 \cdot 1 +4 \cdot (-1) -2\cdot 3\\ -4 \cdot 0-3\cdot 1 + 0 \cdot 2 && -4 \cdot 1 -3 \cdot (-1) + 0\cdot 3 \end{array} \right] \\ &= \left[ \begin{array}{rrr} 0+4-4 && 0 -4 -6\\ 0-3+0 && -4 +3 +0 \end{array} \right] \\ &= \left[ \begin{array}{rr} 0 & -10\\ -3 & -1 \end{array} \right]. \end{align*}

Want more examples?

Multiplying matrices and vectors - Math Insight (2024)
Top Articles
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 6542

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.