Borrar filtros
Borrar filtros

Illegal use of reserved keyword "else".

9 visualizaciones (últimos 30 días)
Craig Johnson
Craig Johnson el 2 de Dic. de 2021
Editada: DGM el 2 de Dic. de 2021
function q_P = ParticularSolution (K,M,f_0,t,w_R,roadflag)
Q=[[-K,-w_R*M,w_R*M,-K]
else roadflag==1
s_1==-f_0./K
s_2==0/K
q_P==s_1+s_2*t
elseif roadflag==2
q_P==s_1*sin(w_R*t)+s_2*cos(w_R*t)
s_1==s_2==F./Q
end
  4 comentarios
Chunru
Chunru el 2 de Dic. de 2021
What are your edited code and the error message?
Craig Johnson
Craig Johnson el 2 de Dic. de 2021
function q_P = ParticularSolution (K,M,f_0,t,w_R,roadflag)
Q=[[-K,-w_R*M,w_R*M,-K]
if s_1==-f_0./K
s_2==0/K
q_P==s_1+s_2*t
elseif roadflag==2
q_P==s_1*sin(w_R*t)+s_2*cos(w_R*t)
s_1==s_2==F./Q
end
end

Iniciar sesión para comentar.

Respuestas (2)

KSSV
KSSV el 2 de Dic. de 2021
Editada: KSSV el 2 de Dic. de 2021
function q_P = ParticularSolution (K,M,f_0,t,w_R,roadflag)
Q=[-K,-w_R*M,w_R*M,-K] ;
if roadflag==1
s_1==-f_0./K
s_2==0/K
q_P==s_1+s_2*t
else roadflag==2
q_P==s_1*sin(w_R*t)+s_2*cos(w_R*t)
s_1==s_2==F./Q
end
  3 comentarios
KSSV
KSSV el 2 de Dic. de 2021
Where are you using it? Show us the full code which you are using and throwing error.
KSSV
KSSV el 2 de Dic. de 2021
Editted the code....there is a typo error extra brace.

Iniciar sesión para comentar.


DGM
DGM el 2 de Dic. de 2021
Editada: DGM el 2 de Dic. de 2021
Start with
function q_P = ParticularSolution (K,M,f_0,t,w_R,roadflag)
Q = [-K,-w_R*M,w_R*M,-K]; % fix imbalanced brackets
if roadflag==1 % start with if
s_1 = -f_0./K; % = is an assignment; == is a logical test
s_2 = 0/K; % this is just zero ??
q_P = s_1+s_2*t;
elseif roadflag==2
q_P = s_1*sin(w_R*t) + s_2*cos(w_R*t);
s_1 = s_2==(F./Q); % unused; F is undefined
end
end % close function scope
Observe that s_1 and s_2 are used in both cases, but are only defined in the first case. If these are indeed needed by both, move them outside the conditional structure.
Also, the size of the variables is likely to matter, but we don't know what they are. We know that Q is a vector. if F and s_2 are scalars, then
s_1 = s_2==(F./Q)
will return a logical vector. If either F or s_2 are vectors, their size would need to be compatible with that of Q. Again, since this assignment occurs after the assignment of the only output variable, the results are never used for anything. If it's to be moved before the assignment of q_P, then it remains to be seen how a logical vector would make conceptual sense in the calculation or whether the variable dimensions would be compatible.
Perhaps this is supposed to be an indexing operation, but I can only really guess at this point.
s_1 = s_2(s_2==(F./Q)) % ??

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by