Info

This question is closed. Reopen it to edit or answer.

solving constrait optimization using external varibales

1 view (last 30 days)
Hi i am trying to solve constarint optimization usinf for loop, Actually i trying to maximize x with this constrains but olsa i have external variable that has some interval. Therefore i tyr to determined them using for loop but it is not working . What am i doing wrong?
for g=0:.1:0.5 % start at 0, step by 0.1 up to 1
for t = 0.5:.1:1
if g +t <= 0.5
fun = @(x)-((1-x)+ log(x)+log(g)+0*t);
lb = 0;
ub = 1;
A = [];
b = [];
Aeq = [];
beq = [];
x0 = (lb+ub)/2;
nonlcon = [];
options = optimoptions('fmincon','Algorithm','interior-point',...
'OptimalityTolerance',1e-20, ...
'StepTolerance', 1e-20, ...
'ConstraintTolerance', 1e-20, ...
'Display', 'iter' );
[x, fval] = fmincon(fun, x0, A, b, Aeq, beq, lb, ub, nonlcon, options);
disp(x)
disp(fval)
else
fprintf('\nThe number of people who agree is\n',x);
end
end
  1 Comment
Sinem Senel
Sinem Senel on 11 Aug 2020
I use x as a g2 in my code and i am trying to maximize x. For g1 i use g and it should be 0=<g1=< 0.5 and fot t2 it should be 0.5=<t2=<1 . But they are not my constrains for optimization they are my intervals.

Answers (0)

Community Treasure Hunt

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

Start Hunting!