## Apps.DiscreteStateSpace History

June 12, 2019, at 10:17 PM by 10.37.73.127 -
Changed lines 54-88 from:
The discrete state space with 4 steps of delay is also possible with a time series (ARX) model using the '''delay''' function.

(:source lang=python:)
import numpy as np
from gekko import GEKKO
import matplotlib.pyplot as plt

# Create GEKKO model
m = GEKKO()

cv = m.Var()
mv = m.Param()

m.delay(mv,cv,4)

m.time = np.linspace(0,120,9)
mv.value = np.zeros(9)
mv.value[3:9] = 1
m.options.imode = 4
m.options.nodes = 2

m.solve() # (GUI=True)

# also create a Python plot
import matplotlib.pyplot as plt

plt.subplot(2,1,1)
plt.plot(m.time,mv.value,'r-',label=r'MV')
plt.legend()
plt.subplot(2,1,2)
plt.plot(m.time,cv.value,'b--',label=r'$CV$')
plt.legend()
plt.show()
(:sourceend:)

to:
The discrete state space with 4 steps of delay is also possible with a time series (ARX) model using the [[Apps/TimeDelay|Gekko delay function]].
Changed lines 59-60 from:
* [[Apps/LinearStateSpace|Continuous State Space]]
to:
* [[Apps/LinearStateSpace|Continuous State Space]]
* [[Apps/TimeDelay | Time Delay
]]
June 12, 2019, at 10:09 PM by 10.37.73.127 -
Deleted line 63:
# Build GEKKO ARX model
June 12, 2019, at 10:09 PM by 10.37.73.127 -
plt.legend()
plt.show()
(:sourceend:)

The discrete state space with 4 steps of delay is also possible with a time series (ARX) model using the '''delay''' function.

(:source lang=python:)
import numpy as np
from gekko import GEKKO
import matplotlib.pyplot as plt

# Create GEKKO model
m = GEKKO()

# Build GEKKO ARX model
cv = m.Var()
mv = m.Param()

m.delay(mv,cv,4)

m.time = np.linspace(0,120,9)
mv.value = np.zeros(9)
mv.value[3:9] = 1
m.options.imode = 4
m.options.nodes = 2

m.solve() # (GUI=True)

# also create a Python plot
import matplotlib.pyplot as plt

plt.subplot(2,1,1)
plt.plot(m.time,mv.value,'r-',label=r'MV')
plt.legend()
plt.subplot(2,1,2)
plt.plot(m.time,cv.value,'b--',label=r'$CV$')
Changed lines 54-57 from:
Also see [[Apps/LinearStateSpace|Continuous State Space]]
to:
Also see

* [[Apps/ARXTimeSeries | ARX Time Series]]
*
[[Apps/LinearStateSpace|Continuous State Space]]
November 17, 2018, at 07:29 AM by 174.148.88.122 -
!!!! Discrete State Space in [[https://gekko.readthedocs.io/en/latest/|GEKKO]]
Deleted lines 6-7:
!!!! Discrete State Space in [[https://gekko.readthedocs.io/en/latest/|GEKKO]]

Also see [[Apps/LinearStateSpace|Continuous State Space]]
November 17, 2018, at 07:27 AM by 174.148.88.122 -
Changed line 7 from:
Attach:input_delay_dss.png
to:
%width=550px%Attach:input_delay_dss.png
November 17, 2018, at 07:26 AM by 174.148.88.122 -
Model Predictive Control, or MPC, is an advanced method of process control that has been in use in the process industries such as chemical plants and oil refineries since the 1980s. Model predictive controllers rely on dynamic models of the process, most often linear empirical models obtained by system identification. APMonitor and GEKKO support continuous or discrete state space and autoregressive exogenous (ARX) input models.

The following is an example of implementing a discrete state space model for an input delay of 60 seconds. The sample time for this model is 15 seconds.

!!!! Discrete State Space in [[https://gekko.readthedocs.io/en/latest/|GEKKO]]

Attach:input_delay_dss.png

(:source lang=python:)
import numpy as np
from gekko import GEKKO

A = np.array([[0,0,0,0],
[1,0,0,0],
[0,1,0,0],
[0,0,1,0]])

B = np.array([[1],
[0],
[0],
[0]])

C = np.array([[0, 0, 0, 1]])

#%% Build GEKKO State Space model
m = GEKKO()
x,y,u = m.state_space(A,B,C,D=None,discrete=True)

# customize names
mv0 = u[0]
# CVs
cv0 = y[0]

m.time = np.linspace(0,120,9)
mv0.value = np.zeros(9)
mv0.value[3:9] = 1
m.options.imode = 4
m.options.nodes = 2

m.solve() # (GUI=True)

# also create a Python plot
import matplotlib.pyplot as plt

plt.subplot(2,1,1)
plt.plot(m.time,mv0.value,'r-',label=r'$u_0$ as MV')
plt.legend()
plt.subplot(2,1,2)
plt.plot(m.time,cv0.value,'b--',label=r'$y_0$')
plt.legend()
plt.show()
(:sourceend:)