Challenge - 5 Problems
QR Decomposition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of QR decomposition matrices shapes
Given the following code using
scipy.linalg.qr, what are the shapes of matrices Q and R?SciPy
import numpy as np from scipy.linalg import qr A = np.array([[1, 2], [3, 4], [5, 6]]) Q, R = qr(A, mode='economic') print(Q.shape, R.shape)
Attempts:
2 left
💡 Hint
The 'economic' mode returns reduced shapes for Q and R.
✗ Incorrect
For a 3x2 matrix A, economic QR returns Q with shape (3, 2) and R with shape (2, 2).
❓ data_output
intermediate2:00remaining
Result of reconstructing matrix from QR factors
What is the output of the following code that reconstructs matrix A from its QR decomposition?
SciPy
import numpy as np from scipy.linalg import qr A = np.array([[2, 0], [1, 3]]) Q, R = qr(A) reconstructed = np.dot(Q, R) print(np.round(reconstructed, decimals=5))
Attempts:
2 left
💡 Hint
Multiplying Q and R should give back the original matrix A.
✗ Incorrect
The product Q*R reconstructs the original matrix A exactly (within numerical precision).
🔧 Debug
advanced2:00remaining
Identify the error in QR decomposition code
What error will this code raise when executed?
SciPy
import numpy as np from scipy.linalg import qr A = np.array([[1, 2], [3, 4]]) Q, R = qr(A, mode='invalid_mode')
Attempts:
2 left
💡 Hint
Check the valid modes for the qr function.
✗ Incorrect
The mode parameter only accepts specific strings like 'full', 'economic', 'r', or 'raw'. 'invalid_mode' causes a ValueError.
🧠 Conceptual
advanced1:30remaining
Properties of Q matrix from QR decomposition
Which statement about the Q matrix from QR decomposition is true?
Attempts:
2 left
💡 Hint
Think about what orthogonal means for matrices.
✗ Incorrect
Q is orthogonal, meaning its transpose times itself equals the identity matrix.
🚀 Application
expert3:00remaining
Using QR decomposition to solve linear system
Given matrix A and vector b, which code correctly solves Ax = b using QR decomposition?
SciPy
import numpy as np from scipy.linalg import qr A = np.array([[1, 2], [3, 4]]) b = np.array([5, 11])
Attempts:
2 left
💡 Hint
Recall that A = QR and solve Rx = Q^T b for x.
✗ Incorrect
Since A=QR, Ax=b becomes QRx=b, so Rx=Q^Tb. Solve Rx=Q^Tb for x.