MATLAB Answers

Proper usage of GoTo to avoid infinite loop

1 ビュー (過去 30 日間)
riya mathew
riya mathew 2021 年 3 月 27 日
回答済み: Les Beckham 2021 年 3 月 28 日
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 件のコメント
riya mathew
riya mathew 2021 年 3 月 27 日
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.

サインインしてコメントする。

回答 (1 件)

Les Beckham
Les Beckham 2021 年 3 月 28 日
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.

Community Treasure Hunt

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

Start Hunting!

Translated by