# How to calculate this function using a recurrence relation?

I have a function as follows $$R_{nl}(r)=r^l e^{-\frac{\mu r}{n}}\sum_{j=0}^{n-l-1}b_j r^j \tag{1}$$ where $$b_{j+1}=\frac{2\mu}{n}\frac{j+l+1-n}{(j+1)(j+2l+2)}b_j \tag{2}$$ and $$b_0=2\mu^{3/2}$$ and $$\mu=1$$.

Now I want to write a code for calculating $$R_{nl}(r)$$. So I tried this

rvals = RecurrenceTable[{b[j + 1] == (2 \[Mu])/n ( j + l + 1 - n)/((j + 1) (j + 2 l + 2)) b[j], b == 2 \[Mu]^(3/2)}, b, {j, 0, n - 1}];
rvals2 = PrependTo[rvals, 2 \[Mu]^(3/2)];
rfun[n_, l_, r_] :=r^l Exp[-\[Mu] r/n] Sum[rvals[[j]] r^j, {j, 0, n - l - 1}]


but when I try for example

rfun[2, 1, r]


it doesn't give me the answer. It seems that the recurrence table needs to specify the initial values for $$n$$ and $$l$$, but I want to use  rfun[n, l, r] as a function in the next steps. Also I had tired

RSolve[{b[j + 1] == (2 \[Mu])/n (j + l + 1 - n)/((j + 1) (j + 2 l + 2)) b[j],
b == 2 \[Mu]^(3/2)}, b[j], j]


for recursion relation but this does not yield my desire result too. Any idea?

Clear["Global*"]


Using RSolveValue to find the closed-form expression for b

b[j_, l_, n_, μ_ : 1] =
RSolveValue[{b[
j + 1] == (2 μ)/n (j + l + 1 - n)/((j + 1) (j + 2 l + 2)) b[j],
b == 2 μ^(3/2)}, b[j], j] // FullSimplify

(* (2^(1 + j) μ^(3/2) (μ/n)^j Gamma[2 + 2 l] Gamma[1 + j + l - n])/(
Gamma[1 + j] Gamma[2 + j + 2 l] Gamma[1 + l - n]) *)

rfun[n_, l_, r_, μ_ : 1] =
r^l Exp[-μ r/n] Sum[b[j, l, n, μ] r^j, {j, 0, n - l - 1}]

(* 2 E^(-((r μ)/n)) r^l μ^(3/2)
Hypergeometric1F1[1 + l - n, 2 + 2 l, (2 r μ)/n] *)

rfun[2, 1, r]

(* 2 E^(-r/2) r *)

Plot[rfun[2, 1, r], {r, 0, 15}] • Thanks a lot man. It works. just one thing: why you entered $\mu$ as an argument of function? I want to specify it in the beginning my code as an input. Can I pull it out from arguments? Aug 11, 2021 at 16:28
• It is set to default to 1` if not entered as an argument. If you prefer you can define it at the top and eliminate it from the LHS of definitions. Aug 11, 2021 at 16:31