Message Boards Message Boards

0
|
2414 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Graphics in While loop

Posted 3 years ago
While[xop[[i]] > xq, 
          xop = Append[xop, yop[[i]]/(\[Alpha]m + (1 - \[Alpha]m)*yop[[i]])]; 
          yop = Append[yop, R/(R + 1)*xop[[i + 1]] + xd/(R + 1)]; 
          pv[[i]] = 
           Graphics[
            Line[{{xop[[i + 1]], yop[[i]]}, {xop[[i + 1]], yop[[i + 1]]}}]];
          ph[[i]] = 
           Graphics[Line[{{xop[[i]], yop[[i]]}, {xop[[i + 1]], yop[[i]]}}]]; 
          n = i; i++];

Hello, I'm creating a function for McCabe-Thiel method. I want to use Graphics in While loop to store plots in list. But I can't save it on the list. I'd like to know if there is another way. (English may be a little awkward because I am not from America.)

To give you an easier example:

pr = {}; i = 1; While[i > 4, 
 pr = AppendTo[pr, Graphics[Line[{{i, i}, {i + 1, i + 1}}]]]]

result : pr={}

Why???

POSTED BY: Oh Woongryeol
3 Replies

You have i initialized to 1. The loop condition is while i > 4. I don't believe it will execute.

Also, if you know in advance how many graphics you will create, then use Table to initialize your array and simply make assignments instead of the more costly Append.

pr = Table[{}, numberOfGraphs];
While[ ...
    pr[[k]] = ...
POSTED BY: Richard Frost

Thanks to your help, I made the code I wanted. Thank you very much.

Attachments:
POSTED BY: Oh Woongryeol

Thank you very much for your reply. I cannot specify the number of graphics to generate. but I'll try based on what you said

POSTED BY: Oh Woongryeol
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract