如何在 GEKKO 中间体中使用 np.log 或 np.exp

How to use np.log or np.exp in GEKKO intermediate

我正在使用 gekko 求解方程组。作为一个中间步骤,我使用一个将 MV 温度插入以下函数的中间体:

def riedelVP(T, const):
    '''Returns Vapor Pressure
    INPUTS
    :T - Temperature (K)
    :const - A, B, C, D, E constants for eqn
    OUTPUTS
    :Y - Pressure in Pascals'''
    # unpack constants
    a, b, c, d, e = const
    
    # plug into equation
    Y = np.exp(a+b/T+c*np.log(T) + d*T**e)
    return Y

当我这样做时,出现以下错误:

我试过使用 T.valueT.value[0] 作为函数的参数而不是 T。
TypeError: loop of ufunc does not support argument 0 of type GKVariable which has no callable log method
如何使用带有 exp 的函数并登录 gekko 中间体

这种情况下的问题是 np.exp() 函数和 np.log 函数都需要一个 float 参数,而 gekko 变量是它们自己的类型。如果您使用 gekko 的方法求幂并在函数中取对数,它将起作用。为此,请使用 m.expm.log 方法。在此示例中,我已经使用 m = GEKKO() 创建了一个 gekko 模型,然后我可以创建函数:

def riedelVP(T, const):
    '''Returns Vapor Pressure
    INPUTS
    :T - Temperature (K)
    :const - A, B, C, D, E constants for eqn
    OUTPUTS
    :Y - Pressure in Pascals'''
    # unpack constants
    a, b, c, d, e = const
    
    # plug into equation
    Y = m.exp(a+b/T+c*m.log(T) + d*T**e)
    return Y

当函数中出现类型错误时,使用 gekko 的类似方法。