cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Nested while loops

kriley
1-Newbie

Nested while loops

Hello,

Is there a maximum number of nested while loops allowed in Prime 3.1?

Thank you,

Ken

21 REPLIES 21
RichardJ
19-Tanzanite
(To:kriley)

Not that I know of. Why do you ask?

Hello Richard,

I'm attempting to write an optimization  type program. I have 10 nested  while loops, each varying a variable. I get so far into adding the while statements then I get

"unknown error: mpl%_exception". I'm trying to find my error.

RichardJ
19-Tanzanite
(To:kriley)

Unfortunately, because the worksheet is in Prime 3.1 format I can't read it. I can nest more than 10 while loops in Prime 3.0 though:

Werner_E
24-Ruby V
(To:kriley)

Unfortunately I can't read P31 files as well. Maybe you could provide a pdf print of your worksheet.

Did you follow your program immediately by an evaluation?

You may try to change this and do as Richard had done - assign the output to a variable and later evaluate that variable.

Inline evaluation can sometimes have unwanted effects.

WE

Hello Werner,

How do I provide a pdf of the worksheet?

Werner_E
24-Ruby V
(To:kriley)

Ken Riley wrote:

Hello Werner,

How do I provide a pdf of the worksheet?

Its not a feature of Prime to do so. You would need a third party pdf-Printer (like Adobe-PDF, PDF-factory, ...) installed. A pretty good free pdf-Printer is Cute-PDF.

If your file is not that big, a screenshot may suffice.

If you are able to post the file itself you should do so. That way at least those of us having P31 installed can have a look at it and maybe provide the pdf, if you can't.

To attach a file chose "Use advanced editor" at the upper right and then "Attach" at the lower right.

WE

Werner,

I have attached a pdf of the file.

Werner_E
24-Ruby V
(To:kriley)

Hmmm - having the file itself to play with sure would help, but I could not Open your 3.1 file anyway.

I guess R.HMIN is a global constant, not a matrix. Which unit?

I must confess that the error "unknown error: mpl%_exception" at the very first assignment really looks a bit strange.

have you tried to trace back the error?

WE

BTW, its not necessary to create separate variables inside of the program. I guess the suffix means "program". You can use the original names When first USED (RHS of an assignment) the value of the global, worksheet variable is used, but when the name is used on the LHS of an assignment, a local variable is created. So any changes you do do not affect the worksheet variables.

Werner,

Yes, the R.HMIN is a global constant with units of inch.

I have not tried to trace back the error. I do not know how. You are correct that the suffix means program.

How do I trace back the error?

Ken

RichardJ
19-Tanzanite
(To:kriley)

It's going to be impossible to debug such a large program using only a pdf!

I understand. By trace back the error, is there a procedure or sequence for tracing back the error? Do you pull everything out one line at a time until you do not have the error?

RichardJ
19-Tanzanite
(To:kriley)

Unfortunately, in Prime there's no way to trace an error within a program. So, yes, the only real approach is to take pieces out until it works.

Thank you Richard and Werner for you assistance. I'll start redoing it on While statement at a time until I find when the error is occurring.

Again, thank you very much for you help and I'll mark your answer on the number of nest allowed correct, Richard.

Ken.

StuartBruff
23-Emerald II
(To:RichardJ)

Richard Jackson wrote:

Unfortunately, in Prime there's no way to trace an error within a program. So, yes, the only real approach is to take pieces out until it works.

What about the "Trace" group within the Calcuation ribbon?

Another way that I use is to add on error (or try statements in Prime) where I think the failures might be occuring.

Stuart

RichardJ
19-Tanzanite
(To:StuartBruff)

What about the "Trace" group within the Calcuation ribbon?

Does that trace within a program? I thought it would only trace at the worksheet level, but I admit I have not played with it much.

Werner_E
24-Ruby V
(To:kriley)

Just some thoughts:

You define a lot of local functions in the inner loop. You may consider to define those function right at the beginning of the program before the first loop or even on worksheet level. But I guess you may get rid of most of those functions and simply store the calculation result in a normal variable.

I think it would be a matter of better readability if you turn your while-loops into for-loops. You seem to simply add a constant at the end of each loop so the number of loops is the same every time. A for-loop is more compact and less failure prone.

I am confused about your variable names. The condition in your while loops use the variables with a "p" at the end, but those variables never get a new value. So you would end up with endless loops anyway. All you change at the end of each loop is a variable with "..incr" and not "...incrp".

So it looks to me that you confused yourself with all those different but similar variable names and created a nested set of endless loops. Primes error message could be the answer to this - not sure, though.

WE

StuartBruff
23-Emerald II
(To:Werner_E)

I wonder if a Solve Block might not be more appropriate?

Stuart

I must admit that I didn't look closely as to whats happening in the inner loop. I just noticed a myriad of local functions and then, that Ken had created a bunch of endless loops which may be the cause of the error he is experiencing.

I haven't tried to find out what the purpose of the program is but chances are good that you are right and a solve block could do this job much better.


Werner

Hello Werner,

I've been away from this project for awhile but I am now getting back to it. I corrected the .incrp increment issue you mentioned. This did not help with the error.

What I'm trying to do is create a series of equations which are based on specific variable inputs. Calculating the variables minimum and maximum values then increment each variable from its minimum thru maximum values. As the program goes thru its iterations, I want to find what set of variables produce the highest value for a specific out put such as torque or weight or size. I've gone back and studied the use of "while loops" but I'm still missing something. Any thoughts? Is there a better approach?

Ken

RichardJ
19-Tanzanite
(To:kriley)

Create an equation for torque (or weight, or size) as a function of all the variables you wish to adjust. Then use the "maximize" function to find the values of the variables that give the highest torque. If you wish to constrain a variable to a certain range use maximize with a solve block that contains constraints. There are examples in the help.

LucMeekes
23-Emerald III
(To:kriley)

Since you know over what range your input variables will vary, try to use a Monte Carlo approach. See Re: Minimize function strange result

Success!
Luc

Top Tags