Loading content...
Singular Value Decomposition (SVD) is one of the most powerful and versatile factorization techniques in linear algebra and numerical computing. It decomposes any matrix into a product of three matrices that reveal the matrix's fundamental geometric structure: how it rotates, scales, and rotates again when applied as a linear transformation.
For a 2×2 matrix A, the SVD expresses it as:
$$A = U \cdot \Sigma \cdot V$$
Where:
The singular values represent the scaling factors applied to each principal direction. For this problem, we return s as a 1D array [σ₁, σ₂] rather than the full diagonal matrix.
Mathematical Foundation:
The SVD can be computed by finding the eigenvalue decomposition of AᵀA and AAᵀ:
Geometric Interpretation:
Any linear transformation represented by matrix A can be understood as:
Your Task:
Write a Python function that computes the SVD of a 2×2 matrix. The function should:
Important Constraints:
numpy.linalg.svd or other built-in SVD functionsa = [[-10.0, 8.0], [10.0, -1.0]]U = [[-0.8, 0.6], [0.6, 0.8]]
s = [15.6525, 4.4721]
V = [[0.8944, -0.4472], [0.4472, 0.8944]]Explanation
For the matrix A = [[-10, 8], [10, -1]], we compute: 1. **AᵀA** = [[200, -90], [-90, 65]] — eigenvalues: 245.0 and 20.0 2. **Singular values**: √245.0 ≈ 15.6525, √20.0 ≈ 4.4721 3. **V** is constructed from eigenvectors of AᵀA 4. **U** is computed as U = A × V × Σ⁻¹ (or from eigenvectors of AAᵀ) **Verification:** U @ diag(s) @ V ≈ [[-10, 8], [10, -1]] ✓ The larger singular value (15.6525) indicates the primary stretching direction, while the smaller value (4.4721) represents the secondary direction.
a = [[1.0, 0.0], [0.0, 1.0]]U = [[1.0, 0.0], [0.0, 1.0]]
s = [1.0, 1.0]
V = [[1.0, 0.0], [0.0, 1.0]]Explanation
The **identity matrix** is a special case where: - All singular values are equal to 1.0 - Both U and V are the identity matrix - The decomposition is trivially A = I × diag([1,1]) × I = I This represents a transformation that preserves all vectors exactly as they are — no rotation, no scaling.
a = [[3.0, 4.0], [0.0, 5.0]]U = [[0.7071, -0.7071], [0.7071, 0.7071]]
s = [6.7082, 2.2361]
V = [[0.3162, 0.9487], [-0.9487, 0.3162]]Explanation
For this upper triangular matrix: 1. **AᵀA** = [[9, 12], [12, 41]] — compute its eigenvalues and eigenvectors 2. **Singular values**: σ₁ ≈ 6.7082, σ₂ ≈ 2.2361 3. The rotation angle in U is 45° (hence the √2/2 ≈ 0.7071 values) This decomposition reveals that the matrix stretches vectors by about 6.7× in its primary direction.
Constraints