Bird
0
0

Find the bug in this code:

medium📝 Debug Q7 of 15
SciPy - Advanced Optimization
Find the bug in this code:
from scipy.optimize import linprog
c = [1, 1]
A_eq = [[1, 2], [3, 4]]
b_eq = [5]
result = linprog(c, A_eq=A_eq, b_eq=b_eq)
print(result.success)
AIncorrect import statement
BObjective function vector length mismatch
CMissing bounds for variables
DMismatch between number of equality constraints and b_eq length
Step-by-Step Solution
Solution:
  1. Step 1: Check dimensions of constraints

    A_eq has 2 rows (2 equality constraints), but b_eq has length 1. They must match in length.
  2. Step 2: Identify mismatch error

    This mismatch causes an error. Other options are not errors: c length matches variables, bounds are optional, import is correct.
  3. Final Answer:

    Mismatch between number of equality constraints and b_eq length -> Option D
  4. Quick Check:

    Constraint matrix rows must match b_eq length [OK]
Quick Trick: b_eq length must equal number of equality constraints [OK]
Common Mistakes:
  • Ignoring dimension mismatch in constraints
  • Assuming bounds are mandatory
  • Confusing import syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes