Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.3K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Expected maximum Recursion depth of 5 dramatically exceeded

Posted 8 years ago

Please take a look at the following code and output

f[1] = 1;
f[2] = 2;
f[n_] := f[n - 2] + f[n - 1]
f[3]
Plot[f[n], {n, 1, 5}]

Out[]= 3

During evaluation of

$RecursionLimit::reclim2: Recursion depth of 1024 exceeded during evaluation of f[-2007.-2].

Please help

Thank you

Attachments:
POSTED BY: Peter Giesecke
4 Replies
Posted 8 years ago

Perfect hint, thank you so much

POSTED BY: Peter Giesecke

Plot passes real numbers (head Real) to f. Try evaluating f[0.5]. You might want to try DiscretePlot. It would also be a good idea to define f[n_]... with

f[n_Integer?Positive] :=  f[n - 2] + f[n - 1];

Be sure to ClearAll[f] first.

POSTED BY: Michael Rogers

The function f is defined only for integers greater or equal to 1, however Plot can sample any real coordinate in the plot range, which leads to a recursion similarly to f[1.].

Perhaps DiscretePlot[f[n], {n, 1, 5}] is more appropriate.

POSTED BY: Ilian Gachevski

Ilian,

Your post hadn't shown up when I posted mine, at least in my browser, or I wouldn't have answered. Not sure why it didn't since yours was ~2 hrs before mine.

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard