from scipy.optimize import minimize #Define objective function def objective_function(x): return 0.5 * x @ Q @ x + p @ x #Define constraints def constraint(x): return G @ x - h #Define optimization con = {'type': 'ineq', 'fun': constraint} b = (0,10); bnds = (b,b) opt = {'maxiter':1000} res = minimize(objective_function, x0, constraints=con,bounds=bnds, method='SLSQP',options=opt) #print results print(f'Optimal solution: x = {res.x}') print(f'Minimum weight = {res.fun}')