MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sum of recursive fn: solving for n


On 14 Feb 2000, AC fiona wrote:

> what am i doing wrong here?
> 
> f[x_] := (f[x-1])*2
> f[1] =2
> Solve[Sum[f[x], {x, 1,n}] ==62, n]

You're doing the programmatic equivalent of beating a nail with a wrench.

Try using recursion to solve your problem.

In[1]:=
n = 1;
seedvalue = 2;
summation = 2;
NestWhile[
    (n++; term = 2 #; summation += term; term) &, 
    seedvalue, 
    (#; summation < 62) &
    ] ;
n

Out[1]=
5

-- 
P.J. Hinton
Mathematica Programming Group           paulh at wolfram.com
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.



  • Prev by Date: Re: Mathlink and packed arrays
  • Next by Date: postscript color trouble
  • Previous by thread: Re: sum of recursive fn: solving for n
  • Next by thread: Re: sum of recursive fn: solving for n