3

I want to implement the Lucas n-Step Number.

This command taken from here doesn't seem to work, am I using the right command?enter image description here

ClearAll[LnStepN];
LnStepN[2, n_] = 0; LnStepN[1, n_] = 1; LnStepN[3, n_] = 1;

LnStepN[k_Integer, n_Integer] := 
 LnStepN[k, n] = Sum[LnStepN[k - i, n], {i, 1, Min[k, n]}]
Charles
  • 145
  • 1
  • 4

2 Answers2

6

Based on the definition from Wolfram Mathworld, the "Lucas n-Step Number" is define by:

ClearAll[LnStepN];
LnStepN[k_, n_] := -1 /; k < 0;
LnStepN[0, n_] = n;
LnStepN[1, n_] = 1;
LnStepN[k_Integer, n_Integer] := 
 LnStepN[k, n] = Sum[LnStepN[k - i, n], {i, 1, n}]

To verify the solution:

Table[
  LnStepN[k, n]
  , {n, 2, 7}
  , {k, 1, 12}
  ] // TableForm

Mathematica graphics

Now the requested 15th Lucas term in the 3rd order.

LnStepN[15, 3]
9327
rhermans
  • 36,518
  • 4
  • 57
  • 149
3

You can take a look at OEIS for more formulas: http://oeis.org/A001644

Lucas3[n_]:=Last[LinearRecurrence[{1, 1, 1}, {3, 1, 3}, n + 1]];

Lucas3[15]
(* 9327 *)

This is experimental, but seems to work:

Lucas[k_Integer, n_Integer]:=Last[LinearRecurrence[ConstantArray[1,k], Array[(2^#-1)&, k], n]];

Lucas[3, 15]