3
$\begingroup$

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]}]
$\endgroup$
  • 1
    $\begingroup$ Can you not add the code in plain text? This would make people more likely to help you. $\endgroup$ – J. M. will be back soon Oct 12 '15 at 14:25
  • 2
    $\begingroup$ Its from this answer. It does work for me :) $\endgroup$ – rhermans Oct 12 '15 at 14:40
  • 1
    $\begingroup$ @rhermans Notice that the code you added does NOT have the same starting conditions as the code the OP posted. I think therein lies the problem... $\endgroup$ – MarcoB Oct 12 '15 at 15:19
  • $\begingroup$ @MarcoB fixed, thanks! $\endgroup$ – rhermans Oct 13 '15 at 17:35
6
$\begingroup$

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
$\endgroup$
  • $\begingroup$ thanks for helping me, you really are a pro at this :) $\endgroup$ – Charles Oct 13 '15 at 23:20
3
$\begingroup$

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]
$\endgroup$

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.