Group Abstract Group Abstract

Message Boards Message Boards

0
|
75 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:
GROUPS:

How to calculate the 100th term of this recurrence relation?

Posted 4 days ago
RecurrenceTable[{a[1] == 1, a[n + 1] == a[n] - a[n]^2/3}, 
      a, {n, 100}][[-1]]

Why are both code snippets below running so slowly when calculating the 100th term? They’ve been running for a long time without any results. How can I fix this?

Nest[# - #^2/3 &, 1, 99]
POSTED BY: Bill Blair
2 Replies

I suppose that the calculation is slow because the a[n] are rational numbers of very rapidly increasing complication:

Map[ByteCount,
 RecurrenceTable[{a[1] == 1, a[n + 1] == a[n] - a[n]^2/3},
  a, {n, 20}]]
POSTED BY: Gianluca Gorni

Try:

RecurrenceTable[{a[1] == 1.0, a[n + 1] == a[n] - a[n]^2/3},  a, {n, 100}][[-1]] // AbsoluteTiming
(*{0.0003556, 0.0283592}*)

A[1] := 1.0;
A[n_] := A[n] = A[n - 1] - A[n - 1]^2/3;
A[100] // AbsoluteTiming
(*{0.0007379, 0.0283592}*)
POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard