# Define a Recurrence Table involving other tables

I'm relatively new to using Mathematica. Previously I used Matlab, but lately I noticed that the numbers i got in both of them do not match (mostly it seems that Matlab lacks precision...).

The question is: I need a nested table defined recursively, and based on it I'll calculate what I actually need. But the code

L = RecurrenceTable[
{
a[i] == -M[[i - 1]].Inverse[Psi[[i - 1]] +
L[[i - 1]].Lambda[[i - 1]]],
a[2] == -M[[1]].Inverse[Psi[[1]]],
a[1] == {{0}};
},
a,
{i, 1, NN}
];


, where M, Psi and Lambda are nested tables themselves defined like

Psi = Table[Table[ __SOME FORMULAS__ , {i, 0, NN - n}, {j, 0, NN - n}], {n, 1, NN - 1}];
PrependTo[Psi, {{-c*P[NN]}}];


produces the following error:

Part::pspec: "Part specification -1+i is neither a machine-sized integer nor a list of machine-sized integers. "
RecurrenceTable::deqn: Equation or list of equations expected instead of Null in the first argument


Even though I did the same thing like in reference, but i got this error. And considering the performance of numeric calculations - how can I improve it for the code above?

I would really appreciate any help.

NN = N[4, 50];

p[i_, j_] = Binomial[2*NN - i + j, i + j];

Ψ =
Table[Table[\[Piecewise]p[n + i, n + j] i == j 1 True, {i, 0, 1}, {j, 0, 1}], {n, 0,
NN - 1}];

L = {{{1, 2}, {3, 4}}};
Do[AppendTo[L, Inverse[L[[i - 1]].Ψ[[i - 1]]]], {i, 2, NN}]
(*L=RecurrenceTable[{a[i]\[Equal]-M[[i-1]].Inverse[Ψ[[i-1]]+L[[i-1]].\
Λ[[i-1]]],a[2]\[Equal]-M[[1]].Inverse[Ψ[[1]]],a[1]\[Equal]{{0}}\
;},a,{i,1,NN}];*)

N[L, 5] // MatrixForm

• Look at the differences between = and := – barrycarter Oct 19 '14 at 23:35
• Those are immediate and delayed assignments. Is there any difference between them considering the "constant" values I should receive? (as all the parameters are predefined) – Andrew S. Oct 20 '14 at 9:21
• I'd like to take a further look at this: could you provide actual runnable code (using simple functions if you don't want to provide the originals)? In general, you can't use "=" when the right hand side is undefined, so you'd have to compute M, Psi, and Lambda first. – barrycarter Oct 20 '14 at 15:06
• The RecurrenceTable code gives the Recursion Depth error if I substitute "=" with ":=". – Andrew S. Oct 20 '14 at 18:13
• It's quite hard to remove the "extra" code... This is the maximum I could do (there are two versions inside comment): NN=N[4,50]; p[i_,j_]=Binomial[2*NN-i+j,i+j]; \[CapitalPsi]=Table[Table[\[Piecewise] p[n+i,n+j] i==j 1 True ,{i,0,1},{j,0,1}],{n,0,NN-1}]; L={{{1,2},{3,4}}}; Do[ AppendTo[ L,Inverse[L[[i-1]].\[CapitalPsi][[i-1]]] ], {i,2,NN} ] (*L=RecurrenceTable[ { a[i]\[Equal]-M[[i-1]].Inverse[\[CapitalPsi][[i-1]]+L[[i-1]].\[CapitalLambda][[i-1]]], a[2]==-M[[1]].Inverse[\[CapitalPsi][[1]]], a[1]\[Equal]{{0}}; }, a, {i,1,NN} ];*) N[L,5] // MatrixForm How should I paste the code here? – Andrew S. Oct 20 '14 at 18:50

I should've mentioned this earlier, but, instead of RecurrenceTable try defining your recursions like this (using Fibbonaci numbers as an example):

fib[0] = 1;
fib[1] = 1;
fib[n_] := fib[n] = fib[n-1] + fib[n-2];


When you do fib[6] (for example), it will fib[6] and remember the value, making future recursions faster.

It also means you can nest recursions, since everything will be computed on an "as needed" basis.