Gekko class returns 表达式不是值

Gekko class returns an expression not a value

我对 GEKKO class 有疑问: 我必须使用 m.exp 和 m.log 之类的函数,但这之后会产生问题。这是我的代码的一部分:

import numpy as np
from math import sinh, cosh
from scipy.integrate import quad
import csv

m = GEKKO()

def Antoine(T, C1, C2, C3, C4, C5):

    
    P = m.exp(C1 + (C2 / T) + (C3 * m.log(T)) + (C4 * (T ** C5)))

    return (P / 1000) # kPa

当我使用这个函数(在代码的后面)时,它 return 是一个 gekko class,我无法在之后操作。 这是来自 VSC 调试器:

((((exp(((66.60897125778965+((-9.2194)*(log(393.15))))+1.07887711905)))/(1000)))/(200))

这是我使用 type()

时 return 的类型

<class 'gekko.gk_operators.GK_Operators'>

我需要它的值,而不是表达式,我需要一个 float 类型。如果我尝试使用 .VALUE 方法,它 returns 零 0.

我希望有人能帮助我。

尝试使用 m.solve() 命令生成值。 Gekko 构建每个表达式的符号版本以使用自动微分。解决命令后,出现值。

from gekko import GEKKO
m = GEKKO()
def Antoine(T, C1, C2, C3, C4, C5):
    P = m.exp(C1 + (C2 / T) + (C3 * m.log(T)) + (C4 * (T ** C5)))
    return (P / 1000) # kPa

T = m.Var(lb=100)
P = m.Intermediate(Antoine(T,0.1,1.0,0.2,0.3,0.4))
# find temperature where pressure is 101.325kPa
m.Equation(P==101.325)

m.solve()

print('Pressure: ', P.value[0])
print('Temperature: ', T.value[0])

任意安托万系数的结果是:

Number of Iterations....: 10

                                   (scaled)                 (unscaled)
Objective...............:   0.0000000000000000e+00    0.0000000000000000e+00
Dual infeasibility......:   0.0000000000000000e+00    0.0000000000000000e+00
Constraint violation....:   2.5554220428603003e-07    2.5554220428603003e-07
Complementarity.........:   0.0000000000000000e+00    0.0000000000000000e+00
Overall NLP error.......:   2.5554220428603003e-07    2.5554220428603003e-07


Number of objective function evaluations             = 12
Number of objective gradient evaluations             = 11
Number of equality constraint evaluations            = 18
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 11
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 10
Total CPU secs in IPOPT (w/o function evaluations)   =      0.004
Total CPU secs in NLP function evaluations           =      0.001

EXIT: Optimal Solution Found.
 
 The solution was found.
 
 The final value of the objective function is   0.000000000000000E+000
 
 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :   1.020000000426080E-002 sec
 Objective      :   0.000000000000000E+000
 Successful solution
 ---------------------------------------------------
 
Pressure:  101.32500026
Temperature:  5926.9919202