0
0
SciPydata~10 mins

Solving linear systems (solve) 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 function that solves linear systems.

SciPy
from scipy.linalg import [1]

A = [[3, 1], [1, 2]]
b = [9, 8]
x = [1](A, b)
print(x)
Drag options to blanks, or click blank then click option'
Asolve
Binv
Cdet
Deig
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'inv' instead of 'solve' to solve the system.
Trying to use 'det' or 'eig' which are unrelated to solving linear systems.
2fill in blank
medium

Complete the code to solve the system and print the solution vector.

SciPy
from scipy.linalg import solve

A = [[4, 2], [3, 1]]
b = [10, 8]
x = solve(A, [1])
print(x)
Drag options to blanks, or click blank then click option'
A[10, 8]
Bb
CA
Dsolve
Attempts:
3 left
💡 Hint
Common Mistakes
Passing matrix A as second argument instead of vector b.
Passing the function name 'solve' as argument.
3fill in blank
hard

Fix the error in the code to correctly solve the linear system.

SciPy
from scipy.linalg import solve

A = [[1, 2], [3, 4]]
b = [5, 6]
x = solve([1], b)
print(x)
Drag options to blanks, or click blank then click option'
AA
Bb
C[5, 6]
Dsolve
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments to solve.
Passing the vector b as first argument.
4fill in blank
hard

Fill both blanks to create a dictionary of solutions for each variable from the system.

SciPy
from scipy.linalg import solve

A = [[2, 1], [1, 3]]
b = [8, 13]
x = solve(A, b)
solution = { [1]: x[0], [2]: x[1] }
print(solution)
Drag options to blanks, or click blank then click option'
A"x1"
B"x2"
C"a"
D"b"
Attempts:
3 left
💡 Hint
Common Mistakes
Using matrix or vector names as keys instead of variable names.
Using unquoted keys causing syntax errors.
5fill in blank
hard

Fill the blanks to create a dictionary comprehension that maps variable names to their solutions if the solution is positive.

SciPy
from scipy.linalg import solve

A = [[1, -1], [2, 3]]
b = [1, 12]
x = solve(A, b)
result = { [1]: x[i] for i in range(2) if x[i] [2] 0 }
print(result)
Drag options to blanks, or click blank then click option'
A"x" + str(i+1)
B>
C>=
D"var" + str(i)
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect string concatenation for keys.
Using '<' or '<=' instead of '>' in the condition.