MATLAB: While executing a m-file it shows busy

while running m file it shows busy

I am working on PV Cell modelling. I came across a matlab code and while running the m file it shows busy.
clc;
clear all;
T=25+273;
Tn=25+273;
dT=T-Tn;
G=800;
Gn=1000;
Imp=7.61;
Vmp=26.3;
Iscn=8.21;
Vocn=32.9;
Pmaxe=Vmp*Imp;
Kv=-0.1230;
Ki=0.0032;
Ns=54;
k=1.38065e-23;
q=1.602e-19;
a=1.3;
Vtn=k*Tn/q;
Vt=k*T/q;
Rpmin=(Vmp/(Iscn-Imp))-((Vocn-Vmp)/Imp);
Rp=Rpmin;
Rs=0;
Io=(Iscn+(Ki*dT))/((exp((Vocn+(Kv*dT))/a*Vt))-1);
P=(0);
err=inf;
tol=0.01;
while(err>tol)
Ipvn=(((Rs+Rp)/Rp))*Iscn;
Ipv=(Ipvn+(Ki*dT))*(G/Gn);
Isc=(Iscn+(Ki*dT))*(G/Gn);
Rs=Rs+0.01;
b=exp(((Vmp+(Imp*Rs))*q)/(Ns*a*k*T));
Rp=(Vmp+(Imp*Rs))/((Vmp*Ipv)-(Vmp*Io*b)+(Vmp*Io)-Pmaxe);
clear V
clear I
V=0:0.1:50;
I=zeros(1,size(V,2));
g=zeros(1,size(V,2));
glin=zeros(1,size(V,2));
I_=zeros(1,size(V,2));
for j=1:size(V,2)
g(j)=Ipv-(Io*exp(V(j)+(Rs*I(j)))/(Vt*a*Ns))+Io-((V(j)+(Rs*I(j)))/Rp)-I(j);
while(abs(g(j))>0.001)
g(j)=Ipv-(Io*exp(V(j)+(Rs*I(j)))/(Vt*a*Ns))+Io-((V(j)+(Rs*I(j)))/Rp)-I(j);
glin(j)=-(Io*exp((V(j)+(Rs*I(j)))/(Vt*a*Ns))*Rs/(Vt*a*Ns))-(Rs/Rp)-1;
I_(j)=I(j)-(g(j)/glin(j));
I(j)=I_(j);
end
end
P=(Ipv-(Io*exp((V+(I.*Rs))/(Vt*a*Ns)))+Io-((V+(I.*Rs))/Rp)).*V;
Pmax=max(P);
err=(Pmax-Pmaxe);
end
fprintf('Model info:-\n');
fprintf('Rp=%f',Rp);
fprintf('Rs=%f',Rs);
fprintf('Pmax=%f',Pmax);

Best Answer

It is getting in stuck while performing while loop inside for loop ( while(abs(g(j))>0.001)). Check your code for mistakes, because there are situations when (abs(g(j))>0.001) cannot be false.