Proper usage of GoTo to avoid infinite loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
function [Eb,Edump,diesel,t] = OUR_RUN_DIESEL_GENERATOR(Pp,Eb,Ebmax,uinv,Pl,t,Pg,Edump,Edch,Ech,diesel,Ebmin)
%^^^^^^^^^^^^^^^RUN DIESEL GENERATOR ^^^^^^^^^^^^^^
%LABEL RUN_DIESEL_GENERATOR
if Edch(t)<=((Pg*uinv+Pp(t))-(Pl(t)/uinv))
Eb(t)=Eb(t-1)+(Pg*uinv)+Pp(t)-((Pl(t)/uinv)*1);
if Eb(t)>Ebmax
Edump(t)=Eb(t)-Ebmax;
Eb(t)=Ebmax;
end
if Eb(t)<Ebmin
Edump(t)=0;
Eb(t)=Ebmin;
end
diesel(t)=Pg*uinv;
%JUMP TO RUN DIESEL GENERATOR!!!
% return
end
end
While implementing a code on Particle Swarm Optimization to perform Techno-Economic Analysis of a Hybrid Renewable Energy (PV Diesel Battery) System, this function (OUR_RUN_DIESEL_GENERATOR) seems to be running in an infinite loop.
In lieu of this, any help regarding the usage of the statement would be highly appreciated.
2 comentarios
Walter Roberson
el 27 de Mzo. de 2021
??
MATLAB does not have any GOTO... I am not clear on what you are asking.
Respuestas (1)
Les Beckham
el 28 de Mzo. de 2021
It appears that you are attempting to create a recursive algorithm. If so, replace "%JUMP TO RUN DIESEL GENERATOR!!!" with another call to OUR_RUN_DIESEL_GENERATOR. You probably need to update the t for the next iteration. You haven't provided any way to get out of the recursion, though. Maybe an else for your main if that exits?
I didn't look at the additional code you posted but these issues were immediately obvious from the top level code.
0 comentarios
Ver también
Categorías
Más información sobre Particle Swarm 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!