Aan de slagGa gratis aan de slag

Multivariate optimization

Great job maximizing that revenue! You now want to look at minimizing costs.

You'll need to consider two variables for your new cookie product, the sugar ingredient (a[0]) and the flour ingredient (a[1]). This is a multivariate optimization problem where you want to find the best way to mix these ingredients so that your cookies are delicious but not too expensive!

SciPy's minimize() function has been loaded for you and the objective function has been provided.

Deze oefening maakt deel uit van de cursus

Introduction to Optimization in Python

Cursus bekijken

Oefeninstructies

  • Save your initial guess to x0; this can be anything!
  • Calculate and print the minimum.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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

# Save your initial guess
x0 = ____

# Calculate and print the minimum
result = minimize(____, ____)
print(f"minimum is (x, y) = ({result.x[0]:.2f}, {result.x[1]:.2f}) in two decimals.")
Code bewerken en uitvoeren