【问题标题】:How to use np.log or np.exp in GEKKO intermediate如何在 GEKKO 中级中使用 np.log 或 np.exp
【发布时间】:2021-06-01 05:57:28
【问题描述】:

我正在使用 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 中间体

【问题讨论】:

    标签: numpy gekko


    【解决方案1】:

    这种情况下的问题是np.exp() 函数和np.log 函数都需要一个浮点参数,而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的类似方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2021-11-20
      • 2014-09-18
      • 2021-01-07
      • 2021-04-16
      • 1970-01-01
      相关资源
      最近更新 更多