Proper usage of GoTo to avoid infinite loop

1 visualización (últimos 30 días)
riya mathew
riya mathew el 27 de Mzo. de 2021
Respondida: Les Beckham el 28 de Mzo. de 2021
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
Walter Roberson el 27 de Mzo. de 2021
??
MATLAB does not have any GOTO... I am not clear on what you are asking.
riya mathew
riya mathew el 27 de Mzo. de 2021
We used a .m file that was available online as a reference to develop the code we require. The code pasted above is what was available.
When we run the pso_final_isitso.m file, it is giving us one vaue in an infinite loop. Please refer the image attached below.
We have attached all the .m files we used to run our code. Kindly share your insights to solve this issue. Your help would be highly appreciated.

Iniciar sesión para comentar.

Respuestas (1)

Les Beckham
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.

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!

Translated by