我最近开始尝试使用 GEKKO 进行移动地平线估计。我指定的操纵变量用于我的模型中的热平衡方程,我在模型中遇到一些矩阵运算问题。
示例代码:
from gekko import GEKKO
import numpy as np
#creating a sample array of input values
nt = 51
u_meas = np.zeros(nt)
u_meas[3:10] = 1.0
u_meas[10:20] = 2.0
u_meas[20:40] = 0.5
u_meas[40:] = 3.0
p = GEKKO(remote=False)
p.time = np.linspace(0,10,nt)
n = 1 #process model order
#designating u as my input, and that I'm going to be using these measurements to estimate my parameters with MHE
p.u = p.MV(value=u_meas)
p.u.FSTATUS=1
#parameters I'm looking to modulate
p.K = p.FV(value=1, lb = 1, ub = 3) #gain
p.tau = p.FV(value=5, lb = 1, ub = 10) #time constant
p.x = [p.Intermediate(p.u)]
#constants within the model that do not change
X_O2 = 0.5
X_SiO2 = 0.25
X_N2 = 0.1
m_feed = 100
#creating an array with my feed separated into components. This creates a 1D array with the individual feed streams of my components.
mdot_F_i = (np.tile(m_feed,3)*np.array([X_O2, X_SiO2, X_N2])
#at this point, I want to add my MV values to the end of my component feed array for later heat and mass balance equations. Normally, in my previous model without MHE, I would put
mdot_c_i = np.concatenate(mdot_F_i, x, (other MV variables after))
但是,现在 u 是 GEKKO 中指定的 MV,而不是设定值,我在 mdot_c_i 行收到一个错误,指出索引 0 处的数组有 1 维,而索引 1 处的数组有 2 维。
我猜我必须将 mdot_c_i 指定为 Gekko 中的中间变量。我尝试了几种不同的变体,交替指定 mdot_c_i 作为中间值并尝试仅使用 MV 的值;但是,我不断收到该错误。
有没有人遇到类似的问题?
aluckdog
相关分类