# DAE formulation
u = ca.SX.sym("u", nu) # Control
x = ca.SX.sym("x", nx ) # Differential states
y = ca.SX.sym("y", ny) #Algebraic states
T_Amb = ca.SX.sym("T_Amb")
LOAD_H = ca.SX.sym("LOAD_H")
dxdt = ODE ..
f_z = Algebraic equations...
daepar = ca.vertcat(u,T_Amb,LOAD_H)
dae = {'x':x, 'z':y, 'p':daepar, 'ode':dxdt, 'alg':f_z}
I = ca.integrator('I','collocation', dae)
f = ca.Function('f', [x, y, daepar], [dxdt,f_z], ['x', 'z', 'p'], ['ode','alg'])
fz = ca.Function('fz', [y, x, daepar], [f_z], ['z','x', 'p'], ['alg'])
N = time horizon
# Optimal control problem formulation
X = [ ca.MX.sym("x", nx) for i in range(N+1)]
U = [ ca.MX.sym("u", nu) for i in range(N)]
T_AMB = ca.MX.sym("T_AMB",N)
LOAD_H_P = ca.MX.sym("Pth_LOAD_H_P ", N)
...
for k in range(N):
r = I(x0=X[k],z0=z0,p=ca.vertcat(U[k],T_AMB[k],Pth_LOAD_H_P[k]))
p = ca.vertcat(T_AMB,LOAD_H_P)
p_track = ca.vertcat(T_Amb_vals,Load_vals)
nlp = {"x": ca.veccat(*V), "p": p, "f": J, "g": gaps}
solver = ca.nlpsol('solver','ipopt',nlp,opts)
solution = solver(x0 = ca.vertcat(*V_init), p = p_track, lbx = lbw, ubx = ubw, lbg = g_min, ubg = g_max)