4.2 Quadratic Forms uᵀCu: Measuring Directional Variance in Any Direction

Once we have built the covariance matrix C=1nXTXC = \frac{1}{n}X^T X, how do we find out how spread out the data cloud is along an arbitrary tilted direction u\mathbf{u}? The answer is one of the most important expressions in applied mathematics: the quadratic form uTCu\mathbf{u}^T C \mathbf{u}.

In this microlearning, we prove that uTCu\mathbf{u}^T C \mathbf{u} equals the exact empirical variance along unit vector u\mathbf{u}, expand it into a polynomial in the components of u\mathbf{u}, and visualize its level sets as variance ellipses.

In this Article

1. Proving σ²(u) = uᵀCu in Three Lines of Matrix Algebra

Let X∈Rn×dX \in \mathbb{R}^{n \times d} be our centered data matrix and u∈Rd\mathbf{u} \in \mathbb{R}^d be any unit direction vector (uTu=1\mathbf{u}^T\mathbf{u} = 1). Projecting each row xiT\mathbf{x}_i^T onto u\mathbf{u} produces the vector of nn scalar projections:

z=Xu=[x1Tu⋮xnTu]\mathbf{z} = X\mathbf{u} = \begin{bmatrix} \mathbf{x}_1^T \mathbf{u} \\ \vdots \\ \mathbf{x}_n^T \mathbf{u} \end{bmatrix}

Because XX is mean-centered, the average of z\mathbf{z} is zero. Its empirical variance σu2\sigma_{\mathbf{u}}^2 is the average squared entry of z\mathbf{z}:

σu2=1nzTz=1n(Xu)T(Xu)=uT(1nXTX)u=uTCu\sigma_{\mathbf{u}}^2 = \frac{1}{n} \mathbf{z}^T \mathbf{z} = \frac{1}{n} (X\mathbf{u})^T (X\mathbf{u}) = \mathbf{u}^T \left(\frac{1}{n} X^T X\right) \mathbf{u} = \mathbf{u}^T C \mathbf{u}

2. Expanding uᵀCu in 2D: How Cross-Terms Reward Alignment

In 2D, let u=[u1u2]=[cos⁡θsin⁡θ]\mathbf{u} = \begin{bmatrix} u_1 \\ u_2 \end{bmatrix} = \begin{bmatrix} \cos\theta \\ \sin\theta \end{bmatrix} and C=[c11c12c12c22]C = \begin{bmatrix} c_{11} & c_{12} \\ c_{12} & c_{22} \end{bmatrix}. Carrying out the multiplication uTCu\mathbf{u}^T C \mathbf{u} gives a degree-2 homogeneous polynomial (which is why it is called a quadratic form):

uTCu=c11u12+2c12u1u2+c22u22\mathbf{u}^T C \mathbf{u} = c_{11} u_1^2 + 2 c_{12} u_1 u_2 + c_{22} u_2^2

Look closely at the middle term 2c12u1u22 c_{12} u_1 u_2: when c12>0c_{12} > 0 (positive correlation between x1x_1 and x2x_2), choosing u1u_1 and u2u_2 with the same sign (pointing into Quadrant I or III) makes 2c12u1u22 c_{12} u_1 u_2 positive and boosts the variance above the axis variances!

3. Visualizing the Quadratic Bowl and Variance Contours

If we allow an arbitrary vector w∈R2\mathbf{w} \in \mathbb{R}^2 and plot f(w)=wTCwf(\mathbf{w}) = \mathbf{w}^T C \mathbf{w} as a height in 3D, it forms an upward-curving elliptic paraboloid (a bowl). Slicing this bowl horizontally at a constant height f(w)=k>0f(\mathbf{w}) = k > 0 produces concentric ellipses in the plane:

            w2 ^
               |          . - ~ ~ - .
               |      . '            / ' .   <-- Level curve w^T C w = constant
               |    /               /     \
         ------+---/---------------0-------+---> w1
               |  \               /       /
               |    ' .          /    . '
               |        ' - . _ . - '
                 Minor axis = Steepest wall of bowl (largest eigenvalue lambda_1)
                 Major axis = Gentlest valley of bowl (smallest eigenvalue lambda_2)

4. Worked Numerical Directional Sweep

Suppose C=[4224]C = \begin{bmatrix} 4 & 2 \\ 2 & 4 \end{bmatrix}. Then for any unit vector u=(cos⁡θ,sin⁡θ)T\mathbf{u} = (\cos\theta, \sin\theta)^T:

uTCu=4cos⁡2θ+4cos⁡θsin⁡θ+4sin⁡2θ=4+2sin⁡(2θ)\mathbf{u}^T C \mathbf{u} = 4\cos^2\theta + 4\cos\theta\sin\theta + 4\sin^2\theta = 4 + 2\sin(2\theta)

Angle θ\thetaUnit Vector u\mathbf{u}Directional Variance uTCu=4+2sin⁡(2θ)\mathbf{u}^T C \mathbf{u} = 4 + 2\sin(2\theta)
0∘0^\circ(1,0)T(1, 0)^T4+2(0)=4.04 + 2(0) = 4.0
45∘45^\circ(1/2,1/2)T(1/\sqrt{2}, 1/\sqrt{2})^T4+2(1)=6.04 + 2(1) = 6.0 (Global Maximum = λ1\lambda_1)
90∘90^\circ(0,1)T(0, 1)^T4+2(0)=4.04 + 2(0) = 4.0
135∘135^\circ(−1/2,1/2)T(-1/\sqrt{2}, 1/\sqrt{2})^T4+2(−1)=2.04 + 2(-1) = 2.0 (Global Minimum = λ2\lambda_2)

5. Active Recall Check and Key Takeaways

Quick Check: Test Your Understanding

Question: Given C=[5−3−35]C = \begin{bmatrix} 5 & -3 \\ -3 & 5 \end{bmatrix}, does a unit vector in Quadrant I (u1>0,u2>0u_1 > 0, u_2 > 0) or Quadrant II (u1<0,u2>0u_1 < 0, u_2 > 0) achieve larger projected variance?

Answer: Quadrant II! Because c12=−3<0c_{12} = -3 < 0, the cross term −6u1u2-6 u_1 u_2 becomes positive (+6 u_1 |u_2|) when u1u_1 and u2u_2 have opposite signs, yielding maximum variance 88 at u=(−1/2,1/2)T\mathbf{u} = (-1/\sqrt{2}, 1/\sqrt{2})^T.

  • Universal Variance Formula: σu2=uTCu\sigma_{\mathbf{u}}^2 = \mathbf{u}^T C \mathbf{u} for any unit vector u\mathbf{u}.
  • Cross-Term Geometry: Off-diagonal covariances reward directions aligned with the correlation sign of the cloud.
  • Canonical References: See Wikipedia Reference on Quadratic Forms in Statistics.

Take a Quiz Based on This Article

Test your understanding with AI-generated questions tailored to this content

Adaptive Learning with SynLearn

Explore this article through guided practice that adapts to your answers

✓Step-by-step concepts & lessons
✓Active recall & adaptive feedback
✓Personalized spaced repetition
quadratic-forms
directional-variance
covariance-matrix
rayleigh-quotient
pca
linear-algebra