Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
SciPy - Advanced Optimization
What will be the output of this code?
from scipy.optimize import linprog
c = [2, 3]
A_eq = [[1, 1]]
b_eq = [5]
result = linprog(c, A_eq=A_eq, b_eq=b_eq, bounds=[(0, None), (0, None)])
print(result.x)
A[0. 5.]
B[2.5 2.5]
C[5. 0.]
D[0. 0.]
Step-by-Step Solution
Solution:
  1. Step 1: Understand the problem constraints

    The equality constraint is x1 + x2 = 5, with both variables >= 0.
  2. Step 2: Minimize the objective function

    The objective is to minimize 2*x1 + 3*x2. Since 3 > 2, minimizing cost means setting x2 as low as possible (0) and x1 as high as possible (5). So solution is x1=5, x2=0.
  3. Final Answer:

    [5. 0.] -> Option C
  4. Quick Check:

    linprog solution = [5. 0.] [OK]
Quick Trick: Minimize cost by assigning more to cheaper variable [OK]
Common Mistakes:
  • Swapping variable values
  • Ignoring bounds
  • Misinterpreting equality constraints

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes