6
$\begingroup$

I want to know the formula for the general term of the following recurrence system. I guess it can be written with Floor or Mod. How can I find it?

RSolve[{a[n + 5] == a[n] + 6, a[1] == 1, a[2] == 3, a[3] == 2, a[4] == 1, a[5] == 1}, a[n], n]

DiscretePlot[-2 + (6 n)/5 + 
  2/5 Sqrt[28 + 53/Sqrt[5]] Sin[(2 n π)/5 - ArcTan[15/Sqrt[85 + 38 Sqrt[5]]]] + 
  2/5 Sqrt[28 - 53/Sqrt[5]] Sin[(4 n π)/5 - ArcTan[3 Sqrt[5 (85 + 38 Sqrt[5])]]],
 {n, 1, 20}]

Updated

I would like to have the formula for the general term without using recursion just as

RecurrenceTable[{y[n + 5] == y[n] + 1, 
  Sequence @@ Table[y[i] == i, {i, 5}]}, y, {n, 1, 30}]

can be written

n - 4 Floor[(n - 1)/5] /. n -> Range@30
$\endgroup$
3
  • $\begingroup$ Not sure how to obtain this programmatically, but it is b[n_] := 6*(n - Mod[n, 5, 1])/5 + {1, 3, 2, 1, 1}.Map[DiscreteDelta, Mod[n, 5, 1] - Range[5]] $\endgroup$ Commented Jan 23, 2013 at 15:52
  • 1
    $\begingroup$ @Daniel Please use backticks to offset code in comments. Thanks. $\endgroup$
    – Mr.Wizard
    Commented Jan 23, 2013 at 17:39
  • $\begingroup$ I am curious about the reason for the edit, because although it suggests you are getting recursive formulas in the answers, none of the (three) replies so far use recursion. $\endgroup$
    – whuber
    Commented Jan 23, 2013 at 18:22

4 Answers 4

5
$\begingroup$

The argument of DiscretePlot is the sum of a linear function and explicitly periodic functions (Sin). The periodicity can be expressed by the relationship

$$\sin(x) = \sin(\text{mod}(x, 2\pi)).$$

Whence, because $n$ is multiplied by $2\pi/5$ where it appears within the arguments of $\sin$, you can reduce the evaluation of the argument to values of $n$ between (say) $1$ and $5$ via the replacement

g = f /. Sin[x_] -> Sin[Mod[x, 2 \[Pi]]]

where f represents the function. Noting that $n$ always appears divided by $5$, we can further simplify it by expressing $n$ in the form $5m + j$, $j=0, 1, 2, 3, 4$:

FullSimplify[g /. n -> 5 m + # , Assumptions -> m \[Element] Integers] & /@ Range[0, 4]

{-5 + 6 m, 1 + 6 m, 3 + 6 m, 2 + 6 m, 1 + 6 m}

Because $m = \text{floor}\frac{n-1}{5}$ and the remainder is given by Mod, we can now proceed to write a formula in terms of Floor and Mod.

However, none of this manipulation is necessary. The first line in the question exhibits a as a sum of a linear function (with slope $6/5$) and a periodic function of period $5$ defined by the values of $n$ from $1$ through $5$. Both Mod and Floor naturally work with periods starting at $0$, whence we need to (a) offset Mod by $1$ and (b) subtract $1$ from $n$ before dividing by $5$ and applying Floor. This immediately leads to the solution

a[1] = 1; a[2] = 3; a[3] = 2; a[4] = 1; a[5] = 1;
a[n_] /; n > 5 := a[Mod[n, 5, 1]] + 6 Floor[(n - 1)/5];

Looking at DiscretePlot[a[n], {n, 1, 20}] shows this to be exactly the same as the trigonometric formula.

$\endgroup$
3
$\begingroup$

Pardon me of this is tautological but perhaps there will be some value to be found here.

Your sequence can be described as a linear recurrence:

LinearRecurrence[{1, 0, 0, 0, 1, -1}, {1, 3, 2, 1, 1, 7}, 50] // 
  ListPlot[#, Filling -> Bottom] &

Mathematica graphics

Seeding this with symbolic values a simple pattern is apparent:

LinearRecurrence[{1, 0, 0, 0, 1, -1}, {a, b, c, d, e, f}, 31];
% ~Drop~ 6 ~Partition~ 5 // Column

Mathematica graphics

{a, b, c, d, e, f} = {1, 3, 2, 1, 1, 7};

Table[
  With[{x = Quotient[n, 5]}, {b, c, d, e, f}[[1 + Mod[n, 5]]] - a x + f x],
  {n, -1, 48}
] // ListPlot[#, Filling -> Bottom] &

Mathematica graphics

The sequence is the same, though the index is offset by two.

Correcting that offset and converting this to a function:

fn[n_Integer] := {-5, 1, 3, 2, 1}[[1 + Mod[n, 5]]] + 6 Quotient[n, 5]

Array[fn, 50]
{1, 3, 2, 1, 1, 7, 9, 8, 7, 7, 13, 15, 14, 13, 13, 19, 21, 20, 19, 19, 25, 27,
 26, 25, 25, 31, 33, 32, 31, 31, 37, 39, 38, 37, 37, 43, 45, 44, 43, 43, 49,
 51, 50, 49, 49, 55, 57, 56, 55, 55}

Or:

fn[n_Integer] := {-5, 1, 3, 2, 1}[[1 + #2]] + 6 # & @@ QuotientRemainder[n, 5]
$\endgroup$
2
$\begingroup$

Also:

y[n_] := Ceiling[6/5 n] + Switch[Mod[n, 5], 0, -5, 1, -1, 2, 0, 3, -2, 4, -4];
$\endgroup$
2
$\begingroup$

Also:

fn[n_] := 6 Floor[(n - 1)/5] + Mod[2 n^4 + 3 n^3 + 3 n^2 + 2 n + 1, 5]
Array[fn, 30]
DiscretePlot[fn[n], {n, 30}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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