Graphics in While loop

Posted 1 year ago
1185 Views
|
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]] = 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??? Answer
3 Replies
Sort By:
Posted 1 year ago
 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]] = ... Answer
Posted 1 year ago
 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 Answer
Posted 1 year ago
 Thanks to your help, I made the code I wanted. Thank you very much. Attachments: Answer