Constraint of optimization problem

5 次查看(过去 30 天)
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!!

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by