Message Boards Message Boards


Graphics in While loop

Posted 1 year ago
3 Replies
2 Total Likes
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]] = 
            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={}


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]] = ...

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

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

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract