fmincon and constraints inherant to the function
5 views (last 30 days)
Show older comments
Good evening,
I am currently stuck on a problem and till now couldn't find a solution to it.
I'm using fmincon to find the minimum of a cost function forecastSOC, with variables x(1) and x(2):
[z1,z2,z3,z4] = fmincon(@(x)forecastSOC(x,aConst),x,A,b,Aeq,beq,lb,ub);
Now, what I would like to do is add a constraint to a variable y (vector) that is calculated in my function (y depends x(1) and x(2)). For example let's say the values of y should always stay between 60 and 90.
I've tried to included y(x(1),x(2)) as a decision parameter, then add upper and lower boundaries; I also tried non linear constraints.. with no success.
I hope very much that you can help me. Thank you
kind regards
0 Comments
Accepted Answer
Matt J
on 29 May 2014
I also tried non linear constraints
If y is a nonlinear (and twice differentiable) function of x, there's no obvious reason this wouldn't have worked.
3 Comments
Matt J
on 29 May 2014
Edited: Matt J
on 29 May 2014
I don't fully understand the idea of "adding y as variables". Since y depends on the other variables the only way you can recast it as an independent variable in the optimization is to add nonlinear equality constraints,
x(3:27)=y(x(1),x(2))
which are again not differentiable because y() is not differentiable.
Incidentally, the constraints are not your only problem. Since y() is an intermediate quantity in the computation of your objective function, that will be non-differentiable as well. I think you need to find a better formulation of y() than one which uses ceil() operations.
John D'Errico
on 29 May 2014
Fmincon does NOT handle problems that are not differentiable. In fact, if you used ceil, then it is not even continuous.
More Answers (1)
Alan Weiss
on 29 May 2014
It depends on how you tried to include the nonlinear constraints. I believe the way to do so successfully is as follows:
function [c,ceq] = constrfun(x)
ceq = [];
% Put your code for calculating y here
c(1) = 60 - y; % ensures y >= 60
c(2) = y - 90; % ensures y <= 90
Be sure to pass @constrfun after the ub argument to fmincon.
Alan Weiss
MATLAB mathematical toolbox documentation
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!