Challenge - 5 Problems
Preconditioner Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of applying Jacobi preconditioner
Given the sparse matrix A and vector b, what is the output of applying the Jacobi preconditioner to b using scipy?
SciPy
import numpy as np from scipy.sparse import diags from scipy.sparse.linalg import LinearOperator A = diags([4, -1, -1], [0, -1, 1], shape=(3,3)) b = np.array([1, 2, 3]) D_inv = diags(1 / A.diagonal()) M = LinearOperator(A.shape, matvec=lambda x: D_inv.dot(x)) result = M.matvec(b) print(result)
Attempts:
2 left
💡 Hint
Remember the Jacobi preconditioner uses the inverse of the diagonal elements of A.
✗ Incorrect
The Jacobi preconditioner multiplies the vector by the inverse of the diagonal of A. Since A's diagonal is [4,4,4], the inverse diagonal is [0.25, 0.25, 0.25]. Multiplying by b = [1,2,3] gives [0.25, 0.5, 0.75].
🧠 Conceptual
intermediate1:30remaining
Purpose of Preconditioners in Iterative Solvers
What is the main purpose of using a preconditioner in iterative methods for solving linear systems?
Attempts:
2 left
💡 Hint
Think about how preconditioners affect the matrix properties.
✗ Incorrect
Preconditioners improve the matrix's condition number, making iterative solvers converge faster by transforming the system into an easier one to solve.
🔧 Debug
advanced2:00remaining
Identify the error in incomplete LU preconditioner code
What error will this code raise when trying to create an incomplete LU preconditioner with scipy.sparse.linalg.spilu on a singular matrix?
SciPy
import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.linalg import spilu A = csr_matrix([[0, 1], [0, 0]]) ilu = spilu(A)
Attempts:
2 left
💡 Hint
Consider what happens if the matrix cannot be factorized.
✗ Incorrect
The matrix is singular (zero row), so spilu cannot factorize it and raises a RuntimeError indicating the factor is exactly singular.
❓ data_output
advanced1:30remaining
Output shape of preconditioned vector
If you apply an incomplete LU preconditioner created by spilu on a vector of length 5, what will be the shape of the output vector?
SciPy
import numpy as np from scipy.sparse import diags from scipy.sparse.linalg import spilu A = diags([1, 2, 3, 4, 5], 0) ilu = spilu(A) v = np.array([1, 2, 3, 4, 5]) result = ilu.solve(v) print(result.shape)
Attempts:
2 left
💡 Hint
The preconditioner solves a system of the same size as the input vector.
✗ Incorrect
The preconditioner returns a vector of the same shape as the input vector, which is (5,).
🚀 Application
expert2:30remaining
Choosing a preconditioner for a large sparse symmetric positive definite matrix
You have a large sparse symmetric positive definite matrix A. Which preconditioner is generally the best choice to speed up conjugate gradient solver convergence?
Attempts:
2 left
💡 Hint
Consider the matrix properties and the solver used.
✗ Incorrect
For symmetric positive definite matrices, incomplete Cholesky is preferred as it preserves symmetry and positive definiteness, improving conjugate gradient convergence.