Loading content...
The Singular Value Decomposition (SVD) is one of the most powerful and versatile tools in numerical linear algebra, enabling us to decompose any matrix into a product of three special matrices that reveal its fundamental geometric properties.
For a real 2×2 matrix A, the SVD expresses it as:
$$A = U \cdot \Sigma \cdot V^T$$
Where:
The Jacobi Rotation Approach:
One elegant method to compute the SVD of a 2×2 matrix involves a Jacobi rotation—a planar rotation designed to diagonalize symmetric matrices. The algorithm works as follows:
This single-rotation approach provides an approximate SVD that is exact for symmetric matrices and offers a good approximation for general 2×2 matrices.
Your Task:
Implement a Python function that computes the approximate SVD of a real 2×2 matrix using a single Jacobi rotation step. You must not use any high-level SVD library functions (like numpy.linalg.svd). Instead, build the decomposition from fundamental matrix operations.
A = np.array([[2.0, 1.0], [1.0, 2.0]])U ≈ [[0.7071, -0.7071], [0.7071, 0.7071]]
S = [3.0, 1.0]
Vt ≈ [[0.7071, 0.7071], [-0.7071, 0.7071]]This is a symmetric matrix with eigenvalues 3 and 1. For symmetric matrices, the SVD coincides with the eigendecomposition—the singular values equal the absolute values of the eigenvalues, and the singular vectors are the eigenvectors. The decomposition satisfies A = U × diag(S) × Vt:
[[0.7071, -0.7071], [0.7071, 0.7071]] × [[3, 0], [0, 1]] × [[0.7071, 0.7071], [-0.7071, 0.7071]] = [[2, 1], [1, 2]]
A = np.array([[3.0, 0.0], [0.0, 2.0]])U = [[1.0, 0.0], [0.0, 1.0]]
S = [3.0, 2.0]
Vt = [[1.0, 0.0], [-0.0, 1.0]]For a diagonal matrix, the SVD is trivial—the matrix is already in 'decomposed' form. The singular values are simply the diagonal entries (3 and 2), and both U and V are identity matrices (or have sign adjustments). No rotation is needed since the matrix is already aligned with the coordinate axes.
A = np.array([[1.0, 2.0], [3.0, 4.0]])U ≈ [[0.3826, 0.9239], [0.9239, -0.3826]]
S ≈ [5.465, 0.366]
Vt ≈ [[0.8174, 0.576], [-0.576, 0.8174]]For this non-symmetric matrix, the Jacobi rotation method computes the SVD by first analyzing AᵀA. The larger singular value (≈5.465) represents the maximum 'stretching' the matrix applies to any unit vector, while the smaller singular value (≈0.366) represents the minimum stretching. The ratio σ₁/σ₂ ≈ 14.9 indicates this matrix is moderately ill-conditioned.
Constraints