Problem in solving an optimization problem
Afficher commentaires plus anciens
Hi, guys. This is my code for my optimization problem:
Objective=@Case;
p0 =[1,1,1,1,1];
A = [];
b = [];
Aeq = [];
beq = [];
lb=[1;1;1;1;1];
ub=[7;7;7;7;7];
nonlc=[];
%options = optimoptions('fmincon','Algorithm','interior-point','OptimalityTolerance',1e-20,'FunctionTolerance',1e-20,'StepTolerance',1e-20);
C = fmincon(Objective, p0, A, b, Aeq, beq, lb, ub,nonlc);
disp(C)
function E=Case(p)
moleWt=[28;56;84;112;140;168;156]; % mole weight C2,C4,...,C12,C11 [g/mol]
Woo_Datas_g = {[0.377984 0.696286 2.9244 4.43634 4.63528 4.83422 4.47613],[0.656499 1.69098 5.5504 11.1605 10.882 9.33024 10.6034],[0.69628 1.53183 4.43634 5.74934 6.78382 4.66446 6.98276],[0.497347 1.17374 2.68568 3.6008 2.9244 3.95889 4.07825],[0.497347 1.01459 1.57162 2.2878 2.88462 2.96419 2.48674]}; %Woo's data set for C2,C4,..,C12
F_G_out_mmol = [0.354 0.207 0.169 0.0724 0.0179 0.278 0.291]; %Gas outlet for each case[mmol/s]
t_max = 18000; %Reaction duration[s]
F_G_out_mol = zeros(1,7); %Gas outlet for each case at the end of the reaction[mol]
for j=1:7
F_G_out_mol(j) = F_G_out_mmol(j)*t_max*1e-3;
end
C4_mol = zeros(1,7); %C4H8 product(mol)
C6_mol = zeros(1,7); %C6H12 product(mol)
C8_mol = zeros(1,7); %C8H16 product(mol)
C10_mol = zeros(1,7); %C10H24 product(mol)
C12_mol = zeros(1,7); %C12H224 product(mol)
C4_g = cell2mat(Woo_Datas_g(1)); %C4H8 product(mol)
C6_g = cell2mat(Woo_Datas_g(2)); %C6H12 product(mol)
C8_g = cell2mat(Woo_Datas_g(3)); %C8H16 product(mol)
C10_g = cell2mat(Woo_Datas_g(4)); %C10H20 product(mol)
C12_g = cell2mat(Woo_Datas_g(5)); %C12H24 product(mol)
for j=1:7
C4_mol(j) = C4_g(j)./moleWt(2);
C6_mol(j) = C6_g(j)./moleWt(3);
C8_mol(j) = C8_g(j)./moleWt(4);
C10_mol(j) = C10_g(j)./moleWt(5);
C12_mol(j) = C12_g(j)./moleWt(6);
end
a = p(1);
b = p(2);
c = p(3);
d = p(4);
e = p(5);
E = (F_G_out_mol(1)-(C4_mol(round(a))+C6_mol(round(b))+C8_mol(round(c))+C10_mol(round(d))+C12_mol(round(e))))^2;
end
As you can see I want E as my objective function. The problem is my parameters for this problem. a,b,c,d,e should be positive integers and they can't be something like 3.5, 0.5 etc. They can only be 1,2,3,..,7. The problem is I can't figure out how define this in fmincon(). Any suggestions for solving this issue?? I have tried to use floor() and run before the parameters but fmincon() gave me a weird answer (1.99 for all the parameters). I also want E to be as minimum as possible. How can I adjust the error in fmincon()??
2 commentaires
Torsten
le 30 Avr 2024
I don't understand the sense of your code.
naiva saeedia
le 30 Avr 2024
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
