Reputation: 345
I have an optimization problem which is solved with fmincon
. In this problem I have a constraint that says every element of the vector L
must be less than or equal to 1. So basicaly I can add this constraint like this
C=max(L)-1 ; % C(X)<0
But now I want to write the above constraint with out using Max
function.
Any idea?
Upvotes: 0
Views: 82
Reputation:
every element of the vector L must be less than or equal to 1.
This should be written as a set of constraints, not a single constraint. Artificially bundling the constraints L(1)<=1, L(2)<=1, ... into one constraint is just going to cause more pain to the solver.
Example with linear constraints: minimizing -x(1)*x(2) subject to x(1)<=1 and x(2)<=1
fmincon(@(x) -x(1)*x(2), [0.5; 0.5], [1 0; 0 1], [1; 1])
(Here the simple form fmincon(fun,x0,A,b)
is used.)
Example with nonlinear constraints: minimizing -x(1)*x(2) subject to x(1)^2+x(2)^2<=1 and x(1)+x(2)^2<=1
fmincon(@(x) -x(1)*x(2), [0.1; 0.1], [],[],[],[],[],[], @(x) deal([x(1)^2+x(2)^2-1; x(1)+x(2)^2-1],[]))
Here the form fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
is used, where nonlcon returns multiple inequality constraints and equality constraints. Specifically, the first output of the nonlinear constraint function is [x(1)^2+x(2)^2-1; x(1)+x(2)^2-1]
; both of these are required to be <=0. The second output, nonlinear equality constraints, is an empty array.
Upvotes: 1