Skip to content

Update pvl_singlediode.m #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pvl_singlediode.m
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,19 @@
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;
B(u)=p(u);
A(~u)=p(~u);
p=(A+B)/2;
err = g(p,Iph,Io,a,Rs,Rsh);

iterCount = iterCount + 1;
if iterCount > 1000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't object to adding iterCount as insurance against some kind of erroneous behavior in the helper function g(), but perhaps reduce the limit to 50. In this bisection, convergence is achieved at an interval of width < 1e-6, from a starting interval between 0 and Iph. A reasonably large value of Iph is 10. In this case convergence is reached after ~20 iterations, assuming the code functions as intended.

error('Convergence failed in calc_Imp_bisect');
end
end;
Imp = p;

Expand Down Expand Up @@ -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
end