Can someone help me? I am still new to matlab and can fix the errors that I come across.

20 views (last 30 days)
I was trying to follow the flowchart that is attached below and the formulas used in the paper to extract the PV parameter such as
Is (Reverse Saturation Current)
Iph (Photocurrent)
Rs (Series Resistance)
n (ideality factor) ( which I have given a value to make it easier for now)
And while considering rsh =0
I have included the data provided to me to have the program running.
clc, close all, clear all
% Data provided for the project
load('SD_Test_Data_01.mat', 'voltage')
load('SD_Test_Data_01.mat', 'current')
plot (voltage, current,'*')
xlabel('Voltage'), ylabel('Current')
title('I-V Curve')
% At the standard test conditions (STC)
Imp = current; %(A)
Isc = max(max(current)); %(A)
Vmp = voltage; %(v)
Voc = max(max(voltage)); %(V)
% Ig is the light-generated current
% Io = Isat is the diode reverse saturation current
% Rs, Rp are the series and the parallel resistances
n = 1.2; % Ideality factor technology Si-mono
q = 1.6022e+19; %q is the electron charge
K = 1.3806e-23; % k is the Boltzmann constant in (J/k)
% if the solar cells inside a solar module reach 65°C
T = 65; % T the module temperature °C
Tr = 25; % Reference temperature °C
% Temperature coefficient of the maximum output power (Pmax ) at STC (%/°C)
k = -0.41;
Ns = 72; % Ns is the number of series connected cells forming the PV module
Rs = 0;
S = 1; %
% At short circuit point (V = 0); I = Isc
Ig = Isc;
% Vt is the thermal voltage
Vt = (Ns*n*K*T)/q;
% Solve for I(sat), the reverse saturation current of the diode.
Isat = Ig /(exp(1).^(Voc/Vt) - 1);
% Calculate Rp = Rp,min
Rp = (Vmp./(Isc - Imp)) - ((Voc - Vmp)./Imp);
% Voltage and current w.r.t. Voc >= V>= 0
V = Vmp((Vmp>=0) & (Vmp<=Voc));
I = Isc((Vmp>=0) & (Vmp<=Voc));
tol = 1e-4;
err = Inf;
while(err>tol)
% Sol Eq (7),(15) and (16)
Ig = (Isc + k*(T - Tr))*(S/1000); % Eq(7)
% Pmp,model = Pmp,curve = Vmp Imp at the MPP (Vmp , Imp ) of the I–V curve
Rp = Vmp.*(Vmp+(Rs.*Imp))./((Vmp.*(Ig - Isat.*(exp(Vmp+(Rs.*Imp)/Vt))-1)) - Vmp.*Imp);
Ig = ((Rp + Rs)/Rp)*Isc; % Eq(16)
% Sol eq (1) and (9)
% The output current of the single diode model is a function of the output voltage
I = Ig - Isat.*(exp((V + (I*Rs))/Rp)-1) - (V + (I*Rs))/Rp; %Eq(1)
% Solve for I(sat), the reverse saturation current of the diode.
Isat = (Ig - (Voc/Rp))/(exp(Voc/Vt) - 1); % Eq(9)
% For Voc >= V>= 0
P = V.*I;
% finding Pmax,model using max(P)
Pmax = max(P);
% calculating error, %%% Pmaxcurve is not defined anywhere
err = abs(Pmaxmodel - Pmaxcurve);
%%% Change in resistance not defined neither described
Rs = Rs + delRs;
end
[SL: formatted the text of the question as text not code]
  1 Comment
Raymond Norris
Raymond Norris on 16 Oct 2020
Hi,
I would suggest editing your post by
  1. encompassing the code into the CODE block,
  2. providing the error you're getting (it's unclear which is line 72), and
  3. trimming down the code so that it can be run. without the MAT-file, the error can't be re-generated.
Raymond

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 16 Oct 2020
I = Ig - Isat.*(exp((V + (I*Rs))/Rp)-1) - (V + (I*Rs))/Rp; %Eq(1)
%[...]
P = V.*I;
V is not defined.
I = Ig_Md - Isat_0d.*(exp((V + (I*Rs_0d))/Rp_2D)-1) - (V + (I*Rs_0d))/Rp_2D; %Eq(1)
I is assigned to in that statement, but the calculation of I uses I as input, and I is not defined at that point the first time through.
Vmp = voltage; %(v)
Voc = max(max(voltage)); %(V)
You would not bother to take max(max()) of a value that was not 2D or more, so we can predict that voltage is 2D, and since voltage was assigned to Vmp, that Vmp is 2D.
Rp = (Vmp./(Isc - Imp)) - ((Voc - Vmp)./Imp);
Rp involves Vmp and Vmp is 2D, so we can predict that Rp is 2D.
I = Ig - Isat.*(exp((V + (I*Rs))/Rp)-1) - (V + (I*Rs))/Rp; %Eq(1)
That has quantitites / Rp and Rp is 2D. In MATLAB, the / operator is "matrix right division", which is a least squared fitting operation such that P/Q is similar to P * pinv(Q) where * here is matrix multiplication (inner product). Are you sure you want matrix right division there???
Ig = ((Rp + Rs)/Rp)*Isc; % Eq(16)
Likewise on that (slightly earlier) line, / is the matrix right division operator: are you sure you want to use that operator there??
Voc = max(max(voltage)); %(V)
Voc is going to be a scalar unless voltage is has three or more non-scalar dimensions.
Isat = (Ig - (Voc/Rp))/(exp(Voc/Vt) - 1); % Eq(9)
Rp is 2D, so you have scalar / 2D . Earlier I said that P/Q is similar to P*pinv(Q), but it is not exactly the same. The size checks that are done require P and Q to have the same number of rows for P/Q, and scalar / 2D is not going to satisfy that condition.
Ig = (Isc + k*(T - Tr))*(S/1000); % Eq(7)
% Pmp,model = Pmp,curve = Vmp Imp at the MPP (Vmp , Imp ) of the I–V curve
Rp = Vmp.*(Vmp+(Rs.*Imp))./((Vmp.*(Ig - Isat.*(exp(Vmp+(Rs.*Imp)/Vt))-1)) - Vmp.*Imp);
Ig = ((Rp + Rs)/Rp)*Isc; % Eq(16)
Isc and k and T and Tr and S are all scalars, so Eq(7) is going to assign a scalar to Ig. But with Vmp and Imp being 2D, Rp is going to be 2D, and then on the next line you have two matrices the same size / each other, which is going to give a square matrix with the same number of rows and columns that Rp has rows, so Eq(16) is going to be 2D so Ig went from scalar three lines earlier to be reassigned to 2D. This is confusing for the reader!! About the only time you should switch dimensions on a variable in mid-stream (except with explicit subscript assignment or concatenation or repmat() operators) is the case where one of the lines initialized the variable to [] or '' . MATLAB permits arrays to be re-assigned to different dimensions, but I can tell that you yourself got confused over what size Ig is.
  5 Comments
Walter Roberson
Walter Roberson on 18 Oct 2020
I do not know. What is your purpose in trying to index a scalar?
My guess would be that you want
I = Imp((Vmp>=0) & (Vmp<=Voc));

Sign in to comment.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!