MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Introduction to Optimization in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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()
Edit dan Jalankan Kode