ComenzarEmpieza gratis

Exhaustive search method

You've applied the objective function and visualized the result; however, you could only eye-ball the optimal value by reviewing the plot. A more precise way of finding this value is with the exhaustive search method.

You're again working for a media company that publishes and prints magazines, but this time, you'll discover how to maximize profit rather than minimize cost. Recall that the profit and quantity units are in the thousands, so a q of 1 is 1000 magazines and a profit of 5 is $5000.

The same quantity array from the previous exercise has been provided for you, along with a profit() function to optimize.

numpy has been imported for you as np.

Este ejercicio forma parte del curso

Introduction to Optimization in Python

Ver curso

Instrucciones del ejercicio

  • Calculate the profit for every quantity using the profit() function provided, saving to profits.
  • Find the maximum profit with the appropriate array method, saving to max_profit.
  • Find the optimal quantity to maximize profit by saving the index of the maximum profit as max_index, then using this to subset quantity.
  • Print the results by completing the f-string, remembering to multiply the profit and quantity by 1000.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Calculate the profit for every quantity
profits = ____

# Find the maximum profit
max_profit = ____

# Find the optimal quantity
max_profit_ind = ____
optimal_quantity = ____

# Print the results
print(f"You need to print {____} magazines to make the maximum profit of ${____}.")
Editar y ejecutar código