Re: sum of recursive fn: solving for n
- To: mathgroup at smc.vnet.net
- Subject: [mg22174] Re: sum of recursive fn: solving for n
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Thu, 17 Feb 2000 01:24:05 -0500 (EST)
- Organization: Wolfram Research, Inc.
- References: <888afd$c7p@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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]
>
> tia,
> fiona
Here is a method that does not rely on an ability to solve recurrences.
(i) Define f[n] for positive integer values n.
(ii) Define the sum of these for nonnegative n.
(iii) Use interpolation to approximate a reasonable value for noninteger
positive values
(iv) Use a root-finder to solve the equation.
Clear[f,g,h]
f[1] = 2
f[n_Integer] /; n>1 := f[n] = 2*f[n-1]
g[0] = 0
g[n_Integer] /; n>=1 := g[n] = Sum[f[j], {j,1,n}]
g[x_Real] /; x>=0 := h[Floor[x]][x]
h[n_Integer] /; n>=0 := h[n] =
Interpolation[Map[{#,g[#]}&, Range[Max[0,n-4],n+4]]]
Some examples:
In[73]:= FindRoot[g[x]==62, {x,1,2}]
Out[73]= {x -> 5.}
In[74]:= sol = x /. First[FindRoot[g[x]==1129143342278080, {x,1,2},
WorkingPrecision->25, MaxIterations->100]]
Out[74]= 49.00431413459350937126090
We check that this was a very accurate solution.
In[75]:= g[sol] - 1129143342278080
-8
Out[75]= 0. 10
How does interpolation compare with the "actual" function 2^(x+1)-2?
In[76]:= g[sol] - 2^(sol+1)-2
11
Out[76]= -1.284160540929732817 10
Not too bad in this case, we are correct to around 5 places. And when
the actual solution is an integer we do alot better (because we do not
need interpolation then).
In[78]:= sol = x /. First[FindRoot[g[x]==2^51-2, {x,1,2},
WorkingPrecision->25, MaxIterations->100]]
Out[78]= 50.00000000000000000000000
Daniel Lichtblau
Wolfram Research