我最近開始嘗試使用 GEKKO 進(jìn)行移動地平線估計。我指定的操縱變量用于我的模型中的熱平衡方程,我在模型中遇到一些矩陣運算問題。示例代碼:from gekko import GEKKOimport numpy as np#creating a sample array of input valuesnt = 51u_meas = np.zeros(nt)u_meas[3:10] = 1.0u_meas[10:20] = 2.0u_meas[20:40] = 0.5u_meas[40:] = 3.0p = 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 MHEp.u = p.MV(value=u_meas)p.u.FSTATUS=1#parameters I'm looking to modulatep.K = p.FV(value=1, lb = 1, ub = 3) #gainp.tau = p.FV(value=5, lb = 1, ub = 10) #time constantp.x = [p.Intermediate(p.u)]#constants within the model that do not changeX_O2 = 0.5X_SiO2 = 0.25X_N2 = 0.1m_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 putmdot_c_i = np.concatenate(mdot_F_i, x, (other MV variables after))但是,現(xiàn)在 u 是 GEKKO 中指定的 MV,而不是設(shè)定值,我在 mdot_c_i 行收到一個錯誤,指出索引 0 處的數(shù)組有 1 維,而索引 1 處的數(shù)組有 2 維。我猜我必須將 mdot_c_i 指定為 Gekko 中的中間變量。我嘗試了幾種不同的變體,交替指定 mdot_c_i 作為中間值并嘗試僅使用 MV 的值;但是,我不斷收到該錯誤。有沒有人遇到類似的問題?
1 回答

aluckdog
TA貢獻(xiàn)1847條經(jīng)驗 獲得超7個贊
您可以使用np.append()而不是來解決此問題np.concatenate()。嘗試類似的東西:
mdot_c_i = np.append(mdot_F_i, p.u)
如果您想嘗試,這是一個最小且完整的示例。
import numpy as np
from gekko import GEKKO
m = GEKKO(remote=False)
x = m.Array(m.Var,3,lb=-10,ub=10)
y = m.Var(5,lb=-5,ub=5)
z = np.append(x,y)
m.Minimize(np.dot([1,1,-1,1],z))
m.solve(disp=False)
print([zi.value[0] for zi in z])
# solution: [-10.0, -10.0, 10.0, -5.0]
Gekko 變量需要存儲為對象,而不是數(shù)值。該錯誤可能是因為np.concatenate()函數(shù)試圖訪問 Gekko 操縱變量數(shù)據(jù)的長度p.u.value以連接這些值而不是連接p.u為對象。
添加回答
舉報
0/150
提交
取消