# How to directly define a function as the solution of RSolve

This is probably very simple, but I just cannot find this anywhere online. I have the code

Y1[m_,n_,r_] := FullSimplify[RSolve[{A[m,n,r] == (-m-m*(r/n)*(n-m))*A[m-1,n,r] - m*(r/n)*(m-1)*(n-m+1)*A[m-2,n,r], A[0,n,r]==1, A[1,n,r]==-1-((r/n)*(n-1))}, A[m,n,r], {m,n,r}]]


I think it is clear what I am trying to do: I hope to get a function Y1 that solves this recurrence. If I run this line and then write something like

Y1[m, n, r]


I get

{{A[m,n,r]->(E^(-(n/r)) (r/n)^m Gamma[1+m] ((E^(n/r) r+n ExpIntegralE[n,-(n/r)]) Gamma[1+m-n]+n^2 (-(n/r))^m ExpIntegralE[-m+n,-(n/r)] Gamma[-n]))/(r Gamma[1-n])}}


This is not what I had hoped. I want Y1 to be my function, but now A is the function I want. However, I cannot just use A either, since it just seems to be some intermediate function and it is not defined.

How can I get the function in m,n,r that is the solution of my RSolve?

• Try: Y1[m_, n_, r_] := A[m, n, r] /. FullSimplify[.... Apr 26, 2023 at 7:32
• Thank you for your comment @DanielHuber. It sadly doesn't seem to work, but it almost does, so I might be doing something wrong or maybe my question wasn't clear. It seems if I execute the line you mention that Y1 is still 'in between brackets', if that makes sense. If I try for example Y1[2.01,2.01,1] then I am getting the error "RSolve::dsvar: 2.01 cannot be used as a variable." Apr 26, 2023 at 7:50
• replace RSolve with RSolveValue?
– kglr
Apr 26, 2023 at 8:49
• .. and := with =?
– kglr
Apr 26, 2023 at 8:56

To make my comment clear, here is the full code:

Y1[m_, n_, r_] =
A[m, n, r] /.
FullSimplify[
RSolve[{A[m, n, r] == (-m - m*(r/n)*(n - m))*A[m - 1, n, r] -
m*(r/n)*(m - 1)*(n - m + 1)*A[m - 2, n, r], A[0, n, r] == 1,
A[1, n, r] == -1 - ((r/n)*(n - 1))},
A[m, n, r], {m, n, r}]][[1]]


Then:

Y1[2.1, 2.1, 1]

2.10524 + 0.595942 I

• Thank you! I think your original comment didn't work because it included := (just like i originally did) instead of = as @kglr pointed out as well Apr 26, 2023 at 9:11
• Or for an alternate representation, Y1r[m_, n_, r_] = Y1[m, n, r] // FunctionExpand // Simplify` Apr 26, 2023 at 17:35