MATLAB: Adding a constraint in @confun constrained optimization

MATLABnonlinearoptimizationprogramming

Hello, I am struggling to add a second constraint in my optimization problem… My obj function is:
function f = objfun(X)
for i=1..18;
f=sum(exp-(10*X(i)); end
My 1st constraint is a non linear inequality :
function [c,ceq]=confun(X)
ceq = [];
c(1) =(-0.35*X(3)+0.35*X(9)+1.3333*X(10))^2-(0.3333*X(13)+0.3182*X(3)-0.6364*X(6)+0.3182*X(9)-X(17))^2-(0.015/2)^2;
My second constraint is also a non linear inequality which I can't code, here is what I want to verify:
% I need that all the values from 0 to the X(i) to be generated (the optimum X(i)), the condition 1 is verified.
Would you note that ub and lb and all the other entries for fmincon are known and my problem is only in the @confun
[x,fval]= fmincon(@objfun,x0,A,b,Aeq,beq,lb,ub,@confun,options)
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016,0.0016];
lb = [0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015,0.0015];
ub = [0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015,0.015];
options = optimoptions(@fmincon,'Algorithm','sqp');

Best Answer

Mathmematically you could define another constraint function
h(x) := sup { g(y): y in [0,x] }
then optimize your objective function:
argmin obj(x), with the constraint
h(x) <= somevalue
Now the problem becomes "how to compute h(x)?"
But that's is now on your side, and you might able to do it with specific formula of g(x).
You can of course use fmincon or such to compute h(x). But that might be costly. In this case the confun becomes (quick and dirty):
function [c,ceq]=confun(X)
lb = zeros(size(X));
ub = X;
afun = @(X) -0.35*X(3)+0.35*X(9)+1.3333*X(10);
bfun = @(X) 0.3333*X(13)+0.3182*X(3)-0.6364*X(6)+0.3182*X(9)-X(17);
g = @(X) (afun(X).^2-bfun(X).^2);
X = fmincon(@(X) -g(X), X, [], [], [], [], lb, ub); % Maximize g(X)
c = g(X)-(0.015/2)^2;
end
In some problems, it is sometime easier to find a formula for another function that is slightly greater than h(x):
H(x) >= h(x) for all x.
Note: "sup" is loosely speaking "max" for people who are not familiar with the notation.