I need to optimize the objective function (minimize).
The sum of x1+x2+x3 = 1 (This is my unique constranint). Following this, the bounds of the x1,x2,x3 has to be between (+0,<1). Positive values, but less than 1.
I dont have any initial guess. In this example I copy the answear of the problem that I made it on paper. But the scipy answer it's not the same, so it's not right.
I tried using scipy and puLP. But with neither of both I could solve it. I don't know if I am using the perfect tool for this problem.
Thanks you.
from scipy.optimize import minimize
import numpy as np
def objective(x):
x1=x[0]
x2=x[1]
x3=x[2]
return 0.3442 * x1 **2 + 0.3814 * x2 + 0.2901 **2 + 2*(-0.0116)* x1 *x2+ 2*(-0.30373)* x2 * x3 +2*(0.1883)* x1 *x3
def equality(x):
x1=x[0]
x2=x[1]
x3=x[2]
return x1+x2+x3-1
cons = {'type':'eq', 'fun': equality}
x0=[0.1944,0.4056,0.4000] #the correct answear for the values of x1, x2, x3
bounds=[[0,1],[0,1],[0,1]]
print(minimize(objective, x0, constraints=cons, method='SLSQP'))