2
$\begingroup$

Let we have simple recursive function:

Clear[recFun];
recFun[1, k_] := 1;
recFun[n_, 1] := 1;
recFun[n_, k_] := recFun[n, k - 1] + recFun[n - 1, k - 1];

recFun[2,3]
Out: 3

But this code not work:

Clear[rf]; RecurrenceTable[{rf[n, k] == rf[n, k - 1] + rf[n - 1, k - 1], 
      rf[1, k] == 1, rf[n, 1] == 1}, rf, {n, 1, 3}, {k, 1, 3}]

I've read this topic, but TS was answered how to do recursion. Why RecurrenceTable not work remained unclear.

$\endgroup$

1 Answer 1

5
$\begingroup$

This works:

Clear[rf]; 
RecurrenceTable[{rf[n, k] == 
    If[k >= 2 && n >= 2, rf[n, k - 1] + rf[n - 1, k - 1], 1], 
   rf[n, 1] == 1, rf[1, k] == 1}, rf, {n, 1, 5}, {k, 1, 5}] // Grid
1   1   1   1   1
1   2   3   4   5
1   2   4   7   11
1   2   4   8   15
1   2   4   8   16

This doesn't work:

Clear[rf];
RecurrenceTable[{rf[n, k] == 
    If[k >= 2 && n >= 2, rf[n, k - 1] + rf[n - 1, k - 1], 1], 
   rf[1, k] == 1, rf[n, 1] == 1}, rf, {n, 1, 5}, {k, 1, 5}] // Grid
$\endgroup$
0

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.