简体   繁体   English

如何使用GEKKO对日志或sqrt建模? 约束

[英]How should I model log or sqrt with GEKKO? Constraints

I'm trying to develop my constraints with GEKKO, and I need to include some mathematical operations as log, coth or sqrt. 我正在尝试使用GEKKO开发我的约束,并且需要包括一些数学运算,例如log,coth或sqrt。

I tried initially with my habitual procedures, using numpy or mpmath, but I figure out that using GEKKO I need to use their operator definitions, as m.wathever (log,...), once the m = GEKKO() is done 我最初使用numpy或mpmath尝试了惯用程序,但我发现使用mekth时,一旦完成m = GEKKO(),我需要使用它们的运算符定义,例如m.wathever(log,...)。

How is the best way to develop that? 如何发展最好的方法? Should I take some considerations while I'm changing it? 更改时是否应该考虑一些问题?

K_t = (1 + m + np.sqrt(1 + m**3)) - mpmath.coth(s/2)  # Ref 2. Same results

Use the Gekko versions of those functions instead of the NumPy or Math versions: 使用这些函数的Gekko版本而不是NumPy或Math版本:

gk = GEKKO()
K_t = (1 + m + gk.sqrt(1 + m**3)) - gk.cosh(s/2)/gk.sinh(s/2)

The Gekko versions are needed because of operator overloading to calculate first and second derivatives for the solvers with automatic differentiation. 需要Gekko版本是因为运算符重载,以便使用自动微分来计算求解器的一阶和二阶导数。 There is no coth so you'll need to substitute with coth(x) = cosh(x)/sinh(x) . 没有coth因此您需要用coth(x) = cosh(x)/sinh(x)代替。 I typically define my Gekko model as m=GEKKO() but you have another variable named m so I used gk instead. 我通常将我的Gekko模型定义为m=GEKKO()但是您还有另一个名为m变量,因此我改用gk Here is a section from the documentation on Model Building Functions . 这是有关“模型构建功能文档的一部分。

Equation Functions 方程函数

Special function besides algebraic operators are available through GEKKO functions. GEKKO函数可提供除代数运算符之外的特殊函数。 These must be used (not numpy or other equivalent functions): 必须使用这些(不是numpy或其他等效函数):

  • gk.sin(other) gk.sin(其他)
  • gk.cos(other) gk.cos(其他)
  • gk.tan(other) gk.tan(其他)
  • gk.asin(other) gk.asin(其他)
  • gk.acos(other) gk.acos(其他)
  • gk.atan(other) gk.atan(其他)
  • gk.sinh(other) gk.sinh(其他)
  • gk.cosh(other) gk.cosh(其他)
  • gk.tanh(other) gk.tanh(其他)
  • gk.exp(other) gk.exp(其他)
  • gk.log(other) gk.log(其他)
  • gk.log10(other) gk.log10(其他)
  • gk.sqrt(other) gk.sqrt(其他)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM