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

Handling hard inequalities

Back in the coffee shop, you want to look at minimizing daily expenses. You have an objective function that calculates your production costs, and a constraint function that tells you the limits of how much coffee you can produce.

Apply scipy to find the optimal allocation of resources to minimize costs.

Bu egzersiz

Introduction to Optimization in Python

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

Egzersiz talimatları

  • Set the constraint variable using a dictionary.
  • Apply scipy to find the optimal value.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

def objective_function(b):
  return (b[0] - 5) ** 2 + (b[1] - 3) ** 3

def constraint_function(x):
    return 2*x[0] + 3*x[1] - 6

# Set the constraint variable
constraint = ____

x0 = [20, 20]

# Find the minimum
result = minimize(____)

print(result)
Kodu Düzenle ve Çalıştır