Re: Mathematical models for loop calculations



In article <f72dnU8Dh4Rt5mfbnZ2dnUVZ8sCsnZ2d@xxxxxx>, rjh@xxxxxxxxxxxxxxx says...
Tim Frink said:

On Wed, 26 Sep 2007 13:46:20 +0000, Richard Heathfield wrote:

<snip>

Overall:

a += I;
b = pow(2, I);
c = pow(2, pow(2, I));
d = I * (I + 1) /2 + 1;
e += I;

I just see that these cases work since most of the variables
were assigned the value '2'. If you change them to '3', some
formulas like the one for 'b' will not work any more.

Correct.

Are there also any general formulas that depend on the current
value of the identifiers before entering the loop?

Sometimes, yes. For example, b = b * pow(2, I - 1); (and although I haven't
checked it out, a similar technique probably exists for c). a and e are
the same. d can be done, too, with thought and care. Hint: x + x+1 + x+2 +
x+3 + x+4 + ... + x+n = n * (n + 1) / 2 - x

Shouldn't that be: x + x+1 + x+2 + x+3 + x+4 + ... + x+n = n * ( n + 1 ) / 2 + n * x
or = n * ( n + 1 + 2 * x ) / 2.

And the formula for b will be something like b = B0 * power( 2, n) were B0 is the starting value for b.
Similarly c = power( C0, power( 2, n)) with C0 as the starting value for c.

As an obs-puzzle, is there a simple function f(x,i), (and starting values for i and x) for which looping n times
through
i := i+1;
x = f(x,i);
will end up with x = power(3,n)?


Mike
.



Relevant Pages

  • Re: stopping a loop
    ... Quote- "You can also use this technique to have a loop that runs prior to ... > animations and slide advances are timed to advance without user input. ... hide all the slides NOT in the looping section. ...
    (microsoft.public.powerpoint)
  • Re: looping in c language
    ... # a pattern of plume dispersion in an unstable atmosphere, in which the plume undergoes marked vertical oscillations as it is alternately affected by rising convective plumes and the subsiding motions between the plumes. ... Looping can also occur as the result of a skipped stitch. ... hackers "leap frog" or loop through several computer systems before finally going into the system they actually intend to attack. ... the recordings were made sequentially on a roll and later manually synched to picture. ...
    (comp.programming)
  • Re: Using DataReader to count rows
    ... The loop you have there does work. ... beforehand so that it end up not working, but that technique in general will ... > here helped me to realize the performance advantage of using data reader. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: wavread, performance due to memory allocation
    ... this technique is known as preallocation. ... Rather than forcing MATLAB ... to allocate more memory for a growing array each time through the FOR loop, ... preallocation forces MATLAB to allocate memory once before the FOR loop, ...
    (comp.soft-sys.matlab)
  • Re: Loop to run macro each tow
    ... It is a lot of looping to make sense of! ... Sheet named Base ... I would like if possible a loop on the sheet bases with macro Ci below. ... Dim A As Integer, B As Integer, C As Integer ...
    (microsoft.public.excel.programming)