Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
while loop is not excuted

Subject: while loop is not excuted

From: mado

Date: 19 Jul, 2012 09:59:16

Message: 1 of 18

this simple code for maximum power tracking but it's not excuted ,I don't know why.



vlast=vk;

   while pk <plast
       B=0.2
       p=pk-plast;
     
 if pk > plast
 pk
 vref = vlast+B*p;
 elseif pk < plast
  vref = vlast-B*p


% elseif pk > plast
    % vref = vlast-2
 %else vref = vlast-2 ;
 end

   end
thanks

Subject: while loop is not excuted

From: mado

Date: 19 Jul, 2012 10:11:06

Message: 2 of 18

"mado " <elec_mnf@yahoo.com> wrote in message <ju8lpk$a4h$1@newscl01ah.mathworks.com>...
> this simple code for maximum power tracking but it's not excuted ,I don't know why. where pk,plast, vk, vlast are being brought from workspace.
>
>
>
> vlast=vk;
>
> while pk <plast
> B=0.2
> p=pk-plast;
>
> if pk > plast
> pk
> vref = vlast+B*p;
> elseif pk < plast
> vref = vlast-B*p
>
>
> % elseif pk > plast
> % vref = vlast-2
> %else vref = vlast-2 ;
> end
>
> end
> thanks

Subject: while loop is not excuted

From: Torsten

Date: 19 Jul, 2012 10:19:19

Message: 3 of 18

On 19 Jul., 11:59, "mado " <elec_...@yahoo.com> wrote:
> this simple code for maximum power tracking but it's not excuted ,I don't know why.
>
> vlast=vk;
>
> while pk <plast
> B=0.2
> p=pk-plast;
>
> if pk > plast
> pk
> vref = vlast+B*p;
> elseif pk < plast
> vref = vlast-B*p
>
> % elseif pk > plast
> % vref = vlast-2
> %else vref = vlast-2 ;
> end
>
> end
> thanks

1. We don't know the values of pk and plast before the while command -
so we don't know whether the condition to enter
the while loop is fulfilled.
2. Even if pk is smaller than plast before the while loop, you had
created an infinite loop since pk and plast remain unchanged
within the while structure.

Best wishes
Torsten.

Subject: while loop is not excuted

From: mado

Date: 19 Jul, 2012 11:02:12

Message: 4 of 18

I have stored pk and plast in excel file , the curve is increased till maximum point and decreased again
i have made plast by making delay of pkm and these are some values
plast
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1.108420001
32.84743127
77.37938832
117.0185181
135.8687006
148.8734869
141.1583298
127.5051796
114.3377173
104.5800238
97.58267351
91.08819529
84.08623056
77.205494
72.93585348
69.09492841
64.93344044
60.76576438
57.39393244
54.95580147
52.86323097
50.60706457
48.10694863


pk
0
2.032149405
5.890012204
13.11807244
23.84366054
38.65416312
58.69218312
86.43823147
125.2987397
148.9527166
142.1985367
131.8064981
118.8265505
105.887668
98.42893016
91.84250711
84.68389769
77.58186371
73.2481618
69.35100038
65.12768374
60.89976395
57.48724235
55.03336425
52.93529869
50.66985218
48.14840075

Subject: while loop is not excuted

From: Steven_Lord

Date: 19 Jul, 2012 13:25:39

Message: 5 of 18



"mado " <elec_mnf@yahoo.com> wrote in message
news:ju8pfk$lu7$1@newscl01ah.mathworks.com...
> I have stored pk and plast in excel file , the curve is increased till
> maximum point and decreased again i have made plast by making delay of pkm
> and these are some values

*snip the plast and pk vectors*

http://www.mathworks.com/help/techdoc/ref/while.html

"An evaluated expression is true when the result is nonempty and contains
all nonzero elements (logical or real numeric). Otherwise, the expression is
false."

Are ALL elements in pk strictly less than the corresponding elements of
plast? They are not. Therefore the expression is false and the WHILE loop is
never entered.

Explain in words what you're trying to do with that FOR loop and someone may
be able to offer a suggestion for how to accomplish that task.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: while loop is not excuted

From: mado

Date: 19 Jul, 2012 21:12:18

Message: 6 of 18

I just want to repeat the if condition expression ,so i did the loop and i want it to be stopped when pk is less than plast and that will offsure happened this is the nature of the curve.

Subject: while loop is not excuted

From: mado

Date: 20 Jul, 2012 19:42:16

Message: 7 of 18

any help please

Subject: while loop is not excuted

From: dpb

Date: 20 Jul, 2012 20:30:48

Message: 8 of 18

On 7/20/2012 2:42 PM, mado wrote:
> any help please

I couldn't follow the request well enough to decipher, sorry...

How about a _very_ short data set of input and desired output -- like 10
points or less??

--

Subject: while loop is not excuted

From: mado

Date: 21 Jul, 2012 08:31:24

Message: 9 of 18

dpb <none@non.net> wrote in message <jucf5k$32k$1@speranza.aioe.org>...
> On 7/20/2012 2:42 PM, mado wrote:
> > any help please
>
> I couldn't follow the request well enough to decipher, sorry...
>
> How about a _very_ short data set of input and desired output -- like 10
> points or less??

sorry , i didn't get you , the number of points depend on simulation time cause these points are gotten from simulink and there is minimum number of points i can't let it down.

Subject: while loop is not excuted

From: mado

Date: 21 Jul, 2012 09:18:31

Message: 10 of 18

even the If condition without while loop isn't also performed because there are zero elements in the result so what to do?

Subject: while loop is not excuted

From: Bruno Luong

Date: 21 Jul, 2012 11:02:10

Message: 11 of 18

"mado " <elec_mnf@yahoo.com> wrote in message <juds56$gbt$1@newscl01ah.mathworks.com>...
> even the If condition without while loop isn't also performed because there are zero elements in the result so what to do?

Sorry but you need learning the basic of MATLAB programming first. The code does not have any logic all the way from start to bottom (that's also the reason why nobody here can possibly guess your intention from this code)

Read the getting started guide.

Bruno

Subject: while loop is not excuted

From: mado

Date: 21 Jul, 2012 11:23:07

Message: 12 of 18

How did you get that impression that i don't know basics the code is clear and i explained it and this link has flow chart of the code will help you to get it.
http://www.ni.com/white-paper/8106/en
see perturb and observe method

Subject: while loop is not excuted

From: dpb

Date: 21 Jul, 2012 12:50:27

Message: 13 of 18

On 7/21/2012 3:31 AM, mado wrote:
> dpb <none@non.net> wrote in message <jucf5k$32k$1@speranza.aioe.org>...
>> On 7/20/2012 2:42 PM, mado wrote:
>> > any help please
>>
>> I couldn't follow the request well enough to decipher, sorry...
>>
>> How about a _very_ short data set of input and desired output -- like
>> 10 points or less??
>
> sorry , i didn't get you ,...

I meant to _post_ a short dataset that illustrates the input/desired
output so somebody can try to decipher what it is you're trying to do.

That only needs to be a few points, not thousands...

--

Subject: while loop is not excuted

From: Bruno Luong

Date: 21 Jul, 2012 13:02:15

Message: 14 of 18

"mado " <elec_mnf@yahoo.com> wrote in message <jue3er$adf$1@newscl01ah.mathworks.com>...
> How did you get that impression that i don't know basics the code i

Your code shows it.

Basic looping, variable assignment, conditional test are all wrong.

Bruno

Subject: while loop is not excuted

From: mado

Date: 21 Jul, 2012 15:45:21

Message: 15 of 18

you have the flowchart now

Subject: while loop is not excuted

From: Marc

Date: 23 Jul, 2012 04:39:15

Message: 16 of 18

"mado " <elec_mnf@yahoo.com> wrote in message <jueiqh$1rr$1@newscl01ah.mathworks.com>...
> you have the flowchart now

We do not need YOUR flow sheet. Our code works just fine.

I cannot figure out your starting point/starting values. Why would you store anything in excel if you have Matlab?

Add some comments to your code, trying to explain what that line is attempting to accomplish.

Then maybe someone can help you.

Subject: while loop is not excuted

From: mado

Date: 23 Jul, 2012 14:21:15

Message: 17 of 18

unfortunately i can't attach the simulink file
all what i need to do is tracking the maximum power of solar cell ,on the curve of power you should know it
using the method of perturb and observe increase see the flow chart to get it well
there is a point on the curve which will be maximum , the curve is a relation between voltage and power so i increase the volt with constant and observe the power to reach the max , if it pass the max i decrease it again with the same constant , with while loop or without .

vlast=vk;

   while pk <plast
       B=0.2
       p=pk-plast;
     
 if pk > plast % if power is increased
 
 vref = vlast+B*p; % increase
 elseif pk < plast if decreased
  vref = vlast-B*p decreased to return back to max



 end

   end

Subject: while loop is not excuted

From: Ioanna

Date: 23 Jul, 2012 14:33:25

Message: 18 of 18

When you type

while pk<plast,

do you expect the loop to be entered when the first element of pl is less than the first element of plast, AND the second element of pk is less than the second element of plast, AND etc...? If not, then when do you want the while loop to evaluate?

"mado " <elec_mnf@yahoo.com> wrote in message <jujmkr$die$1@newscl01ah.mathworks.com>...
> unfortunately i can't attach the simulink file
> all what i need to do is tracking the maximum power of solar cell ,on the curve of power you should know it
> using the method of perturb and observe increase see the flow chart to get it well
> there is a point on the curve which will be maximum , the curve is a relation between voltage and power so i increase the volt with constant and observe the power to reach the max , if it pass the max i decrease it again with the same constant , with while loop or without .
>
> vlast=vk;
>
> while pk <plast
> B=0.2
> p=pk-plast;
>
> if pk > plast % if power is increased
>
> vref = vlast+B*p; % increase
> elseif pk < plast if decreased
> vref = vlast-B*p decreased to return back to max
>
>
>
> end
>
> end

Tags for this Thread

No tags are associated with this thread.

What are tags?

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.

Contact us