forked from sandialabs/MATLAB_PV_LIB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_theta_phi_exact.m
86 lines (81 loc) · 3.34 KB
/
calc_theta_phi_exact.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function [theta phi] = calc_theta_phi_exact(Imp, IL, Vmp, Io, nNsVth, Rs, Rsh)
% CALC_THETA_PHI_EXACT computes Lambert W values appearing in the analytic
% solutions to the single diode equation for the max power point.
%
% Syntax
% [theta phi] = calc_theta_phi_exact(Imp, IL, Vmp, Io, nNsVth, Rs, Rsh)
%
% Description
% calc_theta_phi_exact calculates values for the Lambert W function
% which are used in the analytic solutions for the single diode equation
% at the maximum power point.
% For V=V(I), phi = W(Io*Rsh/n*Vth * exp((IL + Io - Imp)*Rsh/n*Vth))
% For I=I(V), theta = W(Rs*Io/n*Vth * Rsh/(Rsh+Rs)
% * exp(Rsh/(Rsh+Rs)*((Rs(IL+Io) + V)/n*Vth))
%
% Input:
% Imp - a vector of length N of values for Imp (A)
% IL - a vector of length N of values for light current IL (A)
% Vmp - a vector of length N of values for Vmp (V)
% Io - a vector of length N of values for Io (A)
% nNsVth - a vector of length N of values for the diode factor x thermal
% voltage for the module, equal to Ns (number of cells in series)
% x Vth (thermal voltage per cell).
% Rs - a vector of length N of values for series resistance (ohm)
% Rsh - a vector of length N of values for shunt resistance (ohm)
%
% Output:
% theta - a vector of values for the Lambert W function for solving
% I=I(V)
% phi - a vector of values for the Lambert W function for solving V=V(I)
%
% Sources:
% [1] C. Hansen, Parameter Estimation for Single Diode Models of
% Photovoltaic Modules, Sandia National Laboratories Report SAND2015-XXXX
% [2] A. Jain, A. Kapoor, "Exact analytical solutions of the parameters of
% real solar cells using Lambert W-function", Solar Energy Materials
% and Solar Cells, 81 (2004) 269-277.
% argument for Lambert W function involved in V = V(I)
% [1] Eq. 12; [2] Eq. 3
argw = Rsh.*Io./nNsVth .*exp(Rsh.*(IL + Io - Imp)./nNsVth);
u = argw>0;
w(~u)=NaN;
tmp = pvl_lambertw(argw(u));
ff = isnan(tmp);
% NaN where argw overflows. Switch to log space to evaluate
if any(ff)
logargW = log(Rsh(u)) + log(Io(u)) - log(nNsVth(u)) + Rsh(u).*(IL(u) + Io(u) - Imp(u))./nNsVth(u);
% Three iterations of Newton-Raphson method to solve w+log(w)=logargW.
% The initial guess is w=logargW. Where direct evaluation (above) results
% in NaN from overflow, 3 iterations of Newton's method gives
% approximately 8 digits of precision.
x = logargW;
for i=1:3
x = x.*((1-log(x)+logargW)./(1+x));
end;
tmp(ff) = x(ff);
end
w(u) = tmp;
phi = w(:);
% argument for Lambert W function involved in I=I(V)
% [1] Eq. 11; [2] Eq. 2
argw = Rsh./(Rsh+Rs).*Rs.*Io./nNsVth .*exp(Rsh./(Rsh+Rs).*(Rs.*(IL+Io)+Vmp)./nNsVth);
u = argw>0;
w(~u)=NaN;
tmp = pvl_lambertw(argw(u));
ff = isnan(tmp);
% NaN where argw overflows. Switch to log space to evaluate
if any(ff)
logargW = log(Rsh(u)./(Rsh(u)+Rs(u))) + log(Rs(u)) + log(Io(u)) - log(nNsVth(u)) + (Rsh(u)./(Rsh(u)+Rs(u))).*(Rs(u).*(IL(u)+Io(u)) + Vmp(u))./nNsVth(u);
% Three iterations of Newton-Raphson method to solve w+log(w)=logargW.
% The initial guess is w=logargW. Where direct evaluation (above) results
% in NaN from overflow, 3 iterations of Newton's method gives
% approximately 8 digits of precision.
x = logargW;
for i=1:3
x = x.*((1-log(x)+logargW)./(1+x));
end;
tmp(ff) = x(ff);
end
w(u) = tmp;
theta = w(:);