Constraint condition and IF statement
1 view (last 30 days)
Show older comments
hi all I need help to write a constraint condition used if statement as seen below i have error when put (if) after Ceq . how write it and sovled the error?
function [c,ceq]=bb12(x)
.
.
.
ceq=if (((0.025*(x(1)^2)*(1-exp((-1.025*x(3))/x(1))))/(((x(2)^2)/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2))))))) <=(0.5*x(7)-0.025)
x(9)=((13.91*((x(1)*(x(2)^2))/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2))))*(0.5*x(7)+((((0.025*(x(1)^2)*(1-exp((-1.025*x(3))/x(1))))/(((x(2)^2)/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2))))))))-0.025))/(0.9*1000*275*(x(7)-0.05)));
else if (((0.025*(x(1)^2)*(1-exp((-1.025*x(3))/x(1))))/(((x(2)^2)/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2))))))) > (0.5*x(7)-0.025)
x(9)=(((13.91*((x(1)*(x(2)^2))/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2)))))/0.9)+(0.85*35*1000*x(2)*0.411*(x(7)-0.025))+(x(10)*((600083*(0.411*(x(7)-0.025)-(0.85*0.025))/(0.411*(x(7)-0.025)))-(849.77*35))));
else
x(9)=(0.0025*x(7));
end
end;
Error:Illegal use of reserved keyword "if".
2 Comments
James Tursa
on 8 Jul 2015
What are c and ceq? They are returned from your function but it is not clear what they are supposed to be.
Accepted Answer
Torsten
on 9 Jul 2015
function [c,ceq]=bb12(x)
a=(((0.025*(x(1)^2)*(1-exp((-1.025*x(3))/x(1))))/(((x(2)^2)/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2)))))))
if a<=(0.5*x(7)-0.025)
ceq=x(9)-((13.91*((x(1)*(x(2)^2))/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2))))*(0.5*x(7)+((((0.025*(x(1)^2)*(1-exp((-1.025*x(3))/x(1))))/(((x(2)^2)/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2))))))))-0.025))/(0.9*1000*275*(x(7)-0.05)));
else if a > (0.5*x(7)-0.025)
ceq=x(9)-(((13.91*((x(1)*(x(2)^2))/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2)))))/0.9)+(0.85*35*1000*x(2)*0.411*(x(7)-0.025))+(x(10)*((600083*(0.411*(x(7)-0.025)-(0.85*0.025))/(0.411*(x(7)-0.025)))-(849.77*35))));
end
Best wishes
Torsten.
More Answers (1)
Azzi Abdelmalek
on 8 Jul 2015
Edited: Azzi Abdelmalek
on 8 Jul 2015
Remove ceq= from your If expression
a=(((0.025*(x(1)^2)*(1-exp((-1.025*x(3))/x(1))))/(((x(2)^2)/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2)))))))
if a<=(0.5*x(7)-0.025)
x(9)=((13.91*((x(1)*(x(2)^2))/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2))))*(0.5*x(7)+((((0.025*(x(1)^2)*(1-exp((-1.025*x(3))/x(1))))/(((x(2)^2)/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2))))))))-0.025))/(0.9*1000*275*(x(7)-0.05)));
else if a > (0.5*x(7)-0.025)
x(9)=(((13.91*((x(1)*(x(2)^2))/(x(1)+x(2)))*(1-exp((-0.513*x(3)*(x(1)+x(2)))/(x(1)*x(2)))))/0.9)+(0.85*35*1000*x(2)*0.411*(x(7)-0.025))+(x(10)*((600083*(0.411*(x(7)-0.025)-(0.85*0.025))/(0.411*(x(7)-0.025)))-(849.77*35))));
else
x(9)=(0.0025*x(7));
end
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!