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 the following code that solves a system of linear equations?
import numpy as np A = np.array([[3, 1], [1, 2]]) b = np.array([9, 8]) x = np.linalg.solve(A, b) print(x)
NumPy
import numpy as np A = np.array([[3, 1], [1, 2]]) b = np.array([9, 8]) x = np.linalg.solve(A, b) print(x)
Attempts:
2 left
💡 Hint
Remember that np.linalg.solve finds x in Ax = 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 np.linalg.solve()? Consider this code:
What is the result?
import numpy as np A = np.array([[1, 2], [2, 4]]) b = np.array([5, 10]) x = np.linalg.solve(A, b)
What is the result?
NumPy
import numpy as np A = np.array([[1, 2], [2, 4]]) b = np.array([5, 10]) x = np.linalg.solve(A, b)
Attempts:
2 left
💡 Hint
Singular matrices do not have unique solutions.
✗ Incorrect
The matrix A is singular because the second row is a multiple of the first, so np.linalg.solve raises a LinAlgError.
🔧 Debug
advanced2:00remaining
Identify the error in solving a linear system
What error will this code produce?
import numpy as np A = np.array([[1, 2, 3], [4, 5, 6]]) b = np.array([7, 8]) x = np.linalg.solve(A, b)
NumPy
import numpy as np A = np.array([[1, 2, 3], [4, 5, 6]]) b = np.array([7, 8]) x = np.linalg.solve(A, b)
Attempts:
2 left
💡 Hint
np.linalg.solve requires a square coefficient matrix.
✗ Incorrect
Matrix A is 2x3, not square, so np.linalg.solve raises LinAlgError about non-square matrix.
🚀 Application
advanced2:00remaining
Using np.linalg.solve to find intersection point
Two lines are given by equations:
3x + 2y = 13
7x - y = 19
Use np.linalg.solve to find the intersection point (x, y). What is the output?
3x + 2y = 13
7x - y = 19
Use np.linalg.solve to find the intersection point (x, y). What is the output?
NumPy
import numpy as np A = np.array([[3, 2], [7, -1]]) b = np.array([13, 19]) x = np.linalg.solve(A, b) print(x)
Attempts:
2 left
💡 Hint
Set up the system as Ax = b and solve.
✗ Incorrect
Solving the system gives x=3 and y=2, which satisfies both equations.
🧠 Conceptual
expert2:00remaining
Understanding conditions for np.linalg.solve success
Which condition must be true for np.linalg.solve(A, b) to successfully find a unique solution to Ax = b?
Attempts:
2 left
💡 Hint
Think about when a system has a unique solution.
✗ Incorrect
np.linalg.solve requires A to be square and invertible (non-singular) to find a unique solution.