Why do I get the error "illegal use of reserved keybord "while""?

11 次查看(过去 30 天)
I need to run the following code, where the function @opt is already defined. When I try to run it, I get the error "illegal use of reserved keybord "while"". Actually, the "end" that is not well located is not recognized by matlab as an end (it appears written in black instead of blue). Why does this happen and how can I fix it? Thanks a lot in advance.
if true
% E3=zeros(50,50,4);
rn=sqrt(2*(1-cos(2*pi/n)));
for k=1:50
k
for j=1:51-k
alfa=k/52;
beta=j/52;
gamma=1-alfa-beta;
alfagorro=alfa/(1-beta);
gammagorro=gamma/(1-beta);
H=1;
Hgorro=H;
F=(n-1-H)/2;
[f,c]=fmincon(@opt,[1 1 1],[],[],[],[],[0 0 0],[],[],options);
costoviaH=pe/(2*f(2))+pv*[2*T0+t*(a*alfa*Y/(H*n*f(2))+b*alfagorro*Y/(H*n*f(2))+a*gamma*Y/(2*n*(n-1)*f(2))+b*gammagorro*Y/(2*n*(n-1)*f(2)))];
costoviaF=pe/(2*f(2))+pv*[F*rn*T0+(2*(F-1)+1/2)*t*(a*gamma*F*Y/(n*(n-1)*f(3))+b*gammagorro*F*Y/(n*(n-1)*f(3)));
while costoviaH<costoviaF && H<n-1
H=H+2;
Hgorro=H;
[f,c]=fmincon(@opt,[1 1 1],[],[],[],[],[0 0 0],[],[],options);
costoviaH=pe/(2*f(2))+pv*[2*T0+t*(a*alfa*Y/(H*n*f(2))+b*alfagorro*Y/(H*n*f(2))+a*gamma*Y/(2*n*(n-1)*f(2))+b*gammagorro*Y/(2*n*(n-1)*f(2)))];
F=(n-1-H)/2;
costoviaF=pe/(2*f(2))+pv*[F*rn*T0+(2*(F-1)+1/2)*t*(a*gamma*F*Y/(n*(n-1)*f(3))+b*gammagorro*F*Y/(n*(n-1)*f(3)));
end
for L=1:3
E3(k,j,L)=f(L);
end
E3(k,j,4)=c;
end
end
end
  1 个评论
Image Analyst
Image Analyst 2014-3-28
You forgot to paste the error message. "keybord" is not even an English word, and it's not in your code either so I know that's not the real error message. Please paste in ALL the red text, including line numbers, lines of code, everything . Don't snip or paraphrase like you did.

请先登录,再进行评论。

采纳的回答

Michael
Michael 2014-3-28
Both times you use "costoviaF" (lines 24 and 17) you fail to close the bracket at the end of your line.

更多回答(1 个)

andres
andres 2014-3-28
Wow, it was a very simple mistake, thank you very much, now it is working!

类别

Help CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by