Bắt đầu ngayBắt đầu miễn phí

Working with Bounds

Bound-constrained problems have variables that are limited to a range of values.

You're running a coffee shop and need to place an order for two varieties of coffee beans: b[0] and b[1]. You want to minimize costs. Your supplier only accepts minimum quantity orders of 2 units for each bean, and you can afford a maximum of 100 units per bean.

minimize and Bounds from scipy.optimize have been loaded for you and the objective function is provided.

Bài tập này là một phần của khóa học

Introduction to Optimization in Python

Xem khóa học

Hướng dẫn bài tập

  • Set the lower and upper bound values for b[0] and b[1] as bounds.
  • Use scipy to find the minimum.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

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

# Set the bounds of your problem
bounds = ____

x0 = [10, 5]

# Find the minimum
result = ____(____)

print(result.x)
Chỉnh sửa và Chạy Mã