BaşlayınÜcretsiz Başlayın

Find the global optimum

You've been provided with the following profit maximization problem and are tasked with finding the global maximum.

\(\Pi= -\frac{1}{4}q^4 + 11q^3 - 160q^2 + 900q\)

\(0\) is a natural lower bound for quantity and you observed that at \(q=30\) profit is negative, so \(30\) is a good candidate for upper bound.

Find the global optimum for this problem.

basinhopping has been imported for you.

Bu egzersiz

Introduction to Optimization in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Define the dictionary kwargs of keyword arguments, with bounds \(0\) and \(30\).
  • Run basinhopping, with the objective as negative of profit and the initial guess x0 passed to the minimizer kwargs.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

def profit(q): 
	return -q**4 / 4 + 11 * q**3 - 160 * q**2 + 900 * q
  
x0 = 0

# Define the keyword arguments for bounds
kwargs = {"bounds": [(____, ____)]} 

# Run basinhopping to find the optimal quantity
result = basinhopping(____ q: -profit(q), ____, ____=kwargs)

print(f"{result.message}")
print(f"The maximum according to basinhopping(x0={x0}) is at {result.x[0]:.2f}\n")
Kodu Düzenle ve Çalıştır