Re: Mathematical models for loop calculations
- From: Mike <m.fee@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 27 Sep 2007 14:23:18 +1200
In article <f72dnU8Dh4Rt5mfbnZ2dnUVZ8sCsnZ2d@xxxxxx>, rjh@xxxxxxxxxxxxxxx says...
Tim Frink said:Shouldn't that be: x + x+1 + x+2 + x+3 + x+4 + ... + x+n = n * ( n + 1 ) / 2 + n * x
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
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
.
- Follow-Ups:
- Re: Mathematical models for loop calculations
- From: Richard Heathfield
- Re: Mathematical models for loop calculations
- References:
- Mathematical models for loop calculations
- From: Tim Frink
- Re: Mathematical models for loop calculations
- From: Richard Heathfield
- Re: Mathematical models for loop calculations
- From: Tim Frink
- Re: Mathematical models for loop calculations
- From: Richard Heathfield
- Mathematical models for loop calculations
- Prev by Date: Re: Where does programming begin?
- Next by Date: Re: Mathematical models for loop calculations
- Previous by thread: Re: Mathematical models for loop calculations
- Next by thread: Re: Mathematical models for loop calculations
- Index(es):
Relevant Pages
|