Tuesday, 15 March 2011

How to add constraints in fmincon in MATLAB -



How to add constraints in fmincon in MATLAB -

i trying utilize fmincon , have problem constraints. constraints alter in case of input , in 1 case have 9 , in case have 18 constraints. way define constraint below:

if input(1+(i-1)*3600*tpred/nu/60,3) == 0 %tamb ineq1(i,1)=(-y1(i,1)+16); ineq1(i,2)=(-y2(i,1)+16); ineq1(i,3)=(-y3(i,1)+16); %tamb+1 ineq1(i,4)=(-y12(i,1)+16); ineq1(i,5)=(-y22(i,1)+16); ineq1(i,6)=(-y32(i,1)+16); %tamb-1 ineq1(i,7)=(-y13(i,1)+16); ineq1(i,8)=(-y23(i,1)+16); ineq1(i,9)=(-y33(i,1)+16); else %tamb ineq1(i,1)=(y1(i,1)-25); ineq1(i,2)=(-y1(i,1)+21); eq1(i,1)=(y1(i,1)-23)^2; ineq1(i,3)=(y2(i,1)-25); ineq1(i,4)=(-y2(i,1)+21); eq1(i,2)=(y2(i,1)-23)^2; ineq1(i,5)=(y3(i,1)-25); ineq1(i,6)=(-y3(i,1)+21); eq1(i,3)=(y3(i,1)-23)^2; %tamb+1 ineq1(i,7)=(y12(i,1)-25); ineq1(i,8)=(-y12(i,1)+21); eq1(i,4)=(y12(i,1)-23)^2; ineq1(i,9)=(y22(i,1)-25); ineq1(i,10)=(-y22(i,1)+21); eq1(i,5)=(y22(i,1)-23)^2; ineq1(i,11)=(y32(i,1)-25); ineq1(i,12)=(-y32(i,1)+21); eq1(i,6)=(y32(i,1)-23)^2; %tamb-1 ineq1(i,13)=(y13(i,1)-25); ineq1(i,14)=(-y13(i,1)+21); eq1(i,7)=(y13(i,1)-23)^2; ineq1(i,15)=(y23(i,1)-25); ineq1(i,16)=(-y23(i,1)+21); eq1(i,8)=(y23(i,1)-23)^2; ineq1(i,17)=(y33(i,1)-25); ineq1(i,18)=(-y33(i,1)+21); eq1(i,9)=(y33(i,1)-23)^2; end

i run step step , goes in if-condition , calculate constraints in both cases. don't know why fmincon can't satisfy constraints. know model can satisfy them if inputs alter fmincon without error on waning can't satisfy them. check inequality constraints positive must me negative.

am define constraints wrong?

with best regards,

during minimization process fmincon assumes size of constraints vector doesn't change. because in order minimization has compute gradient of cost function, gradient of constraints, , can't see of elements disappear 1 function phone call another.

maybe possibility redefine problem constraints vector set maximum size (in case 18), , set -1 latest components when half needed. however, notice solution loose of regularity of problem.

matlab constraints mathematical-optimization

No comments:

Post a Comment