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.
This exercise is part of the course
Introduction to Optimization in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create an array of integers from 0 to 9
quantity = ____
# Define the cost function
def cost(q):
return ____
# Plot cost versus quantity
plt.plot(____, ____)
plt.xlabel('Quantity (thousands)')
plt.ylabel('Cost ($ K)')
plt.show()