Bird
0
0

Which of the following is the correct way to call the Conjugate Gradient solver cg from SciPy for a sparse matrix A and vector b?

easy📝 Syntax Q3 of 15
SciPy - Sparse Linear Algebra
Which of the following is the correct way to call the Conjugate Gradient solver cg from SciPy for a sparse matrix A and vector b?
Ax, info = cg(A, b)
Bx = cg(A, b)
Cx, info = cg(b, A)
Dx, info = cg(A)
Step-by-Step Solution
Solution:
  1. Step 1: Recall function signature

    The cg function returns a tuple: solution vector and convergence info. It requires matrix A and right-hand side vector b as inputs.
  2. Step 2: Analyze options

    x, info = cg(A, b) matches the correct call. x = cg(A, b) misses the info output. x, info = cg(b, A) swaps arguments incorrectly. x, info = cg(A) misses vector b.
  3. Final Answer:

    x, info = cg(A, b) -> Option A
  4. Quick Check:

    cg returns (x, info) with (A, b) inputs [OK]
Quick Trick: cg returns (x, info) with A and b inputs [OK]
Common Mistakes:
  • Ignoring the info output
  • Swapping A and b arguments
  • Calling cg without b vector

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes