Implement QR decomposition of a matrix A into an orthogonal matrix Q and upper triangular matrix R, such that A = Q*R. Use the Gram-Schmidt process.
Algorithm:
1. Apply Gram-Schmidt to columns of A to get orthonormal columns → Q
2. Compute R = Q^T * A
Example:
Input: A = [[1, 1], [0, 1]]
Output: Q ≈ [[1, 0], [0, 1]], R ≈ [[1, 1], [0, 1]]
Constraints:
Test Cases
Test Case 1
Input:
[[1, 1], [0, 1]]Expected:
A = Q * R verifiedTest Case 2
Input:
[[1, 0], [0, 1]]Expected:
A = Q * R verifiedTest Case 3
Input:
[[12, -51], [6, 167]]Expected:
A = Q * R verified+ 2 hidden test cases