FMINCON is not providing feasible answers
1 view (last 30 days)
Show older comments
EDIT: a0 = 1
% M-file for Constraint function
function [c,ceq] = constrain(X)
%---------------------------
% Variables:
a1=X(1); % alpha 1
a2=X(2); % alpha 2
a3=X(3); % alpha 3
a4=X(4); % alpha 4
a5=X(5); % alpha 5
%----------------------------
% Inequality Constraint
c =[a1-1;a2-a1;a3-a2;a4-a3;a5-a4];
% Equality Constraint
ceq = [];
end
% M-file for Objective Function
function Thetatotal = objectivef(X)
% Contois Model Given Parameters:
B=0.482; % g Substrate/g cells
Y=0.212; % g cells/g substrate
k=B*Y; %dimensionless constant
%---------------------------
% Variables:
a1=X(1); % alpha 1
a2=X(2); % alpha 2
a3=X(3); % alpha 3
a4=X(4); % alpha 4
a5=X(5); % alpha 5
S0=X(6); % Inlet Substrate Concentration
cell=X(7); % Biomass into Reactor 1
Theta1=(k*(1-a1))/(a1);
Theta2=(k*(a1-a2))/(a2);
Theta3=(k*(a2-a3))/(a3);
Theta4=(k*(a3-a4))/(a4);
Theta5=(k*(a4-a5))/(a5);
%Total Dimensionless Residence Time
Thetatotal = Theta1+Theta2+Theta3+Theta4+Theta5;
end
%M-file for calling function
clc
clear
%Initial Guess
x0= [0.5;0.5;0.5;0.5;0.5;4;0];
%Variable bounds
lb =[0.01;0.01;0.01;0.01;0.01;2;0];
ub =[0.99;0.99;0.99;0.99;0.99;8;0];
%Linear constraints
A=[];
b=[];
Aeq=[];
Beq=[];
%nonlinera constraints
nonlcon=@constrain;
%objectivefunction
objective=@objectivef;
%options = optimoptions('fmincon');
options = optimoptions('fmincon','Display','iter','Algorithm','interior-point','Plotfcn',@optimplotfval,'FunctionTolerance',1e-12);
%options = optimoptions(options,'Algorithm','sqp');
[x,fvalue,exitflag] = fmincon(objective,x0,A,b,Aeq,Beq,lb,ub,nonlcon,options);
0 Comments
Answers (1)
Alan Weiss
on 25 Apr 2021
Your nonlinear constraint functions all look linear to me. I suggest that you remove the nonlinear constraints from the problem and instead provide appropriate linear constraint matrices.
After that, if you still have problems satisfying the constraints, then I suggest that you consult the documentation section Investigate Linear Infeasibilities.
Alan Weiss
MATLAB mathematical toolbox documentation
1 Comment
Matt J
on 25 Apr 2021
Moreover, it looks like the problem could be written in terms of Theta(i) rather than a(i), in which case, the whole thing becaomes a linear program and can be solved with linprog.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!