I wrote the following code to minimize objective where the variables x1, x2, x3 are between 0.8-1.2 and the sum of x1, x2, x3 is a number.
import numpy as np
from scipy.optimize import minimize
def objective(x):
x1 = x[0]
x2 = x[1]
x3 = x[2]
return 1/x1 +2/x3+ 0.5/x2
def constraint1(x):
return 7*x[0]+8*x[1]+4*x[2]-5
x0 = [1,0.8, 1.1]
b = (0.8, 1.2)
bnds = (b,b,b)
con1 = {'type':'eq', 'fun' :constraint1}
solution = minimize(objective, x0, method ='', bounds= bnds, constraints= con1)
print (solution)
I used the BFGS function which gave me an array that is outside the range of 0.8-1.2 while SLSQP gave me success=false. Is there something wrong with my code or am I using the wrong method?