Constraint of optimization problem

5 views (last 30 days)
Brenda Aldaz
Brenda Aldaz on 11 Jul 2019
Commented: Matt J on 12 Jul 2019
Hi!
I am really desperate and I wish you can help me
I need to optimize (maximize) the function:
(a1*w1)+(a2*w2)+(a3*w3)+(a4*w4)+(a5*w5)+(a6*w6)
where the variables are w1, w2, w3, w4, w5 y w5 and a1, a2, a3, a4, a5 and a6 are constants
The Constraints are:
prob.Constraints.cons1 = w1+w2+w3+w4+w5+w6 == 1;
prob.Constraints.cons2 = w1>= 0;
prob.Constraints.cons3 = w2>= 0;
prob.Constraints.cons4 = w3>= 0;
prob.Constraints.cons5 = w4>= 0;
prob.Constraints.cons6 = w5>= 0;
prob.Constraints.cons7 = w6>= 0;
y=sort((w1*vector(:,1))+(w2*vector(:,2))+(w3*vector(:,3))+(w4*vector(:,4))+(w5*vector(:,5))+(w6*vector(:,6)));
prom=mean(y(1:r,:));
y1=prom<=0.0131;
prob.Constraints.cons8 = y1;
where vector is a 1000-by-1 vector and r=100
The problem is that the sort function doesn't work with optimization variable
Do you know if it is possible to optimize with coinstraints like that?
Thanks!!

Accepted Answer

Matt J
Matt J on 11 Jul 2019
Edited: Matt J on 11 Jul 2019
It's the wrong solver. You would need to use ga() for a problem like that.
  2 Comments
Brenda Aldaz
Brenda Aldaz on 12 Jul 2019
Thanks!!
That function works very well!!
Matt J
Matt J on 12 Jul 2019
You're welcome, but since it worked, please Accept-click the answer.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!