Gekko 中的步进函数实现

Step function implementation in Gekko

我正在尝试在 Gekko (IMODE=6) 中实现类似于步进函数的功能。 我试过 If3 并设置自定义上下限,在 Gekko 中仍然找不到解决方案。

对于这样的阶梯函数或 Gekko 中的任何分段函数,您有什么建议?

Gekko 中允许步进函数(或任何其他输入)。如果 step 函数不依赖于条件而仅依赖于时间,那么您将不需要 if3 函数。这是定义阶跃函数的 u_step 的示例问题。

import numpy as np
from gekko import GEKKO
import matplotlib.pyplot as plt

m = GEKKO()    # create GEKKO model
m.time = np.linspace(0,40,401) # time points

# create GEKKO parameter (step 0 to 2 at t=5)
u_step = np.zeros(401)
u_step[50:] = 2.0
u = m.Param(value=u_step)

# create GEKKO variables
x = m.Var(0.0) 
y = m.Var(0.0) 

# create GEEKO equations
m.Equation(2*x.dt()==-x+u) 
m.Equation(5*y.dt()==-y+x) 

# solve ODE
m.options.IMODE = 4
m.solve()

# plot results
plt.plot(m.time,u,'g:',label='u(t)')
plt.plot(m.time,x,'b-',label='x(t)')
plt.plot(m.time,y,'r--',label='y(t)')
plt.ylabel('values')
plt.xlabel('time')
plt.legend(loc='best')
plt.show()

可以使用 differential equations solved with Gekko 的其他教程。