Skip to content

Commit 85efebf

Browse files
joallen6cwhanse
authored andcommitted
Update pvl_singlediode.m (#23)
* Update pvl_singlediode.m Added iteration limit on while loop. This can be infinite if inputs are unreasonable (see comments on pvl_perez). It's good form to let user know source of error. * Update pvl_singlediode.m 50 iterations seems fine. My current data ran fine with this limit. Thanks,
1 parent 6bfa16e commit 85efebf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pvl_singlediode.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,19 @@
338338
p = (A+B)./2;
339339
err = g(p,Iph,Io,a,Rs,Rsh); % value of dP/dV at initial guess p
340340

341+
iterCount = 0;
341342
while max(abs(B-A))>1e-6 % set precision of estimate of Imp to 1e-6 (A)
342343
gA=g(A,Iph,Io,a,Rs,Rsh); % value of dP/dV at left endpoint
343344
u=(gA.*err)<0;
344345
B(u)=p(u);
345346
A(~u)=p(~u);
346347
p=(A+B)/2;
347348
err = g(p,Iph,Io,a,Rs,Rsh);
349+
350+
iterCount = iterCount + 1;
351+
if iterCount > 50
352+
error('Convergence failed in calc_Imp_bisect');
353+
end
348354
end;
349355
Imp = p;
350356

@@ -373,4 +379,4 @@
373379
z = z(:);
374380
Vmp=(Iph+Io-Imp).*Rsh - Imp.*Rs - a.*z; % Compute V from Imp and W(phi)
375381
Pmp = Vmp.*Imp;
376-
end
382+
end

0 commit comments

Comments
 (0)