我试图在Gekko(IMODE = 6)中实现类似于step函数的功能。 我尝试了If3并设置了自定义的上限和下限,但是在Gekko中仍然找不到解决方案。
您对Gekko中的这种步进功能或任何分段功能有何建议?
答案 0 :(得分:2)
在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的其他教程。