Challenge - 5 Problems
Linear Algebra Mastery in Scientific Computing
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Matrix multiplication output
What is the output of the following code that multiplies two matrices using SciPy?
SciPy
import numpy as np from scipy.linalg import blas A = np.array([[1, 2], [3, 4]]) B = np.array([[5, 6], [7, 8]]) result = blas.dgemm(alpha=1.0, a=A, b=B) print(result)
Attempts:
2 left
💡 Hint
Recall how matrix multiplication sums products of rows and columns.
✗ Incorrect
Matrix multiplication multiplies rows of the first matrix by columns of the second. For example, element (0,0) is 1*5 + 2*7 = 19.
❓ data_output
intermediate1:30remaining
Shape of matrix after transpose and multiplication
Given a matrix A of shape (3, 4), what is the shape of the matrix resulting from A.T @ A?
SciPy
import numpy as np A = np.random.rand(3, 4) result = A.T @ A print(result.shape)
Attempts:
2 left
💡 Hint
Transpose flips rows and columns. Matrix multiplication shape depends on inner dimensions.
✗ Incorrect
A.T has shape (4, 3). Multiplying (4, 3) by (3, 4) results in (4, 4).
❓ visualization
advanced3:00remaining
Visualizing eigenvectors of a matrix
Which option correctly plots the eigenvectors of matrix M as arrows starting from the origin?
SciPy
import numpy as np import matplotlib.pyplot as plt M = np.array([[2, 1], [1, 2]]) eigenvalues, eigenvectors = np.linalg.eig(M) plt.figure() plt.axhline(0, color='grey') plt.axvline(0, color='grey') for vec in eigenvectors.T: plt.arrow(0, 0, vec[0], vec[1], head_width=0.05, head_length=0.1, fc='blue', ec='blue') plt.xlim(-1, 1) plt.ylim(-1, 1) plt.title('Eigenvectors of M') plt.show()
Attempts:
2 left
💡 Hint
Eigenvectors show directions that stretch or shrink under M.
✗ Incorrect
The code plots arrows from origin along eigenvectors, showing directions preserved by M.
🧠 Conceptual
advanced1:30remaining
Why is linear algebra essential in scientific computing?
Which statement best explains why linear algebra is the foundation of scientific computing?
Attempts:
2 left
💡 Hint
Think about how many problems can be expressed as linear systems.
✗ Incorrect
Most scientific problems can be modeled as linear systems or transformations, making linear algebra essential.
🔧 Debug
expert2:00remaining
Identify the error in matrix inversion code
What error does the following code raise when trying to invert matrix A?
SciPy
import numpy as np A = np.array([[1, 2], [2, 4]]) inv_A = np.linalg.inv(A) print(inv_A)
Attempts:
2 left
💡 Hint
Check if matrix A is invertible by its determinant.
✗ Incorrect
Matrix A is singular because its rows are linearly dependent, so it cannot be inverted.