MATLAB Newsgroup

I want to draw characteristic curve for photovoltaic panel at different temperature temp=[25,35,45,55] but it enters for loop and can't exit when i change all temp to 25 the nominal temperature it works any other change hang.

clear all

clc

close all hidden

%% Information from the MSX60 solar array datasheet

% You may change these parameters to fit the I-V model

% to other kinds of solar arrays.

Iscn = 4.7; %Nominal short-circuit voltage [A]

Vocn = 43.2; %Nominal array open-circuit voltage [V]

Imp = 4.35; %Array current @ maximum power point [A]

Vmp = 34.6; %Array voltage @ maximum power point [V]

Pmax_e = Vmp*Imp; %Array maximum output peak power [W]

Kv = -0.223*Vocn %Voltage/temperature coefficient [V/K]

Ki = 0.0042*Iscn %Current/temperature coefficient [A/K]

Ns = 72; %Number of series cells

Npp= 1 ;

Nss= 1;

%% Constants

k = 1.3806503e-23; %Boltzmann (J/K)

q = 1.60217646e-19; %Electron charge (C)

a1 = 1; %Diode Ideality Facotrs constant

a=1;

p=a1;

%% Algorithm parameters

%Increment of Rs

Rsinc = 0.0001;

%Initial value of "a"

a = 1.0;

%Increment of "a"

ainc = 0.005;

%Maximum tolerable power error

tol = 0.0001;

%Maximum number of iteractions for each value of "a"

nimax = 10000;

%Voltage points in each iteraction

nv = 100;

%Number of "a" values to try

namax = 80;

%% Nominal values

Gn = 1000; % Nominal irradiance (W/m^2) @ 25oC

Tn = 25 + 273.15; % Nominal operating temperature (K)

Irrad=[1000,800,600,400,200];

Temp=[65,55,45,35,25];

Temperature=1; % Set Temperature=1 for Temperature changes Curves;

Irradiance=0; % Set Irradiance=1 for Irradiance changes Curves;

%% Code for generating I-V and P-V curves

for j=1:6

% %% Adjusting algorithm

if Temperature==1

if j==6

break

end

T=Temp(j)+273.15;

G=Irrad(j);

end

if Irradiance==1

G=Irrad(j);

T=298.15;

end

Vtn = k * Tn / q; %Thermal junction voltage (nominal)

Vt = k * T / q; %Thermal junction voltage (current temperature)

Rp =268.013169;Rs = 0.692200; %these Values are calculated using MSX60.m file

% Temperature and irradiation effect on the current

dT = T-Tn;

Ipvn = Iscn; % Nominal light-generated current((a1+a2)/2.2)

Ipv = (Ipvn + Ki*dT) *G/Gn; % Actual light-generated current

Isc_ = ( Iscn + Ki*dT );

Voc_ = ( Vocn + Kv*dT );

%Io = (Ipv - Vocn/Rp)/(exp(Vocn/Vt/a1/Ns)-1); %% NEW %% UPDATED ON JUNE/2010 %%

Io = Isc_/(exp(Voc_/((a1)/p)/Ns/Vt)-1);

clear V

clear I

V = 0:Vocn/nv:Vocn; % Voltage vector

I = zeros(1,size(V,2)); % Current vector

for j = 1 : length(V) %Calculates for all voltage values

% Solves g = I - f(I,V) = 0 with Newntonn-Raphson

g(j) = Ipv-Io*(exp((V(j)+I(j)*Rs)/Vt/Ns/a1)-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/a1)-1)-(V(j)+I(j)*Rs)/Rp-I(j);

glin(j) = -Io*Rs/Vt/Ns/a1*exp((V(j)+I(j)*Rs)/Vt/Ns/a1)-Rs/Rp-1;

I_(j) = I(j) - g(j)/glin(j);

I(j) = I_(j);

end

end % fr j = 1 : size(V,2)

%% Display the I-V and P-V curves.

% I-V curve

figure(3)

grid on

hold on

xlabel('V (V)');

ylabel('I (A)');

xlim([0 47]);

ylim([0 6]);

plot(V,I,'LineWidth',2,'Color','b'); %

text(38,5, 'T=25 °C ', 'Color', 'r');

text(20, 4.8, '1000 W/ m2 ', 'Color', 'k');

text(20, 3.8, '800 W/ m2 ', 'Color', 'k');

text(20, 2.9, '600 W/ m2 ', 'Color', 'k');

text(20, 1.9, '400 W/ m2 ', 'Color', 'k');

text(20, 1.2, '200 W/ m2 ', 'Color', 'k');

% P-V curve

figure(4)

grid on

hold on

xlabel('V (V)');

ylabel('P (W)');

xlim([0 47]);

ylim([0 160]);

text(36, 150, '1000 W/m2 ', 'Color', 'k');

text(36, 125, '800 W/m2 ', 'Color', 'k');

text(36, 95, '600 W/m2 ', 'Color', 'k');

text(36, 65, '400 W/m2 ', 'Color', 'k');

text(36, 35, '200 W/m2 ', 'Color', 'k');

plot(V,V.*I,'LineWidth',2,'Color','b'); %

end

"mado " <mahmmod.shaban@yahoo.com> wrote in message <lb40jj$1tl$1@newscl01ah.mathworks.com>...

> I want to draw characteristic curve for photovoltaic panel at different temperature temp=[25,35,45,55] but it enters for loop and can't exit when i change all temp to 25 the nominal temperature it works any other change hang.

>

> clear all

> clc

> close all hidden

> %% Information from the MSX60 solar array datasheet

>

> % You may change these parameters to fit the I-V model

> % to other kinds of solar arrays.

>

> Iscn = 4.7; %Nominal short-circuit voltage [A]

> Vocn = 43.2; %Nominal array open-circuit voltage [V]

> Imp = 4.35; %Array current @ maximum power point [A]

> Vmp = 34.6; %Array voltage @ maximum power point [V]

> Pmax_e = Vmp*Imp; %Array maximum output peak power [W]

> Kv = -0.223*Vocn %Voltage/temperature coefficient [V/K]

> Ki = 0.0042*Iscn %Current/temperature coefficient [A/K]

> Ns = 72; %Number of series cells

> Npp= 1 ;

> Nss= 1;

>

>

> %% Constants

>

> k = 1.3806503e-23; %Boltzmann (J/K)

> q = 1.60217646e-19; %Electron charge (C)

> a1 = 1; %Diode Ideality Facotrs constant

> a=1;

> p=a1;

>

>

> %% Algorithm parameters

>

> %Increment of Rs

> Rsinc = 0.0001;

>

> %Initial value of "a"

> a = 1.0;

>

> %Increment of "a"

> ainc = 0.005;

>

> %Maximum tolerable power error

> tol = 0.0001;

>

> %Maximum number of iteractions for each value of "a"

> nimax = 10000;

>

> %Voltage points in each iteraction

> nv = 100;

>

> %Number of "a" values to try

> namax = 80;

>

>

> %% Nominal values

>

> Gn = 1000; % Nominal irradiance (W/m^2) @ 25oC

> Tn = 25 + 273.15; % Nominal operating temperature (K)

>

> Irrad=[1000,800,600,400,200];

> Temp=[65,55,45,35,25];

> Temperature=1; % Set Temperature=1 for Temperature changes Curves;

> Irradiance=0; % Set Irradiance=1 for Irradiance changes Curves;

> %% Code for generating I-V and P-V curves

>

> for j=1:6

> % %% Adjusting algorithm

> if Temperature==1

> if j==6

> break

> end

> T=Temp(j)+273.15;

> G=Irrad(j);

> end

> if Irradiance==1

> G=Irrad(j);

> T=298.15;

> end

>

> Vtn = k * Tn / q; %Thermal junction voltage (nominal)

> Vt = k * T / q; %Thermal junction voltage (current temperature)

> Rp =268.013169;Rs = 0.692200; %these Values are calculated using MSX60.m file

>

> % Temperature and irradiation effect on the current

> dT = T-Tn;

> Ipvn = Iscn; % Nominal light-generated current((a1+a2)/2.2)

> Ipv = (Ipvn + Ki*dT) *G/Gn; % Actual light-generated current

> Isc_ = ( Iscn + Ki*dT );

> Voc_ = ( Vocn + Kv*dT );

> %Io = (Ipv - Vocn/Rp)/(exp(Vocn/Vt/a1/Ns)-1); %% NEW %% UPDATED ON JUNE/2010 %%

> Io = Isc_/(exp(Voc_/((a1)/p)/Ns/Vt)-1);

> clear V

> clear I

>

> V = 0:Vocn/nv:Vocn; % Voltage vector

> I = zeros(1,size(V,2)); % Current vector

>

> for j = 1 : length(V) %Calculates for all voltage values

>

> % Solves g = I - f(I,V) = 0 with Newntonn-Raphson

>

> g(j) = Ipv-Io*(exp((V(j)+I(j)*Rs)/Vt/Ns/a1)-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/a1)-1)-(V(j)+I(j)*Rs)/Rp-I(j);

> glin(j) = -Io*Rs/Vt/Ns/a1*exp((V(j)+I(j)*Rs)/Vt/Ns/a1)-Rs/Rp-1;

> I_(j) = I(j) - g(j)/glin(j);

> I(j) = I_(j);

>

> end

>

> end % fr j = 1 : size(V,2)

> %% Display the I-V and P-V curves.

>

> % I-V curve

> figure(3)

> grid on

> hold on

> xlabel('V (V)');

> ylabel('I (A)');

> xlim([0 47]);

> ylim([0 6]);

> plot(V,I,'LineWidth',2,'Color','b'); %

> text(38,5, 'T=25 °C ', 'Color', 'r');

> text(20, 4.8, '1000 W/ m2 ', 'Color', 'k');

> text(20, 3.8, '800 W/ m2 ', 'Color', 'k');

> text(20, 2.9, '600 W/ m2 ', 'Color', 'k');

> text(20, 1.9, '400 W/ m2 ', 'Color', 'k');

> text(20, 1.2, '200 W/ m2 ', 'Color', 'k');

>

> % P-V curve

> figure(4)

> grid on

> hold on

> xlabel('V (V)');

> ylabel('P (W)');

> xlim([0 47]);

> ylim([0 160]);

> text(36, 150, '1000 W/m2 ', 'Color', 'k');

> text(36, 125, '800 W/m2 ', 'Color', 'k');

> text(36, 95, '600 W/m2 ', 'Color', 'k');

> text(36, 65, '400 W/m2 ', 'Color', 'k');

> text(36, 35, '200 W/m2 ', 'Color', 'k');

>

>

> plot(V,V.*I,'LineWidth',2,'Color','b'); %

> end

Mado,

I believe I figured out your error. There were a couple of errors in your code. I had to rearrange where you put the plot function so the graph comes out accurately. But to answer your question, you code was getting stuck in the 'while' loop. If you stepped through it iteration by iteration you would see you were passing it an always 'true' condition. Be very careful of 'while' loops. I would always try to use if/else statements or pretty much anything else before using a 'while' loop.

Paste THIS code from in place of your for your loop:

%% Code for generating I-V and P-V curves

for j=1:6

%% Adjusting algorithm

if Temperature==1

if j==6

break

end

T=Temp(j)+273.15;

G=Irrad(j);

end

if Irradiance==1

G=Irrad(j);

T=298.15;

end

Vtn = k * Tn / q; %Thermal junction voltage (nominal)

Vt = k * T / q; %Thermal junction voltage (current temperature)

Rp =268.013169;Rs = 0.692200; %these Values are calculated using MSX60.m file

% Temperature and irradiation effect on the current

dT = T-Tn;

Ipvn = Iscn; % Nominal light-generated current((a1+a2)/2.2)

Ipv = (Ipvn + Ki*dT) *G/Gn; % Actual light-generated current

Isc_ = ( Iscn + Ki*dT );

Voc_ = ( Vocn + Kv*dT );

%Io = (Ipv - Vocn/Rp)/(exp(Vocn/Vt/a1/Ns)-1); %% NEW %% UPDATED ON JUNE/2010 %%

Io = Isc_/(exp(Voc_/((a1)/p)/Ns/Vt)-1);

clear V

clear I

V = 0:Vocn/nv:Vocn; % Voltage vector

I = zeros(1,size(V,2)); % Current vector

for i = 1 : length(V) %Calculates for all voltage values

% Solves g = I - f(I,V) = 0 with Newntonn-Raphson

g(i) = Ipv-Io*(exp((V(i)+I(i)*Rs)/Vt/Ns/a1)-1)-(V(i)+I(i)*Rs)/Rp-I(i);

if (abs(g(i)) > 0.001)

%while (abs(g(i)) > 0.001)

g(i) = Ipv-Io*(exp((V(i)+I(i)*Rs)/Vt/Ns/a1)-1)-(V(i)+I(i)*Rs)/Rp-I(i);

glin(i) = -Io*Rs/Vt/Ns/a1*exp((V(i)+I(i)*Rs)/Vt/Ns/a1)-Rs/Rp-1;

I_(i) = I(i) - g(i)/glin(i);

I(i) = I_(i);

end

end % fr j = 1 : size(V,2)

%% Display the I-V and P-V curves.

% I-V curve

figure(3)

grid on

hold on

xlabel('V (V)');

ylabel('I (A)');

xlim([0 47]);

ylim([0 6]);

plot(V,I,'LineWidth',2,'Color','b'); %

text(38,5, 'T=25 °C ', 'Color', 'r');

text(20, 4.8, '1000 W/ m2 ', 'Color', 'k');

text(20, 3.8, '800 W/ m2 ', 'Color', 'k');

text(20, 2.9, '600 W/ m2 ', 'Color', 'k');

text(20, 1.9, '400 W/ m2 ', 'Color', 'k');

text(20, 1.2, '200 W/ m2 ', 'Color', 'k');

% P-V curve

figure(4)

grid on

hold on

xlabel('V (V)');

ylabel('P (W)');

xlim([0 47]);

ylim([0 160]);

plot(V,V.*I,'LineWidth',2,'Color','b'); %

text(36, 150, '1000 W/m2 ', 'Color', 'k');

text(36, 125, '800 W/m2 ', 'Color', 'k');

text(36, 95, '600 W/m2 ', 'Color', 'k');

text(36, 65, '400 W/m2 ', 'Color', 'k');

text(36, 35, '200 W/m2 ', 'Color', 'k');

end

If you use this, you should get all six lines plotted on your power/voltage and current/voltage graphs in thick blue lines. Hope this is what you need.

Kevin

You can think of your watch list as threads that you have bookmarked.

You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.

To add items to your watch list, click the "add to watch list" link at the bottom of any page.

To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.

You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.

To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.

To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.

*No tags are associated with this thread.*

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

The newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.

Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.

Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.

There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.

**MATLAB Central**

You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.

Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.

**One Account**

Your MATLAB Central account is tied to your MathWorks Account for easy access.

**Use the Email Address of Your Choice**

The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.

**Spam Control**

Most newsgroup spam is filtered out by the MATLAB Central Newsreader.

**Tagging**

Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.

**Watch lists**

Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.

- Use a newsreader through your school, employer, or internet service provider
- Pay for newsgroup access from a commercial provider
- Use Google Groups
- Mathforum.org provides a newsreader with access to the comp.soft sys.matlab newsgroup
- Run your own server. For typical instructions, see: http://www.slyck.com/ng.php?page=2