0
0
SciPydata~10 mins

Preconditioners in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the preconditioner module from scipy.

SciPy
from scipy.sparse.linalg import [1]
Drag options to blanks, or click blank then click option'
Aaslinearoperator
Bcg
CLinearOperator
Dspilu
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'cg' which is a solver, not a preconditioner.
Choosing 'LinearOperator' which is a class, not a preconditioner function.
2fill in blank
medium

Complete the code to create an incomplete LU preconditioner for matrix A.

SciPy
M_x = spilu([1])
Drag options to blanks, or click blank then click option'
AA
Bx
Cb
DM
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the right-hand side vector b instead of the matrix.
Passing the preconditioner variable M before it is defined.
3fill in blank
hard

Fix the error in creating a LinearOperator for the preconditioner.

SciPy
M = LinearOperator(A.shape, matvec=[1].solve)
Drag options to blanks, or click blank then click option'
Ab
BA
CM_x
Dspilu
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the matrix A instead of the preconditioner object.
Passing the function spilu itself instead of its result.
4fill in blank
hard

Fill both blanks to solve the linear system using the preconditioner.

SciPy
x, info = cg([1], [2], M=M)
Drag options to blanks, or click blank then click option'
AA
Bb
Cx0
DM_x
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the matrix and vector arguments.
Passing the preconditioner as a positional argument.
5fill in blank
hard

Fill all three blanks to create and apply a preconditioner in a solver.

SciPy
M_x = spilu([1])
M = LinearOperator([2], matvec=M_x.solve)
x, info = cg([3], b, M=M)
Drag options to blanks, or click blank then click option'
AA
BA.shape
Db
Attempts:
3 left
💡 Hint
Common Mistakes
Using the vector b instead of the matrix A for preconditioner.
Passing the wrong shape to LinearOperator.
Passing b instead of A to the solver.