diff --git a/pvl_singlediode.m b/pvl_singlediode.m index 05a2f41..4402d75 100644 --- a/pvl_singlediode.m +++ b/pvl_singlediode.m @@ -338,6 +338,7 @@ p = (A+B)./2; err = g(p,Iph,Io,a,Rs,Rsh); % value of dP/dV at initial guess p +iterCount = 0; while max(abs(B-A))>1e-6 % set precision of estimate of Imp to 1e-6 (A) gA=g(A,Iph,Io,a,Rs,Rsh); % value of dP/dV at left endpoint u=(gA.*err)<0; @@ -345,6 +346,11 @@ A(~u)=p(~u); p=(A+B)/2; err = g(p,Iph,Io,a,Rs,Rsh); + + iterCount = iterCount + 1; + if iterCount > 50 + error('Convergence failed in calc_Imp_bisect'); + end end; Imp = p; @@ -373,4 +379,4 @@ z = z(:); Vmp=(Iph+Io-Imp).*Rsh - Imp.*Rs - a.*z; % Compute V from Imp and W(phi) Pmp = Vmp.*Imp; -end \ No newline at end of file +end