# Defining a recurrence relation

How do I define the following recurrence relation in Mathematica?

$$q_0 = \sqrt{w + 2 \epsilon J},\ q_n = \frac{\epsilon\left(J_n q_0 + \sum\limits_{m=1}^{n-1} \left(J_{n-m} + J_{n+m}\right)q_m\right)}{\epsilon\left(2J - J_{2n}\right) +w}, n \geq 1$$

where $$J_n := |n|^{1+\alpha}$$ and $$J = 1$$ and $$\epsilon = 1$$ and $$w = 1$$.

Attempt:

J[n_, m_, \[Alpha]_] := 1/(n - m)^(1 + \[Alpha]);

q[n_, \[Epsilon]_, \[Alpha]_,
w_] := \[Epsilon] (J[n, 0, \[Alpha]]*q[0] +
Sum[(J[n, m, \[Alpha]] + J[n, -m, \[Alpha]])*q[m], {m, 1,
n - 1}])/(\[Epsilon] (2*1 - J[2*n, 0, \[Alpha]]) + w)

q[0, 1, 1, 1] = Sqrt[w + 2 \[Epsilon]];


However, this syntax is not correct. For example,

q[5, 1, 1, 1]


yields $$\frac{100}{299} \left(\frac{13 q(1)}{144}+\frac{58 q(2)}{441}+\frac{17 q(3)}{64}+\frac{82 q(4)}{81}+\frac{1}{25} \sqrt{w+2 \epsilon }\right)$$. This should be a number, but instead the symbolic representation is given. Why are the $$q(i)$$ not numbers?

Update: New relation. Mimicking the method in the Answer provided below, I obtain a sequence I do not expect.

$$g_0 = g_1= \sqrt{w+\epsilon(2J - J_1)},\ g_n = \frac{\epsilon\sum\limits_{m=1}^{n-1} \left(J_{n-m} + J_{n+m-1}\right)g_m}{\epsilon\left(2J - J_{2n-1}\right) + w}, n \geq 2$$

LatticeEndIndex = 10;
g[0, \[Epsilon]_, \[Alpha]_, w_] :=
Sqrt[w + \[Epsilon] (2 J[0, \[Alpha]] - J[1, \[Alpha]])]
g[1, \[Epsilon]_, \[Alpha]_, w_] :=
Sqrt[w + \[Epsilon] (2 J[0, \[Alpha]] - J[1, \[Alpha]])]
g[n_Integer?Positive, \[Epsilon]_, \[Alpha]_, w_] :=
g[n, \[Epsilon], \[Alpha],
w] = \[Epsilon]  Sum[(J[n - m, \[Alpha]] + J[n + m - 1, \[Alpha]])*
g[m, \[Epsilon], \[Alpha], w], {m, 1,
n - 1}]/(\[Epsilon]   (2*J[0, \[Alpha]] -
J[2*n - 1, \[Alpha]]) + w) // Simplify
offsiteSequence = g[#, 1, 1, 1] & /@ Range[0, LatticeEndIndex ]


This yields $$\left\{\sqrt{2},0,0,0,0,0,0,0,0,0,0\right\}$$ However, I expected this to be a sequence of non-zero values. In particular, since $$g_0 = g_1$$, then why is the second slot of the sequence vanishing?

• In the definition of onsiteSequence you used q where you presumably intended to use g Commented Jul 22 at 20:50
• @BobHanlon Thanks, and the main error I was having was that I had needed to use the Clear command to get rid of some interfering variables. Commented Jul 22 at 21:10

\$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global*"]

J[0, α_] = 1;

J[n_Integer?Positive, α_] := J[n, α] = Abs[n]^(1 + α);

q[0, ϵ_, α_, w_] := Sqrt[w + 2 ϵ  J[0, α]];

q[n_Integer?Positive, ϵ_, α_, w_] := q[n, ϵ, α, w] =
ϵ  (J[n, α]*q[0, ϵ, α, w] +
Sum[(J[n - m, α] + J[n + m, α])*
q[m, ϵ, α, w], {m, 1, n - 1}])/(ϵ  (2*J[0, α] - J[2*n, α]) + w) //
Simplify

q[5, 1, 1, 1]

(* (7633 Sqrt[3])/846131 *)

seq = q[#, 1, 1, 1] & /@ Range[0, 6]

(* {Sqrt[3], -Sqrt[3], (6 Sqrt[3])/13, -(1/(11 Sqrt[3])), 452/(
8723 Sqrt[3]), (7633 Sqrt[3])/846131, 2303090/(119304471 Sqrt[3])} *)

seq // N

(* {1.73205, -1.73205, 0.799408, -0.0524864, 0.0299166, 0.0156249, \
0.0111453} *)
`