0
|
21669 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# Why does thos code generate a recursion limit error?

Posted 9 years ago
 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 = 1000000; f[x_] := f[x] = f[x - 1]*1.05 - 41000; f Out= 1.1132*10^6 In:= f Out= 1.59795*10^6 
2 Replies
Sort By:
Posted 9 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 9 years ago
 The definition is recursive, f 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:= (* comm490447 *) Clear[f]; f = 1000000; f[x_Integer /; x > 0] := f[x] = f[x - 1]*1.05 - 41000 In:= f /@ Table[o + 10^o, {o, 0, 8}] During evaluation of In:=$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of 8983>0. >> During evaluation of In:= $RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of f. >> Out= {1.009*10^6, 1.12786*10^6, 2.69164*10^7, 3.2221*10^26, Hold[f], f, f, f, f} (* this quits the kernel because of RAM exhaustion *) Block[{$RecursionLimit = 10^8 + 9}, f /@ Table[o + 10^o, {o, 0, 8}]] In:= Block[{$RecursionLimit = 10^4 + 5}, f /@ Table[o + 10^o, {o, 0, 4}]] Out= {1.009*10^6, 1.12786*10^6, 2.69164*10^7, 3.2221*10^26, 1.7101*10^217} In:=$RecursionLimit Out= 1024