I would like to write a code in Scipy to optimization. I need to write a code below to get maximize.
Decision variablesx1x2x3
Constraints x1+ x2 ≤ x3
x3<=17.25x1>=0x2>=0x3>=0
Objective function Maximize proft (x1)(30-x1) -3x1 + x2*(50-2x2)- 2x2 -x3*10
How to write a proper code?
I have tried something like this: But i get false result:`
> def objective(x):
> x1=x[0]
> x2=x[1]
> x3=x[2]
> return -((30-x1)*(x1)+(50-2*x2)*(x2)- (2*x2) -(10*x3) -(3*x1))
> def constraint1(x):
> return x[0]+x[1]-x[2]
> def constraint2(x):
> return x[0]+x[1]+x[2]-1
> x0=[8.5,9.5,18]
> print(objective(x0))
> ```
> b=(-100,100)
> bnds=(b)
> con1={'type':'ineq','fun':constraint1}
> cons=[con1]
>
> ```
> #sol=minimize(objective,x0,method='SLSQP',bounds=bnds,constraints=con1)
> sol=minimize(objective,x0,method='BFGS',bounds=bnds,constraints=con1)
fun: -1051775188.2452506
hess_inv: array([[ 0.69990046, 0.06287501, -0.38138773],
[ 0.06287501, 0.33722409, -0.20004955],
[-0.38138773, -0.20004955, 0.29071868]])
jac: array([2.8336e+04, 3.4032e+04, 1.6000e+01])
message: 'Desired error not necessarily achieved due to precision loss.'
nfev: 396
nit: 26
> njev: 79
status: 2
success: False
x: array([ 1.41804955e+04, 8.51889126e+03, -1.39721288e+08])