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

조회 수: 11 (최근 30일)
andres
andres 2014년 3월 28일
답변: andres 2014년 3월 28일
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