Discrete State Space

Apps.DiscreteStateSpace History

Hide minor edits - Show changes to markup

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

  1. 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)

  1. 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 Gekko delay function.

Changed lines 59-60 from:
to:
June 12, 2019, at 10:09 PM by 10.37.73.127 -
Deleted line 63:
  1. Build GEKKO ARX model
June 12, 2019, at 10:09 PM by 10.37.73.127 -
Added lines 50-85:

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

  1. Create GEKKO model

m = GEKKO()

  1. 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)

  1. 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:
to:
November 17, 2018, at 07:29 AM by 174.148.88.122 -
Added lines 3-4:

Discrete State Space in GEKKO

Deleted lines 6-7:

Discrete State Space in GEKKO

Added lines 53-54:
November 17, 2018, at 07:27 AM by 174.148.88.122 -
Changed line 7 from:
to:
November 17, 2018, at 07:26 AM by 174.148.88.122 -
Added lines 1-52:

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 GEKKO

(: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?)

  1. Build GEKKO State Space model

m = GEKKO() x,y,u = m.state_space(A,B,C,D=None,discrete=True)

  1. customize names

mv0 = u[0]

  1. 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)

  1. 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:)