fix project 1 q1 bug

This commit is contained in:
2025-10-21 16:25:27 -04:00
parent 5acb5d6900
commit 1ecd5a4bbe
4 changed files with 39 additions and 33 deletions

View File

@@ -38,9 +38,13 @@ def proj_SVD(A:np.ndarray, b:np.ndarray) -> np.ndarray:
= U S V^* (V S^2 V^*)^(-1) V S U^* b
= U S V^* V S^(-2) V^* V S U^* b
= U U^* b
If A = U S V^*, then the projection onto the column space of A is:
proj_A(b) = U_r U_r^* b
where U_r are the left singular vectors corresponding to nonzero singular values.
"""
U_r = U[:, :np.linalg.matrix_rank(A)] # Take only the relevant columns
# Compute the projection using the SVD components
projection = U @ U.conj().T @ b
projection = U_r @ U_r.conj().T @ b
return projection
def build_A(eps: float) -> np.ndarray: