Skip to content

how to maximize by using scipy.optimize.minimize, given -1.0 multiplied by the predicted value #1

@xw0413happy

Description

@xw0413happy

Exchanger Heat Transfer Equation is Q=del_TA0U, in here U is 200 (constant)

The goal is to maximize Q, and to get the optimal value of del_T and A0

Note: Importing libraries and working directory codes are omitted here.

a=pd.read_csv('some.csv')
features=['del_T','A0']
x=a[features]
y=a['Q'] # to extract a series

Define a function

def objective(x,y,sign= -1.0): # to get maximum by using '-1' sign
x1=x[0]
x2=x[1]
x3=200
pred_Q=signx1x2*x3
return pred_Q

Set initial guess

x0=[100,100]

Use scipy.optimize.minimize function to solve the problem

solution=minimize(objective,x0,method='BFGS',args=(x,),tol=1e-06)

Result

print(solution)
fun: -138217962.454975
hess_inv: array([[ 0.49750004, -0.50249996],
[-0.50249996, 0.49750004]])
jac: array([-166266., -166266.])
message: 'Desired error not necessarily achieved due to precision loss.'
nfev: 348
nit: 1
njev: 112
status: 2
success: False
x: array([831.31811737, 831.31811737])

From the above codes,

(1) The simulation processing failed; (2) the x roots are around 831, however, in my csv file, the del_T and A0 value ranges both are 94.00--110.00, the result is way larger than the real dataset, which I don't know why; (3) The maximum Q is -138217962.454975, is a wrong result, too high value.

I bet there is something wrong in my def function codes, but I don't know to fix it, can anybody please help me to figure it out?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions