问题已更新
以前,我的模型中的控制变量mP范围很广,导致求解器失败。在约翰博士的建议下,我尝试在目标函数中对 P进行对数缩放。当出现新错误并出现错误代码“位置 4”时:
*** Error in syntax of function string: Missing opening parenthesis
Position: 4
log_p-(log10(p))
?
以下是模型和求解器设置的一部分。在模型中,我有控制变量m.log_P,还有两个乘数变量m.u_1,m.u_2,其他变量P,Q,D_1,D_2是状态变量,小写字母都是常数。)
m.log_P = m.CV(value = np.log10(P_ini), name = 'log_P') # log_P for scaling
m.log_P.STATUS = 1 # add log_P to objective function, instead of P
m.log_P.FSTATUS = 1
m.P= m.SV(value = P_ini , name = 'P') # now original P is treated as a state variable
m.u_1 = m.MV(value=u_0, lb = 0, name = 'u_1')
m.u_2 = m.MV(value=u_0, lb = 0, name = 'u_2')
m.u_1.STATUS = 1
m.u_1.FSTATUS = 1
m.u_2.STATUS = 1
m.u_2.FSTATUS = 1
m.Equations([m.P.dt() == (a-mm-n) * m.P + b * m.Q - k_1 * m.D_1 * m.P - k_2 * m.D_2 * m.P,
m.Q.dt() == mm*m.P - b*m.Q,
m.D_1.dt() == m.u_1 - r_1 * m.D_1,
m.D_2.dt() == m.u_2 - r_2 * m.D_2,
m.log_P == m.log10(m.P)]) # first 4 equations defined by model. The last equation take logrithmic value of P.
m.options.IMODE = 6
m.options.SOLVER = 3
m.options.CV_TYPE = 2 # l2-norm
m.options.EV_TYPE = 2
m.solver_options = ['linear_solver mumps',\
'mu_strategy adaptive']
在这里,我使用 '''m.options.CV_TYPE = 2 # l2-norm''' 设置了二次误差项。
for i in range(len(t)-1):
ts = [t[i],t[i+1]]
y = odeint(chemo_model, x0, ts, args = (u_infu1[i],u_infu2[i])) # 'chemo_model' is a model function
P_cell[i+1] = y[-1][0]
Q_cell[i+1] = y[-1][1]
D1_drug[i+1] = y[-1][2]
D2_drug[i+1] = y[-1][3]
''' update '''
m.log_P.MEAS = np.log10(P_cell[i+1]) # insert measurement
m.log_P.SP = np.log10(P_sp[i+1]) # P_sp is predefined trajectory points
''' solve MPC '''
m.solve(disp=True)
一个错误代码为“位置 5”的在线案例是由于该等式中缺少“dt()”。看起来很相似,但不是我的情况。谁可以帮我这个事?提前致谢!!