from gekko import GEKKO import numpy as np m = GEKKO() m.time = np.linspace(0,8,81) t = m.Param(m.time) u = m.MV(1,lb=0,ub=5); u.STATUS=1 x = m.Var(1) m.periodic(u) m.periodic(x) m.Minimize((x-3)**2) m.Equation(x.dt()+x==m.cos(t)+u) m.options.IMODE = 6 m.solve() import matplotlib.pyplot as plt plt.plot(m.time,u,m.time,x) plt.legend(['u','x']) plt.show()