Product of matrices and vectors
Part of Math Camp: An Introduction to Mathematics and Statistics with Applications in Economics.
Main Stam4Econ site | View this section in the book | Author: Fan Wang | DOI: 10.5281/zenodo.24696926
Date: 2026-11-30 | HTML | PDF | QMD
1 Product of matrices and vectors
1.1 The product of two vectors (dot product)
The product of two vectors \(a\) and \(b\), also known as the dot product, is defined as:
\[ a \cdot b = \sum_{i=1}^{n} a_i b_i \]
where \(a_i\) and \(b_i\) are the components of vectors \(a\) and \(b\), respectively, and \(n\) is the number of components in each vector. The dot product results in a scalar value.
Generally, we just use the symbol \(\cdot\) for any scalar multiplication. And when we have a vector \(a\) that is a n by 1 column vector, and a vector \(b\) that is another n by 1 column vector, we can write the dot product as:
\[ a \cdot b = a^T b = \sum_{i=1}^{n} a_i b_i \]
where \(a^T\) is the transpose of vector \(a\), which is a 1 by n row vector. The product \(a^T b\) is then a 1 by 1 matrix, which is equivalent to a scalar. Writing this out in matrix form, we have:
\[\begin{align} a^T b &= \begin{bmatrix} a_1 & a_2 & \cdots & a_n \end{bmatrix} \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_n \end{bmatrix}\\ &= a_1 b_1 + a_2 b_2 + \cdots + a_n b_n\\ &= \sum_{i=1}^{n} a_i b_i \end{align}\]
1.2 The product of a matrix and a vector
The product of a matrix \(A\) that is m by n and a vector \(b\) that is n by 1 is defined as:
\[ Ab = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix} \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_n \end{bmatrix} = \begin{bmatrix} \sum_{j=1}^{n} a_{1j} b_j \\ \sum_{j=1}^{n} a_{2j} b_j \\ \vdots \\ \sum_{j=1}^{n} a_{mj} b_j \end{bmatrix} \]
The result is a m by 1 column vector. The notation \(Ab\) might look confusing, especially confusing if English words are used for matrix names, and \(Ab\) might look like a single word, so be careful about your notations. We often like to use bold to represent column vectors and perhaps capitalized letters (and bold) to represent matrices, and small cap not bold for scalar values. For example, we can write the above as:
\[ \mathbf{A} \mathbf{b} = \mathbf{c} \]
1.3 The product of two matrices
Let A be a m by n matrix, and B be a n by p matrix, then the product of A and B is defined as:
\[\begin{align} C = AB =& \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix} \begin{bmatrix} b_{11} & b_{12} & \cdots & b_{1p} \\ b_{21} & b_{22} & \cdots & b_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ b_{n1} & b_{n2} & \cdots & b_{np} \end{bmatrix}\\ =& \begin{bmatrix} \sum_{j=1}^{n} a_{1j} b_{j1} & \sum_{j=1}^{n} a_{1j} b_{j2} & \cdots & \sum_{j=1}^{n} a_{1j} b_{jp} \\ \sum_{j=1}^{n} a_{2j} b_{j1} & \sum_{j=1}^{n} a_{2j} b_{j2} & \cdots & \sum_{j=1}^{n} a_{2j} b_{jp} \\ \vdots & \vdots & \ddots & \vdots \\ \sum_{j=1}^{n} a_{mj} b_{j1} & \sum_{j=1}^{n} a_{mj} b_{j2} & \cdots & \sum_{j=1}^{n} a_{mj} b_{jp} \end{bmatrix} \end{align}\]
The value in row i and column k of the resulting matrix C is the dot product of row i of matrix A and column k of matrix B:
\[ c_{ik} = \sum_{j=1}^{n} a_{ij} b_{jk} \]
By using matrix notation, rather than having to work out m by p dot products, we can just write the product of two matrices as AB, which is much more compact and easier to read.
Matrixes algebra is a time saving device that allows us to focus on the big picture, and not get mired in the details of individual dot product calculations.
1.4 Matrixes and investment portfolio
This matrix way of representing information is widely applicable in many settings. For example, the m by p matrix C, which is the product of m by n matrix A and n by p matrix B, can be viewed as a return matrix, across states-of-the-world for different investment portfolios. In this case, Matrix A represent contingent-returns for \(n\) assets (e.g., stocks, bonds, etc) across states of the world \(m\), with each value in matrix \(A\) recording the return of asset \(j\) in state of the world \(i\). Each column of matrix \(B\) represents a portfolio. Different columns are different investment strategies.
Each column of matrix C then represents the returns to each portfolio, across states of the world (rows). We can solve for specific vectors in matrix \(B\) that achieves specific vectors of returns. Including a portfolio that hedges risks and returns the same in all states of the world, or a vector that provides insurance and provides only positive return in one state of the world and nothing in other states.
Suppose there are two states of the world, sunny and rain, and two assets, Ray-ban and doordash. The return matrix \(A\) is given as follows:
\[ A = \begin{bmatrix} 1.5 \, (\text{Ray-ban sunny}) & 0.5 \, (\text{doordash sunny}) \\ 0.5 \, (\text{Ray-ban rain}) & 1.2 \, (\text{doordash rain}) \end{bmatrix} \]
where the first row represents the returns of the two assets when it is sunny, and the second row represents the returns of the two assets when it is rainy. The first column represents the returns of Ray-ban, and the second column represents the returns of doordash. Now, suppose we have three investment strategies: (1) invest 50% in Ray-ban and 50% in doordash; (2) invest 20% in Ray-ban and 80% in doordash; (3) invest about 41.18 percent in Ray-ban, and the rest in doordash. The portfolio matrix \(B\) is given as follows:
\[ B = \begin{bmatrix} 0.5 & 0.2 & 0.4118 \\ 0.5 & 0.8 & 0.5882 \end{bmatrix} \]
The return matrix \(C\) is given as follows:
\[ C = AB = \begin{bmatrix} 1.0 & 0.70 & 0.9118 \\ 0.85 & 1.06 & 0.9118 \end{bmatrix} \]
where the first column represents the returns of the first investment strategy across the two states of the world, and so forth. Which strategy is better? Depends on investor’s preferences and the investor needs to insure against, different portofolios can return more in sunny state, more in rainy state, or the same in both states.
An investment firm has three roles: (1) discover the \(A\) matrix with research analysts, with each analyst specializing across subsets of rows (state of the world contingencies) or columns (companies assets); (2) design column vectors in matrix \(B\) that achieve alternative cross-states return objectives with portfolio managers; and (3) pair investors with portfolios that match with their financial needs with financial advisors.
1.5 Generalized solution to the portfolio problem
We now set up the portfolio problem from the prior section formally, without assigning numerical values to returns. Consider two assets and two states of the world. The return matrix is:
\[ A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix}, \]
where row \(i\) gives the returns in state \(i\), and column \(j\) gives the returns of asset \(j\). Thus, \(a_{11}\) is the return of asset 1 in state 1, \(a_{12}\) is the return of asset 2 in state 1, and so forth.
Let \(w_1\) and \(w_2\) denote the fractions of wealth invested in assets 1 and 2. We consider fully invested portfolios, so:
\[ w_1 + w_2 = 1. \]
The portfolio-weight vector is:
\[ w = \begin{bmatrix}w_1 \\ w_2\end{bmatrix}. \]
Matrix multiplication gives the portfolio return in each state:
\[ Aw = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix} \begin{bmatrix}w_1 \\ w_2\end{bmatrix} = \begin{bmatrix} a_{11}w_1 + a_{12}w_2 \\ a_{21}w_1 + a_{22}w_2 \end{bmatrix}. \]
The portfolio has zero risk, in the sense of having the same return in both states, if there is a scalar \(r\) such that:
\[ a_{11}w_1 + a_{12}w_2 = r, \qquad a_{21}w_1 + a_{22}w_2 = r. \]
Equating the two state returns and moving all terms to the left gives:
\[ (a_{11}-a_{21})w_1 + (a_{12}-a_{22})w_2 = 0. \]
Together with the full-investment condition, the two equations determining the weights are:
\[ \begin{aligned} (a_{11}-a_{21})w_1 + (a_{12}-a_{22})w_2 &= 0, \\ w_1+w_2 &= 1. \end{aligned} \]
Use \(w_2=1-w_1\) in the first equation:
\[ (a_{11}-a_{21})w_1 + (a_{12}-a_{22})(1-w_1)=0. \]
Collect the terms involving \(w_1\):
\[ \left(a_{11}-a_{21}-a_{12}+a_{22}\right)w_1 = a_{22}-a_{12}. \]
Define the denominator:
\[ D = a_{11}+a_{22}-a_{12}-a_{21}. \]
When \(D\ne0\), the unique zero-risk portfolio is:
\[ w_1^* = \frac{a_{22}-a_{12}}{D}, \qquad w_2^* = 1-w_1^* = \frac{a_{11}-a_{21}}{D}. \]
Equivalently,
\[ w^* = \frac{1}{D} \begin{bmatrix} a_{22}-a_{12} \\ a_{11}-a_{21} \end{bmatrix}. \]
We can derive the common return by substituting these weights into the return in state 1:
\[ \begin{aligned} r^* &= a_{11}w_1^* + a_{12}w_2^* \\ &= a_{11}\left(\frac{a_{22}-a_{12}}{D}\right) + a_{12}\left(\frac{a_{11}-a_{21}}{D}\right) \\ &= \frac{a_{11}a_{22}-a_{12}a_{21}}{D}. \end{aligned} \]
The same expression results from substituting the weights into the return in state 2. Therefore:
\[ Aw^* = r^*\begin{bmatrix}1 \\ 1\end{bmatrix}, \qquad r^* = \frac{\det(A)}{D}. \]
For the portfolio to be long-only, both weights must be nonnegative. A common sufficient condition is that asset 1 has a higher return in state 1 than in state 2 and asset 2 has a higher return in state 2 than in state 1:
\[ a_{11}>a_{21}, \]