from scipy.optimize import minimize def objective(x): return x[0]*x[3]*(x[0]+x[1]+x[2])+x[2] def constraint1(x): return x[0]*x[1]*x[2]*x[3]-25.0 def constraint2(x): sum_eq = 40.0 for i in range(4): sum_eq = sum_eq - x[i]**2 return sum_eq #initial guesses x0 = [1,5,5,1] #optimize b = (1.0,5.0) bnds = (b, b, b, b) con1 = {'type': 'ineq', 'fun': constraint1} con2 = {'type': 'eq', 'fun': constraint2} cons = ([con1,con2]) solution = minimize(objective,x0,method='SLSQP',\ bounds=bnds,constraints=cons) x = solution.x #print solution print('Objective: ' + str(objective(x))) print('Solution:',x)