• 0. Introduction
  • 1. Weighted means
  • 2. Geometry of weighted sums
  • 3. Matrix as a function
  • 4. Rank and reversibility
  • 5. Barycentric coordinates
  • 6. Matrix-matrix multiplication
  • 7. Linear transformations
  • 8. Polynomials are vectors in disguise
  • 9. Bezier curves
  • 10. Dot product
  • 11. Matrix transpose
  • 12. Rotations
  • 13. Normal vectors
  • 14. Eigenvectors and eigenvalues
  • 15. Eigendecomposition
  • 16. Eigenvectors of symmetric matrices
  • 17. Powers of a matrix
  • 18. Fibonacci numbers
  • 19. Markov matrices
  • 20. Projection matrix
  • 21. Symmetric matrix-vector product
  • 22. Positive symmetric definite matrices
  • 23. SVD
  • 24. Dimension reduction
  • 25. What next
unitgridOpacitycanvasColororiginXoriginY

21. Symmetric matrix-vector product

  • 21.1 Yet another point of view of matrix-matrix product
    • 21.1.1 The proof
  • 21.2 Revisiting the eigendecomposition of a symmetric matrix
  • 21.3 Matrix-vector product in terms of projections
  • 21.4 A visualization of this phenomenon
Review

The projection matrix chapter showed that for any unit vector uuu, the matrix uuTuu^TuuT projects vectors onto the 1-dimensional subspace of uuu. This chapter combines that fact with the eigendecomposition of symmetric matrices to give a beautiful picture of what a symmetric matrix does to a vector.

Recall that an nnn-by-nnn symmetric matrix has nnn real eigenvalues and the corresponding eigenvectors are all perpendicular to each other. This observation provides an elegant insight into what happens when a symmetric matrix is multiplied with a vector.

Also recall the eigendecomposition of a matrix M=VDV−1M = VDV^{-1}M=VDV−1 where VVV is the matrix of unit eigenvectors of MMM and DDD is a diagonal matrix where each diagonal element is an eigenvalue of MMM. If MMM is symmetric, we have V−1=VTV^{-1} = V^TV−1=VT which gives us M=VDVTM = VDV^TM=VDVT.

Finally, recall that for any unit vector uuu, the matrix uuTuu^TuuT is the projection matrix corresponding to the subspace described by uuu. In other words, for any vector vvv, the projection of vvv on the subspace given by uuu is (uuT)v(uu^T)v(uuT)v.

Armed with this knowledge, we rewrite the symmetric matrix MMM in a way that illuminates the relationship between projections and matrix-vector product.


21.1 Yet another point of view of matrix-matrix product

Here we will prove that:

[∣∣∣u1u2⋯un∣∣∣][—v1T——v2T—⋮—vnT—]=u1v1T⏟rank-1 term+u2v2T⏟rank-1 term+⋯+unvnT\begin{bmatrix} \vert & \vert & & \vert \\ \textcolor{#1d4ed8}{u_1} & \textcolor{#be185d}{u_2} & \cdots & u_n \\ \vert & \vert & & \vert \end{bmatrix} \begin{bmatrix} \text{—} & \textcolor{#1d4ed8}{v_1^T} & \text{—} \\ \text{—} & \textcolor{#be185d}{v_2^T} & \text{—} \\ & \vdots & \\ \text{—} & v_n^T & \text{—} \end{bmatrix} = \underbrace{\textcolor{#1d4ed8}{u_1v_1^T}}_{\text{rank-1 term}} + \underbrace{\textcolor{#be185d}{u_2v_2^T}}_{\text{rank-1 term}} + \cdots + u_nv_n^T​∣u1​∣​∣u2​∣​⋯​∣un​∣​​​———​v1T​v2T​⋮vnT​​———​​=rank-1 termu1​v1T​​​+rank-1 termu2​v2T​​​+⋯+un​vnT​

But before we prove it, let's understand the problem clearly:

  • The vectors ui,viu_i, v_iui​,vi​ are all column vectors. Thus viTv_i^TviT​ is a row vector.
  • This makes the product uiviTu_iv_i^Tui​viT​ an nnn-by-nnn matrix.
  • Thus the right hand side is a sum of nnn matrices.

Now let's prove it.


21.1.1 The proof

We will prove it only for two dimensions to avoid messy sums. But the line of reasoning applies to vectors of any dimension.

Let's assume:

U=[∣∣u1u2∣∣],V=[∣∣v1v2∣∣]=[v1xv2xv1yv2y]U = \begin{bmatrix} \vert & \vert \\ \textcolor{#1d4ed8}{u_1} & \textcolor{#be185d}{u_2} \\ \vert & \vert \end{bmatrix}, \quad V = \begin{bmatrix} \vert & \vert \\ \textcolor{#1d4ed8}{v_1} & \textcolor{#be185d}{v_2} \\ \vert & \vert \end{bmatrix} = \begin{bmatrix} \textcolor{#1d4ed8}{v_{1x}} & \textcolor{#be185d}{v_{2x}} \\ \textcolor{#1d4ed8}{v_{1y}} & \textcolor{#be185d}{v_{2y}} \end{bmatrix}U=​∣u1​∣​∣u2​∣​​,V=​∣v1​∣​∣v2​∣​​=[v1x​v1y​​v2x​v2y​​]

Then we have:

u1v1T+u2v2T=[∣u1∣][v1xv1y]+[∣u2∣][v2xv2y]=[∣∣v1xu1v1yu1∣∣]+[∣∣v2xu2v2yu2∣∣]=[∣∣v1xu1+v2xu2v1yu1+v2yu2∣∣]=[∣∣U⋅(first column of VT)U⋅(second column of VT)∣∣]=UVT\begin{aligned} u_1v_1^T + u_2v_2^T &= \begin{bmatrix} \vert \\ \textcolor{#1d4ed8}{u_1} \\ \vert \end{bmatrix} \begin{bmatrix} \textcolor{#1d4ed8}{v_{1x}} & \textcolor{#1d4ed8}{v_{1y}} \end{bmatrix} + \begin{bmatrix} \vert \\ \textcolor{#be185d}{u_2} \\ \vert \end{bmatrix} \begin{bmatrix} \textcolor{#be185d}{v_{2x}} & \textcolor{#be185d}{v_{2y}} \end{bmatrix} \\ &= \begin{bmatrix} \vert & \vert \\ \textcolor{#1d4ed8}{v_{1x}}u_1 & \textcolor{#1d4ed8}{v_{1y}}u_1 \\ \vert & \vert \end{bmatrix} + \begin{bmatrix} \vert & \vert \\ \textcolor{#be185d}{v_{2x}}u_2 & \textcolor{#be185d}{v_{2y}}u_2 \\ \vert & \vert \end{bmatrix} \\ &= \begin{bmatrix} \vert & \vert \\ \textcolor{#1d4ed8}{v_{1x}}u_1 + \textcolor{#be185d}{v_{2x}}u_2 & \textcolor{#1d4ed8}{v_{1y}}u_1 + \textcolor{#be185d}{v_{2y}}u_2 \\ \vert & \vert \end{bmatrix} \\ &= \begin{bmatrix} \vert & \vert \\ U \cdot (\text{first column of } V^T) & U \cdot (\text{second column of } V^T) \\ \vert & \vert \end{bmatrix} \\ &= UV^T \end{aligned}u1​v1T​+u2​v2T​​=​∣u1​∣​​[v1x​​v1y​​]+​∣u2​∣​​[v2x​​v2y​​]=​∣v1x​u1​∣​∣v1y​u1​∣​​+​∣v2x​u2​∣​∣v2y​u2​∣​​=​∣v1x​u1​+v2x​u2​∣​∣v1y​u1​+v2y​u2​∣​​=​∣U⋅(first column of VT)∣​∣U⋅(second column of VT)∣​​=UVT​

The proof for u1v1T+u2v2T+⋯+unvnTu_1v_1^T + u_2v_2^T + \cdots + u_nv_n^Tu1​v1T​+u2​v2T​+⋯+un​vnT​ follows the same line of reasoning. It just includes many more sums. Now let's apply this to the eigendecomposition of a symmetric matrix MMM.


21.2 Revisiting the eigendecomposition of a symmetric matrix

We have M=VDVTM = VDV^TM=VDVT where:

V=[∣∣∣v1v2⋯vn∣∣∣],D=[d1d2⋱dn]V = \begin{bmatrix} \vert & \vert & & \vert \\ v_1 & v_2 & \cdots & v_n \\ \vert & \vert & & \vert \end{bmatrix}, \quad D = \begin{bmatrix} d_1 & & & \\ & d_2 & & \\ & & \ddots & \\ & & & d_n \end{bmatrix}V=​∣v1​∣​∣v2​∣​⋯​∣vn​∣​​,D=​d1​​d2​​⋱​dn​​​

Note that the column vectors of VVV viz. v1,v2,…,vnv_1, v_2, \ldots, v_nv1​,v2​,…,vn​ are all unit vectors. Then we have:

M=[∣∣∣v1v2⋯vn∣∣∣][d1d2⋱dn][—v1T——v2T—⋮—vnT—]=[∣∣∣d1v1d2v2⋯dnvn∣∣∣][—v1T——v2T—⋮—vnT—]=d1(v1v1T)⏟rank-1 projection+d2(v2v2T)⏟rank-1 projection+⋯+dn(vnvnT)\begin{aligned} M &= \begin{bmatrix} \vert & \vert & & \vert \\ \textcolor{#1d4ed8}{v_1} & \textcolor{#be185d}{v_2} & \cdots & v_n \\ \vert & \vert & & \vert \end{bmatrix} \begin{bmatrix} \textcolor{#1d4ed8}{d_1} & & & \\ & \textcolor{#be185d}{d_2} & & \\ & & \ddots & \\ & & & d_n \end{bmatrix} \begin{bmatrix} \text{—} & \textcolor{#1d4ed8}{v_1^T} & \text{—} \\ \text{—} & \textcolor{#be185d}{v_2^T} & \text{—} \\ & \vdots & \\ \text{—} & v_n^T & \text{—} \end{bmatrix} \\ &= \begin{bmatrix} \vert & \vert & & \vert \\ \textcolor{#1d4ed8}{d_1v_1} & \textcolor{#be185d}{d_2v_2} & \cdots & d_nv_n \\ \vert & \vert & & \vert \end{bmatrix} \begin{bmatrix} \text{—} & \textcolor{#1d4ed8}{v_1^T} & \text{—} \\ \text{—} & \textcolor{#be185d}{v_2^T} & \text{—} \\ & \vdots & \\ \text{—} & v_n^T & \text{—} \end{bmatrix} \\ &= \underbrace{\textcolor{#1d4ed8}{d_1(v_1v_1^T)}}_{\text{rank-1 projection}} + \underbrace{\textcolor{#be185d}{d_2(v_2v_2^T)}}_{\text{rank-1 projection}} + \cdots + d_n(v_nv_n^T) \end{aligned}M​=​∣v1​∣​∣v2​∣​⋯​∣vn​∣​​​d1​​d2​​⋱​dn​​​​———​v1T​v2T​⋮vnT​​———​​=​∣d1​v1​∣​∣d2​v2​∣​⋯​∣dn​vn​∣​​​———​v1T​v2T​⋮vnT​​———​​=rank-1 projectiond1​(v1​v1T​)​​+rank-1 projectiond2​(v2​v2T​)​​+⋯+dn​(vn​vnT​)​

Now recall that vvTvv^TvvT is the projection matrix of the subspace of vvv. Thus we can rewrite the above expression as:

M=d1⋅(projection matrix of v1)+d2⋅(projection matrix of v2)+⋯+dn⋅(projection matrix of vn)\begin{aligned} M &= \textcolor{#1d4ed8}{d_1} \cdot (\text{projection matrix of } \textcolor{#1d4ed8}{v_1}) \\ &\quad + \textcolor{#be185d}{d_2} \cdot (\text{projection matrix of } \textcolor{#be185d}{v_2}) \\ &\quad + \cdots \\ &\quad + d_n \cdot (\text{projection matrix of } v_n) \end{aligned}M​=d1​⋅(projection matrix of v1​)+d2​⋅(projection matrix of v2​)+⋯+dn​⋅(projection matrix of vn​)​

21.3 Matrix-vector product in terms of projections

Given a vector xxx, we can write the matrix-vector product MxMxMx as:

Mx=d1⋅(projection matrix of v1)x⏟scaled projection+⋯+dn⋅(projection matrix of vn)x⏟scaled projection\begin{aligned} \textcolor{#e11d48}{Mx} &= \underbrace{d_1 \cdot \textcolor{#0d9488}{(\text{projection matrix of } v_1)}\textcolor{#e11d48}{x}}_{\text{scaled projection}} \\ &\quad + \cdots \\ &\quad + \underbrace{d_n \cdot \textcolor{#0d9488}{(\text{projection matrix of } v_n)}\textcolor{#e11d48}{x}}_{\text{scaled projection}} \end{aligned}Mx​=scaled projectiond1​⋅(projection matrix of v1​)x​​+⋯+scaled projectiondn​⋅(projection matrix of vn​)x​​​

In a less technical language, we can write it as:

Mx=(projection of x on v1) scaled by d1+⋯+(projection of x on vn) scaled by dn\begin{aligned} \textcolor{#e11d48}{Mx} &= \textcolor{#0d9488}{(\text{projection of } x \text{ on } v_1)} \text{ scaled by } d_1 \\ &\quad + \cdots \\ &\quad + \textcolor{#0d9488}{(\text{projection of } x \text{ on } v_n)} \text{ scaled by } d_n \end{aligned}Mx​=(projection of x on v1​) scaled by d1​+⋯+(projection of x on vn​) scaled by dn​​

Thus, the product of a symmetric matrix MMM with a vector xxx is the sum of projections of xxx on the eigenvectors scaled by their respective eigenvalues.


21.4 A visualization of this phenomenon

We use the matrix M=[1−1−10.6]M = \begin{bmatrix} 1 & -1 \\ -1 & 0.6 \end{bmatrix}M=[1−1​−10.6​] as an example here. This matrix has eigenvalues λ1=−0.22\lambda_1 = -0.22λ1​=−0.22 and λ2=1.82\lambda_2 = 1.82λ2​=1.82, and the corresponding unit eigenvectors are given by the columns of the matrix V=[0.634−0.7730.7730.634]V = \begin{bmatrix} 0.634 & -0.773 \\ 0.773 & 0.634 \end{bmatrix}V=[0.6340.773​−0.7730.634​].

We can write this matrix as:

[1−1−10.6]=−0.22[0.4020.4900.4900.598]+1.82[0.598−0.490−0.4900.402]\begin{aligned} \begin{bmatrix} 1 & -1 \\ -1 & 0.6 \end{bmatrix} &= \textcolor{#1d4ed8}{-0.22 \begin{bmatrix} 0.402 & 0.490 \\ 0.490 & 0.598 \end{bmatrix}} \\ &\quad + \textcolor{#be185d}{1.82 \begin{bmatrix} 0.598 & -0.490 \\ -0.490 & 0.402 \end{bmatrix}} \end{aligned}[1−1​−10.6​]​=−0.22[0.4020.490​0.4900.598​]+1.82[0.598−0.490​−0.4900.402​]​

Let's see this decomposition act on a vector xxx on the canvas. First draw the two 1-dimensional subspaces spanned by the eigenvectors v1v_1v1​ and v2v_2v2​ as grey lines, perpendicular to each other since MMM is symmetric.

import math

pie.clear()
pie.scalar(75, out='unit')
GRAY, TEAL, GOLD, ROSE = '#71717a', '#0d9488', '#ca8a04', '#e11d48'
V1, V2 = (0.634, 0.773), (-0.773, 0.634)
LAM1, LAM2 = -0.22, 1.82
pie.line(pie.point(5 * V1[0], 5 * V1[1], out='pa1', hidden=True), pie.point(-5 * V1[0], -5 * V1[1], out='pb1', hidden=True), out='line1', stroke=GRAY)
pie.line(pie.point(5 * V2[0], 5 * V2[1], out='pa2', hidden=True), pie.point(-5 * V2[0], -5 * V2[1], out='pb2', hidden=True), out='line2', stroke=GRAY)
pie.text('v₁', 3.4, 4.3, 12, out='lblV1', stroke=GRAY)
pie.text('v₂', -4.3, 3.4, 12, out='lblV2', stroke=GRAY)

Then take an input vector xxx of length 333 shown in rose.

tdeg = pie.scalar(35, out='tdeg')
# x at angle tdeg (degrees), its projections on v₁ and v₂, those scaled by the eigenvalues, and Mx
def parts(tdeg, which, axis):
    x = (3 * math.cos(math.radians(tdeg)), 3 * math.sin(math.radians(tdeg)))
    d1, d2 = V1[0] * x[0] + V1[1] * x[1], V2[0] * x[0] + V2[1] * x[1]
    p1, p2 = (d1 * V1[0], d1 * V1[1]), (d2 * V2[0], d2 * V2[1])
    s1, s2 = (LAM1 * p1[0], LAM1 * p1[1]), (LAM2 * p2[0], LAM2 * p2[1])
    vec = {'x': x, 'p1': p1, 'p2': p2, 's1': s1, 's2': s2, 'mx': (s1[0] + s2[0], s1[1] + s2[1])}[which]
    return vec[0] if axis == 'x' else vec[1]

part = pie.lift(parts, pie.Scalar)
pie.la_vec2d(part(tdeg, 'x', 'x'), part(tdeg, 'x', 'y'), out='xvec', stroke=ROSE)
lbl_x = pie.text('x', 2.9, 1.9, 13, out='lblX', stroke=ROSE)

Now project xxx on the two subspaces: the projections (v1v1T)x(v_1v_1^T)x(v1​v1T​)x and (v2v2T)x(v_2v_2^T)x(v2​v2T​)x are shown in teal.

pie.la_vec2d(part(tdeg, 'p1', 'x'), part(tdeg, 'p1', 'y'), out='proj1', stroke=TEAL)
pie.la_vec2d(part(tdeg, 'p2', 'x'), part(tdeg, 'p2', 'y'), out='proj2', stroke=TEAL)
lbl_p1 = pie.text('(v₁v₁ᵀ)x', 1.3, 2.7, 12, out='lblP1', stroke=TEAL)
lbl_p2 = pie.text('(v₂v₂ᵀ)x', 1.15, -0.72, 12, out='lblP2', stroke=TEAL)

Next, scale each projection by its eigenvalue and add the results tip-to-tail: the scaled projections λ1(v1v1T)x\lambda_1(v_1v_1^T)xλ1​(v1​v1T​)x and λ2(v2v2T)x\lambda_2(v_2v_2^T)xλ2​(v2​v2T​)x in gold.

s1x, s1y = part(tdeg, 's1', 'x'), part(tdeg, 's1', 'y')
pie.la_vec2d(s1x, s1y, out='scaled1', stroke=GOLD)
pie.la_vec2d(part(tdeg, 's2', 'x'), part(tdeg, 's2', 'y'), s1x, s1y, out='scaled2', stroke=GOLD)
lbl_s1 = pie.text('λ₁(v₁v₁ᵀ)x', -1.2, -0.4, 12, out='lblS1', stroke=GOLD)
lbl_s2 = pie.text('λ₂(v₂v₂ᵀ)x', 0, -1.65, 12, out='lblS2', stroke=GOLD)

Their sum is the output vector MxMxMx, again in rose.

pie.la_vec2d(part(tdeg, 'mx', 'x'), part(tdeg, 'mx', 'y'), out='out', stroke=ROSE)
lbl_mx = pie.text('Mx', 1, -1.5, 13, out='lblMx', stroke=ROSE)

Note how the first projection barely shrinks and flips (since λ1=−0.22\lambda_1 = -0.22λ1​=−0.22) while the second one stretches (since λ2=1.82\lambda_2 = 1.82λ2​=1.82). The tip of xxx moves along a circle of radius 333, shown in grey, while the tip of MxMxMx stays on an ellipse, shown in grey too.

for label in [lbl_x, lbl_p1, lbl_p2, lbl_s1, lbl_s2, lbl_mx]:
    pie.hide(label)
porg = pie.point(0, 0, out='porg', hidden=True)
pie.circle(porg, 3, out='circ', stroke=GRAY)
pie.la_mat_to_ellipse([[3, -3], [-3, 1.8]], porg, out='ellipse', stroke=GRAY)

Now rotate the input vector xxx through a full turn and watch the projections, their scaled copies and the output MxMxMx all update together.

pie.translate_scalar_to(tdeg, 35 + 360, animate=True)

You can also rotate it back.

pie.translate_scalar_to(tdeg, 35, animate=True)
  • When xxx lies on one of the subspaces, its projection on the other subspace vanishes, and Mx=λixMx = \lambda_i xMx=λi​x: the input is an eigenvector.
  • Everywhere else, MxMxMx is a weighted mix of the two projections, weighted by the eigenvalues.

In the next chapter we will use this projection picture to understand a special family of symmetric matrices: positive semi-definite matrices.


← 20. Projection matrix · 22. PSD matrices →