Diagonalization changes coordinates so a square matrix becomes diagonal. For a matrix A with linearly independent eigenvectors, place those eigenvectors in S and its eigenvalues in diagonal Λ: A = SΛS⁻¹. For symmetric A, the eigenvectors are orthogonal, so A = SΛSᵀ and S represents a rotation. section 2.15
Diagonalization supports two useful interpretations:
- It separates a transformation into eigenvector directions, where scaling is represented by the diagonal entries of Λ. section 2.15
- It solves symmetric linear systems without explicitly forming a potentially unstable matrix inverse: transform with Sᵀ, divide by diagonal Λ, then transform with S. section 2.15.2
- It reveals the axes of a hyperellipse: the eigenvectors become the rotated coordinate axes, and the quadratic-form matrix becomes diagonal. section 2.17
A rotated ellipse
For 5x² + 6xy + 5y² = 20, use A = [[5, 3], [3, 5]]. Computing its eigenvectors gives an orthogonal rotation; the major axis forms a 45° angle with the x-axis. Rotating by that basis aligns the ellipse with the coordinate axes. section 2.17.1
Listing 2.21 Axes of a hyperellipse
ellipse_eq = sy.Eq(5*x**2 + 5*y**2 +
6*x*y, 20) ①
A = torch.tensor([[5, 3], [3, 5]]).float()
l, S = torch.linalg.eig(A)
x_axis_vec = torch.zeros((A.shape[0])) ②
first_eigen_vec = S[:, 0] ③
dot_prod = torch.dot(x_axis_vec, first_eigen_vec) ④
theta = math.acos(dot_prod)
theta = math.degrees(theta) ⑤ ① Equation of the ellipse: 5x2 + 6xy + 5y2 = 20 or ② X-axis vector ③ Major axis of the ellipse ④ The dot product between two vectors is the cosine of the angle between them. ⑤ The angle between the ellipse’s major axis and the X-axis: 45° (see figure 2.16) |
Inspect the PyTorch implementation that constructs the ellipse matrix, computes eigenvectors, and measures the major-axis angle. section 2.17.1
