Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Iteration limit of a For or While Loop

dfehr
1-Visitor

Iteration limit of a For or While Loop

Mathcad 14 m030

Is there a limit to the number of iterations allowed for a For or While Loop? I have a program which works properly until I request more than 999 iterations within my For Loop.

Thanks for your assistance
DJF
17 REPLIES 17


No, there is no limit. Mayby there's something odd in your program.
Can you post the worksheet, preferrably saved as a Mathcad version 11 .MCD file (to broaden the audience), so we can have a look.


Luc

Attached is a trivial example which does not work if the number of iterations is greater than 999.

Thanks,
DJF

On 7/2/2009 4:16:54 PM, djfehr wrote:
>Attached is a trivial example
>which does not work if the
>number of iterations is
>greater than 999.
>
>Thanks,
>DJF
____________________________________

Your example is not an iterative loop, simply a running sum. For your particular setup example, the verified limit in 11 is (4096�-1). An iterative process is one that tends to converge to a solution, for instance the numerical Romberg integration. In that case, if the solution "oscillates" for too many cycles and can't meet TOL (default or user), the message "Does not converge" appears.

jmG

Jean,

"To iterate" means "to repeat".
This means that the concept of iteration stands irrespective of the question whether the result converges or not. Of course in many cases in mathematics the concept is used to find an answer (when the iteration converges). But even if it does not converge, it is still called iteration.

In mathcad 11 the for-loop can iterate past 4096^2. The upper limit is 10^9. I can iterate from 1 to 10^9, but when I set the upper limit to (10^9)+1, or start at 0, I get an error message: "Can't understand the way this range variable is defined.". This message leads me to that there is no upper limit on the for-loop, but on a range definition.

Regards.
Luc

from http://dictionary.reference.com/browse/iteration

1. the act of repeating; a repetition.
2. Mathematics.
a. Also called successive approximation. a problem-solving or computational method in which a succession of approximations, each building on the one preceding, is used to achieve a desired degree of accuracy.
b. an instance of the use of this method.
3. Computers. a repetition of a statement or statements in a program.

>In mathcad 11 the for-loop can iterate past 4096^2. The upper limit is 10^9. I can iterate from 1 to 10^9, but when I set the upper limit to (10^9)+1, or start at 0, I get an error message: "Can't understand the way this range variable is defined.". This message leads me to that there is no upper limit on the for-loop, but on a range definition.

Regards.
Luc
____________________________

Thanks Luc,

I missed to specify 4096^2-1 applies to an export, like filling an array of 4096 x 4096 or 4096^2-1 for a vector. Robert showed a method to override this limit. I like the definition "solving by successive approximations". In some cases, the built-in method will fail and the user will have to use a personal method like the seeded root scanner or other method to ramp as far as possible on a near vertical asymptote to override a bit more the "Can't converge to a solution".

Jean
dfehr
1-Visitor
(To:dfehr)

I now believe this is a bug in Mathcad14 when you use an inline evaluation (equals) of an expression. See attachment...

DJF
RichardJ
19-Tanzanite
(To:dfehr)

That's a bug alright.

Richard

In version 11 there is no problem, even going to 1,000,000. But then, there is no inline evaluation in version 11. I bet in version 14 you could go up that high (and futher) as well. You second example shows there is no problem looping past 999.
Why would you want to use an inline evaluation in a program?

Luc

I think it is one bug in Mathcad... 11 too.
We can not change the parameter ot the for-cycle (i) in the body of the for-cycle
Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm

On 7/3/2009 12:53:00 AM, VFO wrote:
>I think it is one bug in
>Mathcad... 11 too.
>We can not change the
>parameter ot the for-cycle (i)
>in the body of the for-cycle

Mathcad 2001 does not accept modifying the loop variable in the body of the loop... but it accepts a for that has no control variable 🙂
In this case just skips the body.
StuartBruff
23-Emerald III
(To:Al2000)

On 7/3/2009 2:02:29 PM, Al2000 wrote:
On 7/3/2009 12:53:00 AM, VFO wrote:
>I think it is one bug in Mathcad... 11 too.
>We can not change the parameter ot the for-cycle (i) in the body of the for-cycle

Well, we can in M14, with restrictions. See below.

== Mathcad 2001 does not accept modifying the loop variable in the body of the loop... but it accepts a for that has no control variable 🙂
In this case just skips the body.

M11 and M14 do so allow. M14 has, IMO, better behaviour in that it exits the loop with the last value of the control variable.

On balance, I prefer the M14 behaviour to being able to modify the range of values that it can take, ie each iteration should take the 'next' value from the iteration sequence and should not 'update' the iteration variable so as to skip values.

Stuart

On 7/3/2009 2:02:29 PM, Al2000 wrote:
>On 7/3/2009 12:53:00 AM, VFO wrote:
>>I think it is one bug in
>>Mathcad... 11 too.
>>We can not change the
>>parameter ot the for-cycle (i)
>>in the body of the for-cycle
>
>Mathcad 2001 does not accept modifying
>the loop variable in the body of the
>loop... but it accepts a for that has no
>control variable 🙂
>In this case just skips the body.
__________________________________

I believe neither of the comments.
Try that, it works in Mathcad 8.



jmG




On 7/3/2009 4:32:24 PM, jmG wrote:
>On 7/3/2009 2:02:29 PM, Al2000 wrote:
>>On 7/3/2009 12:53:00 AM, VFO wrote:
>>>I think it is one bug in
>>>Mathcad... 11 too.
>>>We can not change the
>>>parameter ot the for-cycle (i)
>>>in the body of the for-cycle
>>
>>Mathcad 2001 does not accept modifying
>>the loop variable in the body of the
>>loop... but it accepts a for that has no
>>control variable 🙂
>>In this case just skips the body.
>__________________________________
>
>I believe neither of the comments.
>Try that, it works in Mathcad 8.
>
>==================================

Try that too, it works in Mathcad 8.
The Mathcad ForLoop structure is lot more powerful than it looks, and that must be from very early days of the design. It goes backward too !



jmG




On 7/3/2009 4:50:42 PM, jmG wrote:
>On 7/3/2009 4:32:24 PM, jmG wrote:
>>On 7/3/2009 2:02:29 PM, Al2000 wrote:
>>>On 7/3/2009 12:53:00 AM, VFO wrote:
>>>>I think it is one bug in
>>>>Mathcad... 11 too.
>>>>We can not change the
>>>>parameter ot the for-cycle (i)
>>>>in the body of the for-cycle
>>>
>>>Mathcad 2001 does not accept modifying
>>>the loop variable in the body of the
>>>loop... but it accepts a for that has no
>>>control variable 🙂
>>>In this case just skips the body.
>>__________________________________
>>
>>I believe neither of the comments.
>>Try that, it works in Mathcad 8.
>>
>>==================================
>
>Try that too, it works in Mathcad 8.
>The Mathcad ForLoop structure is lot
>more powerful than it looks, and that
>must be from very early days of the
>design. It goes backward too !
>
>jmG
>+++++++++++++++++++++++++++++++++++

Try that backward Forloop too !
My ForLoop Structure work sheet is 18 pages.
It has never been posted or the very initial.



jmG




>The Mathcad ForLoop structure is lot more
>powerful than it looks
See too

Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm

On 7/4/2009 12:50:14 AM, VFO wrote:
>>The Mathcad ForLoop structure is lot more
>>powerful than it looks [jmG]

==> See too [Valery]
======================

See too +++ ... attached [jmG]
The TCF added (for use)
Sorry 14 users if some(s) turn red.

Salut Valery ! Jean



If you want to change the "i-value" in Cycles - use the cycle-while not for!

See the for cycle in SMath Studio too
http://en.smath.info/forum/default.aspx?g=posts&t=101
Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm
Announcements

Top Tags