According to the SciPy documentation, it is possible to minimize functions with multiple variables, yet it doesn’t say how to optimize such functions.
from scipy.optimize import minimize
from math import *
def f(c):
return sqrt((sin(pi/2) + sin(0) + sin(c) - 2)**2 + (cos(pi/2) + cos(0) + cos(c) - 1)**2)
print(minimize(f, 3.14/2 + 3.14/7))
The above code try to minimize the function f, but for my task I need to minimize with respect to three variables.
Simply introducing a second argument and adjusting minimize accordingly yields an error:
TypeError: f() takes exactly 2 arguments (1 given)
How does minimize work when minimizing with multiple variables?
Pack the multiple variables into a single array:
yields