from gekko import GEKKO t_data = [0, 0.1, 0.2, 0.4, 0.8, 1] x_data = [2.0, 1.6, 1.2, 0.7, 0.3, 0.15] m = GEKKO(remote=False) m.time = t_data x = m.CV(value=x_data); x.FSTATUS = 1 # fit to measurement k = m.FV(); k.STATUS = 1 # adjustable parameter m.Equation(x.dt()== -k * x) # differential equation m.options.IMODE = 5 # dynamic estimation m.options.NODES = 5 # collocation nodes m.solve(disp=False) # display solver output k = k.value[0] import numpy as np import matplotlib.pyplot as plt # plot solution plt.plot(m.time,x.value,'bo',\ label='Predicted (k='+str(np.round(k,2))+')') plt.plot(m.time,x_data,'rx',label='Measured') # plot exact solution t = np.linspace(0,1); xe = 2*np.exp(-k*t) plt.plot(t,xe,'k:',label='Exact Solution') plt.legend() plt.xlabel('Time'), plt.ylabel('Value') plt.show()