# Why does thos code generate a recursion limit error?

Posted 8 years ago
21109 Views
|
2 Replies
|
0 Total Likes
|
 It evaluates the function correctly. (Why would the recursion level exceed 30?) Generates a red box of error information.Thanks for helping! Clear[f]; f[0] = 1000000; f[x_] := f[x] = f[x - 1]*1.05 - 41000; f[10] Out[143]= 1.1132*10^6 In[144]:= f[30] Out[144]= 1.59795*10^6 
2 Replies
Sort By:
Anonymous User
Anonymous User
Posted 8 years ago
 Clearing the session with Quit [ ] and restarting made the problem go away. A fluke I can't explain. But all that ends well. . .
Posted 8 years ago
 The definition is recursive, f[30] evaluates here (Mathematica 10.1, Window 7 64 Bit Home Premium) without messages, but in general a big enough argument invokes the reclim message, if the $RecursionLimit is not set to Infinity (then RAM tends to become short) In[1]:= (* comm490447 *) Clear[f]; f[0] = 1000000; f[x_Integer /; x > 0] := f[x] = f[x - 1]*1.05 - 41000 In[4]:= f /@ Table[o + 10^o, {o, 0, 8}] During evaluation of In[4]:=$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of 8983>0. >> During evaluation of In[4]:= $RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of f[8983]. >> Out[4]= {1.009*10^6, 1.12786*10^6, 2.69164*10^7, 3.2221*10^26, Hold[f[8983]], f[100005], f[1000006], f[10000007], f[100000008]} (* this quits the kernel because of RAM exhaustion *) Block[{$RecursionLimit = 10^8 + 9}, f /@ Table[o + 10^o, {o, 0, 8}]] In[5]:= Block[{$RecursionLimit = 10^4 + 5}, f /@ Table[o + 10^o, {o, 0, 4}]] Out[5]= {1.009*10^6, 1.12786*10^6, 2.69164*10^7, 3.2221*10^26, 1.7101*10^217} In[6]:=$RecursionLimit Out[6]= 1024