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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

control iteration

payman
13-Aquamarine

control iteration

Hello All,

My program, for some particular cases, spends too much time on a "genfit" function and finally stops calculation (regression doesn’t converge).

Is there a way to ask the program, that if it couldn't find the answer within a time interval (or limited number of iterations), forget about the particular case and continue to the next case?

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:payman)

PAYMAN RAJAI wrote:

Thank you Werner and Fred,

One last question; suppose the program is running for hundred cases for example. Is there a way to understand which case in under processing at the moment?

Yes, there is.

You can use either the trace() command in your program and turn on debug mode or you can use one of the write comands (WRITEPRN, WRITEEXCEL, ....) which writes the iteration number to a file.

Both methods will slow down calculation. In case of just hundred iteration where each one would take a lot of time the second method may have advantages, but you will have to compare yourself.

View solution in original post

6 REPLIES 6
Fred_Kohlhepp
23-Emerald I
(To:payman)

Since what you posted is clearly an excerpt, we can only guess; have you tried "on error"?

Werner_E
24-Ruby V
(To:payman)

PAYMAN RAJAI wrote:

Hello All,

My program, for some particular cases, spends too much time on a "genfit" function and finally stops calculation (regression doesn’t converge).

Is there a way to ask the program, that if it couldn't find the answer within a time interval (or limited number of iterations), forget about the particular case and continue to the next case?

Unfortunately you can neither set a time limit nor a limit for the iteration steps. You will have to code a routine like genfit yourself to be able to implement that feature.

But as Fred already has suggested you can use the on error statement to avoid that your complete calculation routine fails without any result at all just because one case throws an error.

payman
13-Aquamarine
(To:Werner_E)

Thank you Werner and Fred,

One last question; suppose the program is running for hundred cases for example. Is there a way to understand which case in under processing at the moment?

Werner_E
24-Ruby V
(To:payman)

PAYMAN RAJAI wrote:

Thank you Werner and Fred,

One last question; suppose the program is running for hundred cases for example. Is there a way to understand which case in under processing at the moment?

Yes, there is.

You can use either the trace() command in your program and turn on debug mode or you can use one of the write comands (WRITEPRN, WRITEEXCEL, ....) which writes the iteration number to a file.

Both methods will slow down calculation. In case of just hundred iteration where each one would take a lot of time the second method may have advantages, but you will have to compare yourself.

payman
13-Aquamarine
(To:Werner_E)

Thank you Werner,

I am using Mathcad 14 and it is unable to read and write excel files. Is it possible to have the equivalent version of the attached program so it does the same job (export the final results) in Mathcad14 ?

Thanks again

Werner_E
24-Ruby V
(To:payman)

I am not sure what I am supposed to see in this program and I am confused.

All you want to achieve is to write a single number (from 0 .. 100) in a file so you can look at it while Mathcad continues to calculate. If WRITEXCEL is not available you can use any of the other WRITE... commands, like WRITECSV, WRITEPRN or WRITEBIN. You'd use a small editor to read that number rather than fire up Excel.

I am not sure why you want to see that number anyway.

In case this is a new question and you are asking how to rewrite your routine to create an Excel file with the results of your calculations without using WRITEEXCEL, my advice would be to collect your result matrices in a vector, create a big matrix consisting of all the results and write this matrix via WRITECSV. Excel can cear it and convert to an Excel file.

Another way is to search for components which were posted here from time to time. As far as I remember Mike posted many times some scripted components which would read and write Excel files and should work in Mathcad14, too. One link Ijust stumbled over: http://communities.ptc.com/message/169861#169861

Top Tags