Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
SciPy - Linear Algebra (scipy.linalg)
What is the output of this code?
import numpy as np
from scipy.linalg import solve
A = np.array([[2, 1], [1, 3]])
b = np.array([10, 15])
x = solve(A, b)
print(x)
A[4. 3.]
B[3. 4.]
C[2. 5.]
D[5. 2.]
Step-by-Step Solution
Solution:
  1. Step 1: Set up the system of equations

    The matrix A and vector b represent the system:
    2x + y = 10
    x + 3y = 15
  2. Step 2: Solve the system manually

    Solving manually:
    Multiply first equation by 3: 6x + 3y = 30
    Subtract second equation: 5x = 15 -> x = 3
    y = 10 - 2*3 = 4
    Thus, x = [3. 4.], which matches the output of solve(A, b).
  3. Final Answer:

    [3. 4.] -> Option B
  4. Quick Check:

    solve(A,b) output = [3. 4.] [OK]
Quick Trick: Trust solve() output for exact numeric solutions. [OK]
Common Mistakes:
MISTAKES
  • Mixing up order of solution vector
  • Trying to solve manually without decimals
  • Assuming integer solutions only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes