Challenge - 5 Problems
Matrix Inverse Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of matrix inverse calculation
What is the output of this code that calculates the inverse of a 2x2 matrix using scipy?
SciPy
import numpy as np from scipy.linalg import inv matrix = np.array([[4, 7], [2, 6]]) result = inv(matrix) print(result)
Attempts:
2 left
💡 Hint
Recall the formula for inverse of 2x2 matrix [[a,b],[c,d]] is (1/(ad-bc))*[[d,-b],[-c,a]]
✗ Incorrect
The determinant is (4*6 - 7*2) = 10. The inverse is (1/10)*[[6, -7], [-2, 4]] = [[0.6, -0.7], [-0.2, 0.4]].
❓ data_output
intermediate1:30remaining
Number of elements in inverse matrix
After computing the inverse of a 3x3 matrix using scipy.linalg.inv, how many elements does the resulting matrix contain?
SciPy
import numpy as np from scipy.linalg import inv matrix = np.array([[1,2,3],[0,1,4],[5,6,0]]) inverse = inv(matrix) print(inverse.size)
Attempts:
2 left
💡 Hint
The inverse matrix has the same shape as the original matrix.
✗ Incorrect
A 3x3 matrix has 9 elements. Its inverse also has 9 elements.
🔧 Debug
advanced2:00remaining
Error type when inverting a singular matrix
What error does this code raise when trying to invert a singular matrix using scipy.linalg.inv?
SciPy
import numpy as np from scipy.linalg import inv singular_matrix = np.array([[1, 2], [2, 4]]) inv(singular_matrix)
Attempts:
2 left
💡 Hint
A singular matrix has zero determinant and cannot be inverted.
✗ Incorrect
The scipy.linalg.inv function raises a LinAlgError with message 'Singular matrix' when the matrix is not invertible.
🧠 Conceptual
advanced1:00remaining
Effect of matrix inverse on identity matrix
If you multiply a matrix by its inverse, what is the resulting matrix?
Attempts:
2 left
💡 Hint
Think about what an inverse matrix means in multiplication.
✗ Incorrect
Multiplying a matrix by its inverse returns the identity matrix, which acts like 1 in matrix multiplication.
🚀 Application
expert2:30remaining
Using matrix inverse to solve linear equations
Given the system of equations represented by Ax = b, where A is a 2x2 matrix and b is a vector, which code correctly computes x using scipy.linalg.inv?
SciPy
import numpy as np from scipy.linalg import inv A = np.array([[3, 1], [1, 2]]) b = np.array([9, 8])
Attempts:
2 left
💡 Hint
Remember the formula x = A^-1 * b for solving Ax = b.
✗ Incorrect
To solve Ax = b, multiply the inverse of A by b. The dot product order matters.