Challenge - 5 Problems
Linear System Solver Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of solving a 2x2 linear system
What is the output of this code that solves a simple 2x2 linear system?
SciPy
import numpy as np from scipy.linalg import solve A = np.array([[3, 1], [1, 2]]) b = np.array([9, 8]) x = solve(A, b) print(x)
Attempts:
2 left
💡 Hint
Remember to multiply matrix A by vector x to get vector b.
✗ Incorrect
The system is 3x + y = 9 and x + 2y = 8. Solving gives x=2, y=3.
❓ data_output
intermediate2:00remaining
Number of solutions for a singular matrix
What happens when you try to solve a linear system with a singular matrix using scipy.linalg.solve?
SciPy
import numpy as np from scipy.linalg import solve A = np.array([[1, 2], [2, 4]]) b = np.array([5, 10]) x = solve(A, b) print(x)
Attempts:
2 left
💡 Hint
Check if the matrix can be inverted.
✗ Incorrect
Matrix A is singular (second row is multiple of first), so solve raises LinAlgError.
🔧 Debug
advanced2:00remaining
Identify the error in solving a system with mismatched dimensions
What error does this code produce and why?
SciPy
import numpy as np from scipy.linalg import solve A = np.array([[1, 2], [3, 4]]) b = np.array([5, 6, 7]) x = solve(A, b) print(x)
Attempts:
2 left
💡 Hint
Check the shape of A and b before solving.
✗ Incorrect
Matrix A is 2x2 but vector b has length 3, so dimensions don't match for solving.
🧠 Conceptual
advanced2:00remaining
Effect of using scipy.linalg.solve vs numpy.linalg.solve
Which statement correctly describes the difference between scipy.linalg.solve and numpy.linalg.solve?
Attempts:
2 left
💡 Hint
Think about the libraries' scope and features.
✗ Incorrect
scipy.linalg.solve is built on top of LAPACK and supports more options and matrix types than numpy.linalg.solve.
🚀 Application
expert3:00remaining
Solving a system with a large sparse matrix efficiently
You have a large sparse matrix A and vector b. Which approach is best to solve Ax = b efficiently?
Attempts:
2 left
💡 Hint
Sparse matrices need special solvers to save memory and time.
✗ Incorrect
scipy.sparse.linalg.spsolve is designed for sparse matrices and is efficient for large systems.