# Solving recurrence equation with variable $x$

Please I want to solve this recurrence equation

$$p_n(x)=\frac{1}{x}\left[\frac{n\;}{\sqrt{2 n-1} \sqrt{2 n+1}}p_{n-1}(x)+\frac{(n+1)}{\sqrt{2 n+1} \sqrt{2 n+3}}p_{n+1}(x)\right]$$

$$x$$ is a variable

 RSolve[{p[n,x]==(1/x)(((n p[n-1,x])/(Sqrt[2n+1]Sqrt[2n-1]))+(((n+1)p[n+1,x])/(Sqrt[2n+1]Sqrt[2n+3]))),p[0,x]==1},p[n,x],n]


to find automatically $$p_1(x)$$, $$p_2(x)$$, $$p_3(x)$$, ...

• You need one more constraint (initial condition). This is an order-2 system, so you need two starting values. Commented Jul 7, 2019 at 13:29

The change of variables $$p\to\sqrt{2n+1}p$$ makes the equation into Legendre's equation:

p[n, x] == (1/x) (((n p[n - 1, x])/(Sqrt[2 n + 1] Sqrt[2 n - 1])) + (((n + 1) p[n + 1, x])/(Sqrt[2 n + 1] Sqrt[2 n + 3]))) /. p[n_, x] -> Sqrt[2 n + 1] p[n, x] // FullSimplify[#, n > 0] & //TeXForm


$$n p(n-1,x)+(n+1) p(n+1,x)=(2 n x+x) p(n,x)$$ with solution

RSolve[{-n p[-1 + n] + (x + 2 n x) p[n] - (1 + n) p[1 + n] == 0, p[0] == 1, p[1] == x}, p[n], n]
(* {{p[n] -> LegendreP[n, x]}} *)


Therefore, $$\sqrt{2n+1} P_n(x)$$

Table[Sqrt[2 n + 1] LegendreP[n, x], {n, 0, 4}] // Simplify // TableForm // TeXForm


$$\begin{array}{c} 1 \\ \sqrt{3} x \\ \frac{1}{2} \sqrt{5} \left(3 x^2-1\right) \\ \frac{1}{2} \sqrt{7} x \left(5 x^2-3\right) \\ \frac{3}{8} \left(35 x^4-30 x^2+3\right) \\ \end{array}$$ in agreement with Roman's answer.

• Yes indeed it is @AccidentalFourierTransform, Thank you. Commented Jul 7, 2019 at 14:42

In the absence of a closed-form solution, you can construct a recurrence table:

RecurrenceTable[{p[n] == ((n*p[n-1])/Sqrt[(2n-1)(2n+1)] + ((n+1)*p[n+1])/Sqrt[(2n+1)(2n+3)])/x,
p[0] == 1, p[1] == x*Sqrt[3]},
p[n], {n, 0, 10}] // Expand


{1, Sqrt[3] x, -(Sqrt[5]/2) + (3 Sqrt[5] x^2)/2, -((3 Sqrt[7] x)/2) + ( 5 Sqrt[7] x^3)/2, 9/8 - (45 x^2)/4 + (105 x^4)/8, (15 Sqrt[11] x)/8 - ( 35 Sqrt[11] x^3)/4 + (63 Sqrt[11] x^5)/8, -((5 Sqrt[13])/16) + ( 105 Sqrt[13] x^2)/16 - (315 Sqrt[13] x^4)/16 + (231 Sqrt[13] x^6)/ 16, -((35 Sqrt[15] x)/16) + (315 Sqrt[15] x^3)/16 - ( 693 Sqrt[15] x^5)/16 + (429 Sqrt[15] x^7)/16, (35 Sqrt[17])/128 - ( 315 Sqrt[17] x^2)/32 + (3465 Sqrt[17] x^4)/64 - (3003 Sqrt[17] x^6)/ 32 + (6435 Sqrt[17] x^8)/128, (315 Sqrt[19] x)/128 - ( 1155 Sqrt[19] x^3)/32 + (9009 Sqrt[19] x^5)/64 - ( 6435 Sqrt[19] x^7)/32 + (12155 Sqrt[19] x^9)/ 128, -((63 Sqrt[21])/256) + (3465 Sqrt[21] x^2)/256 - ( 15015 Sqrt[21] x^4)/128 + (45045 Sqrt[21] x^6)/128 - ( 109395 Sqrt[21] x^8)/256 + (46189 Sqrt[21] x^10)/256}

• Thank you very much @Roman for your answer, sorry I forgot that p[1] == Sqrt[3] x. Commented Jul 7, 2019 at 13:40
• Yes, that's it! Thank you again. Commented Jul 7, 2019 at 13:52