I need to integrate over a system of differential equations in GEKKO and want to use parameters to alter a gradient.
Conceptually this works, but the output is not what I expected. I added a code snippet for a sample problem below to illustrate the problem.
The solver will integrate over a specified time horizon, in this case t = [0, 1, 2, 3]
A parameter is defined that represents the gradient at each value in time called p = [0, 1, 2, 3].
My expectation is that the gradient at t=0 is 0, at t=1 is 1 and so forth. Instead GEKKO interprets it as the gradient at t=0 is 1, at t=1 is 2 etc.
Is there a reason why GEKKO does not use the gradient information at t=0?
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
n = 3
m = GEKKO(remote=False)
m.time = np.linspace(0,n,n+1) # [0, 1, 2 .. n]
y = m.Var(value=5)
p = m.Param(value=list(range(n+1))) # [0, 1, 2 .. n]
m.Equation(y.dt()==1*p)
m.options.IMODE=4
m.solve(disp=False)
plt.plot(m.time, y.value, '-x')
plt.xlabel('time'); plt.ylabel('y')
plt.show()


