fmincon output is converging to infeasible point

1 view (last 30 days)
I am getting an output that is correctly following lower bound and upper bound but is not satisfying the non-linear constraint. Those values are not useful for me at all. Do let me know if you require the entire code.
m = 20
lb = zeros(m,2);
ub = ones(m,2);
Y = 0.5.*ub;
[xopt,fval] = fmincon(@getCost,Y,[],[],[],[],lb,ub,@nlcon)
function [x,n,N,S] = getCost(Y)
..............
.........
end
%Constraint function
function [c, ceq] = nlcon(Y)
[~,~,c,~] = getCost(Y);
[~,~,~,ceq] = getCost(Y);
c = ceq;
end

Answers (1)

Alan Weiss
Alan Weiss on 29 Jul 2020
While I don't understand your listed code at all, perhaps you will be able to solve your problem using some ideas from the documentaton on what to do when the solver converges to an infeasible point.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
Harshvardhan Tandon
Harshvardhan Tandon on 4 Aug 2020
I did try what you recommended but fmincon was still converging to an infeasible point. My program is quite complex to be solved easily. I am trying to use different/ or modify the non-linear constraints and get convergence to a feasible point.
%Constraint function
function [c, ceq] = nlcon(Y)
[~,~,c,~] = getCost(Y);
[~,~,~,ceq] = getCost(Y);
c = ceq;
end
%%%I made it to this%%%
%Constraint function
function [c, ceq] = nlcon(Y)
[~,~,c,~] = getCost(Y);
[~,~,~,ceq] = getCost(Y);
c == ceq;
end
If you could give an idea of how fmincon reaches its value or how it reacts to when i put a '==' operator. That would be helpful.
Alan Weiss
Alan Weiss on 4 Aug 2020
As I said, I don't understand your code at all, so I don't know what you are trying to do or how to advise you. In particular, I don't know what you are attempting to do with the 'c = ceq' or 'c == ceq' calls. To me, they are equally nonsensical, but I'm sure that you have a reason for including them. I would have simply given
function [c, ceq] = nlcon(Y)
[~,~,c,ceq] = getCost(Y);
end
but I don't know what any of these lines of code mean.
I suggest that you try using the debugger to see what MATLAB is doing.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!