0Pricing
R Academy · Lesson

SVD, QR, and Cholesky Decompositions

Apply svd(), qr(), and chol() for dimensionality reduction and factorization.

Why Matrix Decompositions?

Matrix decompositions factor A into products of simpler matrices. They reveal hidden structure (rank, condition), enable efficient computation, and are the backbone of PCA, regression, and optimization in statistics and machine learning.

# Three fundamental decompositions:
# 1. SVD: A = U D V'  (any matrix)
# 2. QR:  A = Q R    (any matrix)
# 3. Cholesky: A = L L'  (symmetric positive definite)

# Each serves a purpose:
# SVD -> PCA, pseudoinverse, rank, image compression
# QR  -> linear regression, Gram-Schmidt, eigenvalues
# Cholesky -> fast solve for SPD systems, simulation

A <- matrix(c(4, 3, 2,
              3, 6, 1,
              2, 1, 5), nrow = 3, byrow = TRUE)
cat('Matrix ready for decomposition')
print(A)

SVD: svd() Function

The Singular Value Decomposition (SVD) factorizes any m×n matrix A = U D V', where U and V are orthogonal and D is diagonal with non-negative singular values in decreasing order.

A <- matrix(c(1, 2, 3,
              4, 5, 6), nrow = 2, byrow = TRUE)

# Compute SVD
svd_result <- svd(A)

# Components:
svd_result$d  # singular values (decreasing)
svd_result$u  # left singular vectors  (2x2)
svd_result$v  # right singular vectors (3x2)

cat('Singular values:', svd_result$d, '\n')
cat('Rank of A:', sum(svd_result$d > 1e-10), '\n')

All lessons in this course

  1. Matrix Multiplication and Determinants
  2. Solving Linear Systems with solve()
  3. Eigenvalues and Eigenvectors
  4. SVD, QR, and Cholesky Decompositions
← Back to R Academy