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

11 visualizaciones (últimos 30 días)
andres
andres el 28 de Mzo. de 2014
Respondida: andres el 28 de Mzo. de 2014
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 comentario
Image Analyst
Image Analyst el 28 de Mzo. de 2014
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.

Iniciar sesión para comentar.

Respuesta aceptada

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

Más respuestas (1)

andres
andres el 28 de Mzo. de 2014
Wow, it was a very simple mistake, thank you very much, now it is working!

Categorías

Más información sobre Financial Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by