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

Finding the maxima

Unconstrained optimization is finding the maxima or minima of a function that does not have any constraints or restrictions on the input variables.

Suppose you are launching a new product in your delicious cookie company and you want to maximize the revenue. The revenue can be modeled with this objective function where R is the revenue generated at price x.

R = -(x**2) + 3*x - 5

Solve this maximization problem using SciPys minimize_scalar() which has been loaded for you.

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

  • Define a new objective function that is the negation of the original objective function.
  • Maximize the negated function.
  • Print the optimal value to two decimal places.

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.

# Define the new objective function
def negated_function(x):
  ____

# Maximize the negated function
result = ____

# Print the result
print(f"The maximum is {____} in two decimals")
Chỉnh sửa và Chạy Mã