# Using NIntegrate inside RecurrenceTable

I'm trying to solve self-consistent equations of the form

RecurrenceTable[{d[n] == NIntegrate[(d[n - 1]/Sqrt[((1/3) + (2/9) (Cos[kx] + Cos[(kx + Sqrt[3] ky)/2] + Cos[(kx - Sqrt[3] ky)/2]))^2 + d[n - 1]^2]), {kx,0,4}, {ky,0,4}], d[0] == 1}, d, {n, 1, 10}]


However the above expression, when evaluated, produces the following error:

and the output:

{NIntegrate[d[(1 + 0) - 1]/
Sqrt[(1/3 +
2/9 (Cos[kx] + Cos[(kx + Compile$53) Compile$56] +
Cos[(kx - Compile$53) Compile$56]))^2 +
d[(1 + 0) - 1]^2], {kx, 0, 4}, {ky, 0, 4}],
NIntegrate[d[(1 + 1) - 1]/
Sqrt[(1/3 +
2/9 (Cos[kx] + Cos[(kx + Compile$53) Compile$56] +
Cos[(kx - Compile$53) Compile$56]))^2 +
d[(1 + 1) - 1]^2], {kx, 0, 4}, {ky, 0, 4}]}


Any help would be greatly appreciated, thank you!

• This doesn't use RecurrenceTable but d[0]=1; d[n_]:=d[n]=NIntegrate[d[n-1]/Sqrt[(1/3 +2/9(Cos[kx]+Cos[(kx+Sqrt[3] ky)/2]+Cos[(kx-Sqrt[3]ky)/2]))^2+d[n-1]^2],{kx,0,4},{ky,0,4}]; Table[d[i],{i,1,10}] instantly gives you your table of results without any errors.
– Bill
Commented Mar 18, 2020 at 4:49

Define NIntegrate... as a numerical function:

nint[uu_?NumericQ] :=
NIntegrate[(uu/Sqrt[((1/
3) + (2/9) (Cos[kx] + Cos[(kx + Sqrt[3] ky)/2] +
Cos[(kx - Sqrt[3] ky)/2]))^2 + uu^2]),
{kx, 0, 4}, {ky, 0,4}]

RecurrenceTable[{d[n] == nint[d[n - 1]], d[0] == 1}, d,
{n, 1, 10}]

(*   {15.1676, 15.9952, 15.9957, 15.9957, 15.9957,
15.9957, 15.9957, 15.9957, 15.9957, 15.9957}   *)


The same as @Bill got in his comment.