I am trying to use fmincon and I have problem in constraint.
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to use fmincon and I have problem in constraint. my constraint change in the case of input and in one case I have 9 and in another case I have 18 constraints. The way that I define my constraint is like 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 it step by step and it goes in if condition and calculate constraints in both cases. But I don't know why my fmincon can't satisfy the constraints? I know my model can satisfy them if inputs change but fmincon without any error on waning just can't satisfy them. Also as I check my inequality constraints are positive which must me negative.
Am I define my constraints wrong?
With best regards,
0 个评论
采纳的回答
Matt J
2014-6-23
编辑:Matt J
2014-6-23
my constraint change in the case of input and in one case I have 9 and in another case I have 18 constraints.
We don't know what this "input" means. Your code doesn't show which quantities are the unknown variables and which are just constants. You cannot make the number of constraints a function of the unknown variables, if that's what you mean. They are not allowed to evolve throughout the optimization.
but fmincon without any error on waning just can't satisfy them.
The additional output arguments from fmincon, (e.g, exitflag, output) always tells you whether constraints were satisfied and other info about the termination condition. A summary should also have been printed to the screen, unless you suppressed that.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!