Re: calculate Recurrence Equations
- To: mathgroup at smc.vnet.net
- Subject: [mg68750] Re: [mg68713] calculate Recurrence Equations
- From: Adriano Pascoletti <pascolet at dimi.uniud.it>
- Date: Fri, 18 Aug 2006 03:11:52 -0400 (EDT)
- References: <200608170818.EAA24918@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 17 ago 2006, at 10:18, Frank Hechtner wrote: > hi, > > i?m in trouble with my Recurrence Equations: > > i?ve defined the following function > > anteil[0] = 1 > anteil[n_] := anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 > > i want mathematica to calculate the values for anteil[30] and so on. > > Unfortunately mathematica needs for this calculation over 2 hours (and > is still running, athlon x2 4600, 2 gb ram). > > I don?t see where are the difficulties for mathematica... Frank, Your definition is memoryless. Let's make a slight modification that adds memory (note the = on the right hand side): In[1]:= anteil[0] = 1; anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100 On an old 800MHz iMac it gives In[3]:= Timing[anteil[30]//InputForm] Out[3]= {0.004157 \ Second,4909085745117164100520051333566036654601/\ 1342177280000000000000000000000000000000} The same result via RSolve: In[10]:= ClearAll[anteil]; RSolve[{anteil[n]==anteil[n-1]+(anteil[n-1]*5-1)/100,anteil[0] ==1},anteil, n]//InputForm Out[11]//InputForm= {{anteil -> Function[{n}, (1 + 4^(1 - n)*(21/5)^n)/5]}} Extract the solution In[22]:= sol=%[[1,1,2]]; and compute sol[30] In[23]:= sol[30]//InputForm Out[23]//InputForm= 4909085745117164100520051333566036654601/ 1342177280000000000000000000000000000000 Hope it helps Adriano Pascoletti
- References:
- calculate Recurrence Equations
- From: Frank Hechtner <frank.hechtner@rub.de>
- calculate Recurrence Equations