我有一个具有二次输入(操纵变量,[MV])的非线性系统。为了使用 GEKKO 对该系统进行 MPC 仿真,我定义了以下函数来处理二次输入:
def NTVin(T, u):
n = T.shape[0]
Tntv = zeros(n)
u2 = zeros_like(u, dtype = float64)
for i in range(len(u2)):
u2[i] = copy(u[i].VALUE)
for i in range(n):
Tntv[i] = dot(dot(u2, T[i,:,:]), u2)
return Tntv
然后我定义我的系统方程如下:
from pylab import*
dt = .02 # sec = 20ms
m = GEKKO(remote = True)
ntg = int(tf/dt) + 1
m.time = linspace(0., tf, ntg)
m.options.CV_TYPE = 2 # 2 = squared error
x = m.Array(m.SV, Nnew, value = 0.)
y = m.Array(m.CV, Mm, value = 0.)
unb = m.Array(m.MV, B.shape[1], lb = 5.e5, ub = 2.25e6)
untv = m.Array(m.MV, Bntv.shape[1], value = 0.)
tau_sp = 3.e-2
for i in range(Bntv.shape[1]):
untv[i].value = ic[i]
untv[i].STATUS = 1
for i in range(B.shape[1]):
unb[i].value = 0.
unb[i].STATUS = 1
unb[i].DCOST = 0.
unb[i].COST = 0.
for i in range(N):
x[i].value = ans0[i]
for i in range(Nnew):
m.Equation(x[i].dt() == dot(A[i,:], x) + Bint[i] + dot(B[i,:], unb) - dot(Mnew[i,:], NTVin(Bntv, untv)))
for i in range(Mm):
m.Equation(y[i] == dot(Phim[i,:], x))
y[i].value = dot(Phim[i,:], ans0)
y[i].STATUS = 1
y[i].TR_INIT = 1
y[i].SP = omegaR0[i]
y[i].TAU = tau_sp
m.options.IMODE = 6
m.options.NODES = 2
m.solve(disp = True, GUI = False)
模拟运行,但 GEKKO 永远不会改变 MV untv
(无论为 设置什么untv[i].value
,都保持在模拟的那个值),而线性 MVunb
在模拟期间进行了优化,并且会随时间变化。我怀疑我的功能NTVin
应该受到指责(特别是在这一行:)u2[i] = copy(u[i].VALUE
。那么我的问题是,GEKKO 可以处理非线性 MV,如果可以,在声明系统方程时有没有办法处理这个二次输入?