Re: calculate Recurrence Equations
- To: mathgroup at smc.vnet.net
- Subject: [mg68795] Re: calculate Recurrence Equations
- From: Peter Pein <petsie at dordos.net>
- Date: Fri, 18 Aug 2006 03:12:57 -0400 (EDT)
- References: <ec1a1u$omo$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Frank Hechtner schrieb: > 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... > > Thanx for your help > > frank > Hi Frank, Mathematika doesn't remeber the values it has alraedy calculated. So anteil[30] leads to 2^30 ~ 10^9 calls to anteil[]. If you store the calculated values, the calls to anteil[] are 31: In[1]:= anteil[0] = 1; anteil[n_] := anteil[n] = anteil[n - 1] + (anteil[n - 1]*5 - 1)/100; AbsoluteTiming[anteil[30]] Out[3]= {0.*Second, 4909085745117164100520051333566036654601/1342177280000000000000000000000000000000} But I prefer using RSolve[]: In[1]:= << "DiscreteMath`RSolve`" anteil = a /. First[RSolve[{a[0] == 1, a[n] == a[n - 1] + (a[n - 1]*5 - 1)/100}, a, n]] anteil[30] N[%] Out[2]= Function[{n}, (1/5)*(1 + 4^(1 - n)*(21/5)^n)] Out[3]= 4909085745117164100520051333566036654601/ 1342177280000000000000000000000000000000 Out[4]= 3.6575539001205297 HTH, Peter