1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Optimization in Python

Connected

Exercise

Applying an objective function

You work for a media company and are faced with the problem of minimizing the cost to print and distribute magazines. You want to find the optimal number of magazines to publish and print for the smallest cost.

In your organization, the costs associated with a number of magazines printed is calculated using the following equation:

$$ C = 50 + 5(q - 2)^2 $$

The costs \(C\) and quantity of magazines \(q\) are in thousands, so the 50 represents $50,000, the fixed costs of your business, such as paying the rent on the building.

numpy and matplotlib.pyplot have been imported for you as np and plt, respectively.

Instructions 1/2

undefined XP
    1
    2
  • Create a numpy array ranging from 0 to 9; this represents the number of magazines printed.
  • Define a cost() function that computes the cost for a given quantity, \(q\), using the equation: \(50 + 5(q - 2)^2\).
  • Plot the cost, using the cost() function, to see where the optimum is.