I am getting some very weird results when running the minimize function from scipy optimize.
Here is the code
from scipy.optimize import minimize
def objective(x):
return - (0.05 * x[0] ** 0.64 + 0.4 * x[1] ** 0.36)
def constraint(x):
return x[0] + x[1] - 5000
cons = [{'type':'eq', 'fun': constraint}]
when running
minimize(objective, [2500.0, 2500.0], method='SLSQP', constraints=cons)
i get allocation 2500
for each element of x.
with fun: -14.164036415985395
With a quick check, this allocation [3800, 1200]
gives -14.9
It is highly sensitive to the initial conditions also .
Any thoughts as to what i am doing wrong
the two functions plotted
UPDATE It actually returns the initial conditions.
If i try this though
def objective(x):
return - (x[0] ** 0.64 + x[1] ** 0.36)
def constraint(x):
return x[0] + x[1] - 5000.0
cons = [{'type':'eq', 'fun': constraint}]
minimize(objective, [2500, 2500], method='SLSQP', constraints=cons)
returned results seem to be just fine (i have changed the objective function)