How to create multiple inputs and generate outputs.
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hye, I need help on my program, currently it can only run with a single input - Temperature (T) and Sun Irradiance (G). If you see in my codes, the inputs is only one 'T' and one 'G'. The main objective of this program is to find the PMax and Plot a graph of PMax over time. It can also plot graph of I-V Characteristic and Power Against Voltage.
Let say if I have a 100 inputs to be run, can anyone help me on how to edit the program so that it can import a set of data from a spreadsheet and can find the PMax of each correspondence (T) and (G), and can automatically Plot the graph? Seriously I'm stuck here. Need help asap. Thanks
Here is the current coding that I've made for a single input ;
clc
clear
VOC=64.2; %open circuit voltage (V)
ISC=5.96; %short circuit current (A)
VR=54.7; %reference voltage for maximum power
IR=5.58; %reference current for maximum power
TR=298; %reference temperature (K)
GR=1000; %reference irradiance (W/m^2)
NS=96; %number of cells per module
AM0=1.631; %area of one module (m^2)
mi=0.0035; %temperature coefficient for short circuit current (A/K)
% VOC=44.8; %open circuit voltage (V)
% ISC=8.33; %short circuit current (A)
% VR=35.2; %reference voltage for maximum power
% IR=7.95; %reference current for maximum power
% TR=298; %reference temperature (K)
% GR=1000; %reference irradiance (W/m^2)
% NS=72; %number of cells per module
% AM0=1.94; %area of one module (m^2)
% mi=0.00045; %temperature coefficient for short circuit current (A/K)
%-----CELL PARAMETERS-----
EG=1.124; %energy gap (eV)
A=1.3; %ideality factor
k=1.38*10^-23; %Boltzmann's constant (J/K)
q=1.6*10^-19; %charge of electron (C)
%-----INPUT-----
TA=input('Temperature (oC): ');
T1=TA+273; %convert from Celcius to Kelvin
%T1=input('Temperature (K): ');
G1=input('Solar irradiance (W/m^2): ');
% MS1=input('Number of modules in series (0 for single): ');
% MP1=input('Number of modules in parallel (0 for single): ');
MS1=0;
MP1=0;
%-----CALCULATION OF V BY VARYING I FOR A SINGLE MODULE-----
IL1=(ISC+(mi)*(T1-TR))*(G1/GR); %light generated current
IRS1=ISC/(exp((VOC*q)/(NS*A*k*TR))-1); %reference saturation current
IS1=IRS1*((T1/TR)^3)*exp((q*EG/(A*k))*((1/TR)-(1/T1))); %saturation current
RS1=((NS*A*k*TR/q)*log(((ISC-IR)/IRS1)+1)-VR)/IR; %series resistance
h1=IL1/1000; %setting increment
IA=0:h1:IL1; %range of I with increment h
N1=length(IA); %number of data points
VA(N1)=0; %setting final value of V
for i=1:(N1-1)
VA(i)=(NS*A*k*T1/q)*log(1+(IL1-IA(i))/IS1)-IA(i)*RS1; %computing V
end
%
% -----DETERMINATION OF OUTPUT BASED ON NUMBER OF MODULES-----
if MS1==0 %determining number of modules connected in series
MSA=1; %single module
else
MSA=MS1; %multiple modules connected in series
end
if MP1==0 %determining number of modules connected in parallel
MPA=1; %single module
else
MPA=MP1; %multiple modules connected in parallel
end
V1=MSA*VA; %new voltage limit
I1=MPA*IA; %new current limit
P1(N1)=0; %setting final value of P
for i=1:(N1-1)
P1(i)=I1(i)*V1(i); %computing P
end
%-----MAXIMUM POINT DETERMINATION-----
[PMAX1,i]=max(P1); %maximum P
VMAX1=V1(i); %V at maximum P
IMAX1=I1(i); %I at maximum P
%-----FILL FACTOR DETERMINATION-----
FF1=(VMAX1*IMAX1)/(V1(1)*I1(N1));
%-----EFFICIENCY DETERMINATION-----
AM1=MSA*MPA*AM0; %area based on number of modules
n1=(PMAX1/(AM1*GR))*100;
%-----I-V CHARACTERISTIC PLOT-----
figure(1)
plot(V1,I1), xlabel('Voltage (V)'), ylabel('Current (A)');
%
% %-----POWER AGAINST VOLTAGE PLOT-----
figure(2)
plot(V1,P1), xlabel('Voltage (V)'), ylabel('Power (W)');
2 commentaires
Image Analyst
le 23 Juin 2012
Edit your question. Highlight your code. Then click the "Code" icon above the text box. Do this whenever you have code in your question.
Réponses (2)
Walter Roberson
le 24 Juin 2012
1) Get rid of the "clear"
2) Move your input to the top, above the rest
3) Move everything else into a function that accepts G and T as parameters and does everything (including the plotting) and returns the appropriate values. Then after the part that reads the inputs from the user, insert a call to that function. And wrap the inputting and call into its own function.
function driveit
input....
[output1, output2, ...] = do_the_work(T1, G1);
end
function [output1, output2, ...] = do_the_work(T1, G1)
VOC = <etc>
end
4) When that works, move the plotting into the first routine instead of the second, so the second just does calculations and no plotting.
5) Add code to the first function to read TA, G1 values from the spreadsheet and loop through each pair, calling the work routine for that pair and getting the results back and doing the existing plotting. Use drawnow() to make each one visible as it is created, or put each one in a new figure, or use subplots, or whatever is appropriate.
6) If some kind of new plotting over the overall set of values read in from the spreadsheet, change the first routine to save the relevant information as it loops over the TA, G1 pairs, and do that new plotting after all the calculations have been done.
7) Now remove anything that is no longer relevant (e.g., individual plots.)
There is a completely different strategy available in some cases, involving making the program work for multiple TA, G1 pairs at the same time, a process known as "vectorization". Your code for calculating the resistance, IL1 can be vectorized, as can the next few statements up to calculating the increment. However, the part from IA onward uses different number of loop values depending on calculations on the T1, G1 values, and since the same amount of work is not being done, vectorization becomes tricky and even non-productive (slower and less clear and uses more memory.)
If you could redefine your hA and IA so that the same amount of work was done for all of the T1, G1 pairs, even if that meant taking the finest step size implied by the set of pairs and using that for everything, then vectorization would be more practical.
But you should always treat vectorization as an optimization, with your most important goal being to Get It Working First. And if that means following the steps I gave above to create a looped version, do that. The looped version might be fast enough. And if it isn't, you'll have a working reference version to compare against as you develop the vectorized version.
Voir également
Catégories
En savoir plus sur Renewables dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!