%insirir os dados de inversor
data_KC85T
constantes
%% Adjusting algorithm
plott = 0; %1 = Enables plotting during the algorithm execution
%0 = Disables plotting
% Valores de referencia de Rs e Rp
Rs_max = (Vocn - Vmp)/ Imp;
Rp_min = Vmp/(Iscn-Imp) - Rs_max;
% Valores Iniciais de Rp e Rs
Rs = 0;
Rp = Rp_min;
% Condicoes STC
T = Tn;
G = Gn;
Vtn = k * Tn / q; %Thermal junction voltage (nominal)
Vt = k * T / q; %Thermal junction voltage (current temperature)
perror = Inf; %dummy value
% Processo Iterativo para calculo de Rs e Rp ate Pmax,modelo = Pmax,experimental
ni = 0;
while (perror>tol) && (Rp > 0) && (ni < nimax)
ni = ni + 1;
% Efeito da temperatura e Radicao na corrente
dT = T-Tn;
Ipvn = (Rs+Rp)/Rp * Iscn; % Fotocorrente Nominal
Ipv = (Ipvn + Ki*dT) *G/Gn; % Fotocorrente a radiacao e temperatura
Isc = (Iscn + Ki*dT) *G/Gn; % Corrente de Curto-Circuito Atual
Io = (Ipv - Vocn/Rp)/(exp(Vocn/Vt/a/Ns)-1);
% Incremento Rs
Rs = Rs + Rsinc;
Rp_ = Rp;
Rp = Vmp*(Vmp+Imp*Rs)/(Vmp*Ipv-Vmp*Io*exp((Vmp+Imp*Rs)/Vt/Ns/a)+Vmp*Io-Pmax_e);
% Resolucao da equacao I-V para Varios Valores de Pares (V,I)
clear V
clear I
V = 0:Vocn/nv:Vocn; % Vetor das Tensoes
I = zeros(1,size(V,2)); % Vetor das Correntes
for j = 1 : size(V,2) % Calculo para todos os valores da tensao
% Resolver g = I - f(I,V) = 0 com Newton-Raphson
g(j) = Ipv-Io*(exp((V(j)+I(j)*Rs)/Vt/Ns/a)-1)-(V(j)+I(j)*Rs)/Rp-I(j);
while (abs(g(j)) > 0.001)
g(j) = Ipv-Io*(exp((V(j)+I(j)*Rs)/Vt/Ns/a)-1)-(V(j)+I(j)*Rs)/Rp-I(j);
glin(j) = -Io*Rs/Vt/Ns/a*exp((V(j)+I(j)*Rs)/Vt/Ns/a)-Rs/Rp-1;
I_(j) = I(j) - g(j)/glin(j);
I(j) = I_(j);
end
end % para j = 1 : size(V,2)
if (plott)
%Plots para I-V e curvas P-V
%Corrente x Voltagem
figure(1)
grid on
hold on
title('I-V curve - Adjusting Rs and Rp');
xlabel('V [V]');
ylabel('I [A]');
xlim([0 Vocn]);
ylim([0 Iscn]);
%Plots I x V curva
plot(V,I,'LineWidth',2,'Color','k')
%Plots de "pontos remarcáveis" na curva I x V
plot([0 Vmp Vocn],[Iscn Imp 0],'o','LineWidth',2,'MarkerSize',5,'Color','k')
%Potencia x Voltagem
figure(2)
grid on
hold on
title('P-V curve - Adjusting peak power');
xlabel('V [V]');
ylabel('P [W]');
xlim([0 Vocn])
ylim([0 Vmp*Imp]);
end % if(plott)
% Calcular a potencia usando a equação I-V
P = (Ipv-Io*(exp((V+I.*Rs)/Vt/Ns/a)-1)-(V+I.*Rs)/Rp).*V;
Pmax_m = max(P);
perror = (Pmax_m-Pmax_e);
if (plott)
%Plots P x V curva
plot(V,P,'LineWidth',2,'Color','k')
%Plots de "pontos remarcáveis" da curva de potência
plot([0 Vmp Vocn],[0 Vmp*Imp 0],'o','LineWidth',2,'MarkerSize',5,'Color','k')
end % if (plott)
end % while (error>tol)
if (Rp<0) Rp = Rp_
end
Ion = Io; %
%% Outputs
% I-V curve
figure(3)
grid on
hold on
title('Adjusted I-V curve');
xlabel('V [V]');
ylabel('I [A]');
xlim([0 Vocn*1.1]);
ylim([0 Iscn*1.1]);
plot(V,I,'LineWidth',2,'Color','k') %
plot([0 Vmp Vocn ],[Iscn Imp 0 ],'o','LineWidth',2,'MarkerSize',5,'Color','k')
% P-V curve
figure(4)
grid on
hold on
title('Adjusted P-V curve');
xlabel('V [V]');
ylabel('P [W]');
xlim([0 Vocn*1.1]);
ylim([0 Vmp*Imp*1.1]);
plot(V,P,'LineWidth',2,'Color','k') %
plot([0 Vmp Vocn ],[0 Pmax_e 0 ],'o','LineWidth',2,'MarkerSize',5,'Color','k')
disp(sprintf('Modelo info:\n'));
disp(sprintf(' Rp_min = %f',Rp_min));
disp(sprintf(' Rp = %f',Rp));
disp(sprintf(' Rs_max = %f',Rs_max));
disp(sprintf(' Rs = %f',Rs));
disp(sprintf(' a = %f',a));
disp(sprintf(' T = %f',T-273.15));
disp(sprintf(' G = %f',G));
disp(sprintf(' Pmax,m = %f (modelo)',Pmax_m));
disp(sprintf(' Pmax,e = %f (experimental)',Pmax_e));
disp(sprintf(' tol = %f',tol));
disp(sprintf('P_error = %f',perror));
disp(sprintf(' Ipv = %f',Ipv));
disp(sprintf(' Isc = %f',Isc));
disp(sprintf(' Ion = %g',Ion));
disp(sprintf('\n\n'));