2
$\begingroup$

I have a recurrence relation with a complicated index pattern. However, even simple examples fail. For example, consider

RecurrenceTable[{a[n + 1] == a[n - Floor[Sqrt[n]]], a[0] == 1}, a, {n, 0, 10}]

This gives the error

"All arguments in position 1 of a[1+n]==a[n-Floor[Sqrt[n]]] should be in the form n + integer."

When I look at the type for Floor[Sqrt[n]], Mathematica tells me it is an integer, but it doesn't seem to recognize n-Floor[Sqrt[n]] as an integer. How can I use a function like Floor inside the indices for a recurrence table?

$\endgroup$
  • $\begingroup$ Isn't the answer just a[n]=1 for all n? $\endgroup$ – bill s Aug 11 '17 at 18:26
  • $\begingroup$ It might be for this one. This is just an simple example to see the error. $\endgroup$ – Trevor Aug 11 '17 at 18:27
2
$\begingroup$

I would not use RecurrenceTable for this... just define it recursively:

a[n_] := a[n - 1 - Floor[Sqrt[n - 1]]];
a[0] = 1;

You can verify that for this particular recursion, a[n]=1 for any n you care to chose. To see why RecurrenceTable does not work, note that the help says: "The eqns can involve objects of the form a[n+i] where i is any fixed integer." In this case, i is an integer, but it is not fixed.

$\endgroup$
  • $\begingroup$ This is a classic example of something not working until I ask about it. I did try what you suggested based on another answer, but I must have typed something wrong somewhere. It worked this time. The question still remains about why it won't work within RecurrenceTable. $\endgroup$ – Trevor Aug 11 '17 at 18:35
  • 1
    $\begingroup$ Looking at the help for RecurrenceTable, it says: "The eqns can involve objects of the form a[n+i] where i is any fixed integer." In your case, i is an integer, but it is not fixed. $\endgroup$ – bill s Aug 11 '17 at 18:44
  • $\begingroup$ @bills I'd include the contents of your last comment in your answer, as it seems very relevant to the original question as it had been posed. $\endgroup$ – MarcoB Aug 11 '17 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.