Skip to content
← All questions

Why does the Python code use negative coefficients when maximizing profit with scipy.optimize.linprog?

The code uses negative coefficients because the scipy.optimize.linprog function minimizes by default. To solve a maximization problem, the objective coefficients are negated, converting the task of maximizing profit into minimizing the negative profit.

Conditions

  • Using scipy.optimize.linprog.
  • The original problem is a maximization problem.

Reasoning, step by step

  1. Identify the business goal: maximize profit.
  2. Recognize that linprog minimizes by default.
  3. Negate the objective coefficients to convert maximization to minimization.
  4. Pass the negated coefficients to the solver.

Example

For the chair and table problem, the objective is to maximize 50x+80y50x + 80y. The code sets `c=[−50,−80]c = [-50, -80]` with the comment '# negative for max'.

Common misconceptions

  • Assuming linprog can directly maximize if you pass positive coefficients.
  • Thinking that negating coefficients changes the optimal solution values x and y.

Watch the explanation

Connected concepts

Explore next

Related questions

Understand why

↗
Meet the concept

↗
Find a method

↗

Answers are generated from source material and independently checked. Consult the original video or creator if something is unclear.