can fmincon handle dynamic constraints ?

To be more clear
function A = Constraints_ineql1(Gd)
[T_h_ex_in,T_h_out,~,~,T_c_in,~,~,~,~,Rp,~,...
~,alpha,Mh,kappa_c,kappa_h,M_h,M_c2,~,m_h,...
m_CO2_O2_mix,y,y_CO2_O2,c2_stream,Mc,Phase_C2,Phase_h,P2,P,~,T2,Tcout,...
~,~,h_stream,Lc_k,~,~,~,~,Dc,Dh,A_xc,...
Fluid_C2,Fluid_h,dz,m2_h,t1,t2,t3,te] = Inputs_opti;
Lx = Gd(1);
Ly = Gd(2);
Lz = Gd(3);
Nb_element = floor(Lz / dz);
N = Nb_element + 1;
Nc = round((Lx + t3 - 2 * t1) / (Dc + t3)); % Number of channels per plate
Np = round(Ly / (Dc / 2 + t2)); % Number of plates
Plates_g = Nc * Np; % total number of channels
P_h = zeros(1, Nb_element + 1);
P_c = zeros(1, Nb_element + 1);
P_h(Nb_element+1) = P(1);
P_c(1) = P2(2);
T_h = zeros(1, Nb_element + 1);
T_c = zeros(1, Nb_element + 1);
[T_h,Twh, T_c] = T_func(Plates_g, Nb_element,T_h_out,Tcout,T_c_in,te, Rp, P, P2, T2, T_h_ex_in, Phase_h, Fluid_h, A_xc, m2_h, Dh, Lc_k, y, h_stream, y_CO2_O2, c2_stream, Phase_C2, Fluid_C2, m_CO2_O2_mix, M_h, M_c2, alpha, Mh, Mc, kappa_h, kappa_c);
N = Nb_element + 1;
for i = 1:Nb_element
px1 = Properties.Pressure_drop2(y, h_stream, T_h(Nb_element-i+1), P_h(Nb_element-i+1), Phase_h, Fluid_h, Nhp, A_xc, m_h, Dh, dz, alpha, Mh, kappa_h);
P_h(Nb_element-i+1) = P_h(Nb_element-i+2) - px1;
if P_h(Nb_element-i+1) < 0
break;
end
px = Properties.Pressure_drop2(y_CO2_O2, c2_stream, T_c(i), P_c(i), Phase_C2, Fluid_C2, Ncp, A_xc, m_CO2_O2_mix, Dh, dz, alpha, Mc, kappa_c);
P_c(i+1) = P_c(i) - px;
end
A = [1.8e5 - sum(P_h(2:N)-P_h(1:N-1)), 1.8e5 - sum(P_c(1:N-1)-P_c(2:N)),0;1.8e5 - sum(P_h(2:N)-P_h(1:N-1)), 1.8e5 - sum(P_c(1:N-1)-P_c(2:N)),0; -2.5,0,1];
%ceq = [];
options = optimoptions('fmincon', 'Display', 'iter');
[G, fval] = fmincon(@Opti_MHX, Gd, A,b, [], [], lb,ub,options); %fmincon(
function
M_HX = Opti_MHX(Gd)
%%%expression%%%
end
The A keeps on changing as the guess values Gd will change, the solver needs to chk this constraint first and then go to 'Opti_MHX' .
I just want to know how we can achieve this as we do in scipy minimize 'trust-constr' algo.
Thanks

 Accepted Answer

Matt J
Matt J on 9 Feb 2024
Edited: Matt J on 9 Feb 2024
By "dynamic constraints" it sounds like you mean nonlinear constraints. If so, yes, that is what the nonlcon argument is for,
However, the constraints are supposed to be continuous and differentiable, so your round() operations will probably invalidate that.

1 Comment

Thanks for considering. I'll have a look at that :)

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019a

Asked:

Jai
on 9 Feb 2024

Edited:

on 9 Feb 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!