I have spent some time to solve this issue but still cannot find the solution. Basically, I have a parameter, say k, as a piecewise linear function of time, for example:

And so we can write k as an array vs time - k(t). The thing is I have an ODE system containing k, let say a simple one like: dx/dt = k(t), and I would like GEKKO to linear interpolate k from the above piecewise linear function during the ODE integration. This is basically a simulation problem.
After that, I will look at varying k(t) (i.e., optimal control using a piecewise linear control) to meet some objective function.
Is there any suggestion on how to do these things properly in GEKKO?
Thank you
I tried np.interp, but it did not accept GK variables. I also tried to write my own code for linear interpolation, but could not figure out how to extract the time point (m.time) during the integration.
Create the linear interpolation before creating the
m.Param().Here is an example solving at 0.1 time intervals from 0 to 1.
If there is interpolation error (as shown in the figure above), increase the number of time points or include the
kttime points inm.time.If
kis calculated, setk=m.MV()withk.STATUS=1for linear interpolation of the interior collocation time points. There is a global optionm.options.MV_TYPEfor either zero-order hold or first-order hold (linear interpolation).