## Constraint of optimization problem

### Brenda Aldaz (view profile)

on 11 Jul 2019
Latest activity Commented on by Matt J

on 12 Jul 2019

### Matt J (view profile)

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!!

on 11 Jul 2019
Edited by Matt J

### Matt J (view profile)

on 11 Jul 2019

It's the wrong solver. You would need to use ga() for a problem like that.

Brenda Aldaz

### Brenda Aldaz (view profile)

on 12 Jul 2019
Thanks!!
That function works very well!!
Matt J

on 12 Jul 2019