I am trying to use scipy.optimize.minimize (simplex method) for minimizing the following function
argmin (sum(i=0 to 9) (a*i - b_i)**2)
I would like to obtain the value of a. I have 10 values of b_i (i have it already calculated outside the function) that i want to insert in the function
def f(a, b):
func = 0
for i in range(10):
func+= (a*i - b[i])**2
return func
init = [1]
out= optimize.minimize(f, init, method='nelder-mead')
it gives an error saying: f() missing 1 required positional argument: 'b'
How can i make it run.
init = [1 , 1]? You should pass two values to objective function. Ordef f(a)(as you saidbcalculated already, then just remove it from arguments.)bis not one value, it has 10 values. I have corrected now.b[i]instead ofb! I mean :func+= (a*i - b[i])**2and also removebfrom function arguments.