# difference equation and continued fractions

I'm interested in solving the following difference equation: $$x[k-1]+(k^2+k+a)/x[k]=b$$, $$k=1,2,\ldots$$, where $$a,b$$ are fixed positive numbers; let's say $$x[1]=c>0$$. Mathematica's RSolve function doesn't yield the general solution.

RSolve[{x[k - 1] + (k^2 + k + a)/x[k] == b}, x, k]


I tried RecurrenceTable. It produced something that looks like a cont fraction. Does anyone recognize it?

RecurrenceTable[{x[k - 1] + (k^2 + k + a)/x[k] == b,
x[1] == c}, x, {k, 10}]

{c, (6 + a)/(b - c), (12 + a)/(b - (6 + a)/(b - c)), (20 + a)/(
b - (12 + a)/(b - (6 + a)/(b - c))), (30 + a)/(
b - (20 + a)/(b - (12 + a)/(b - (6 + a)/(b - c)))), (42 + a)/(
b - (30 + a)/(b - (20 + a)/(b - (12 + a)/(b - (6 + a)/(b - c))))), (
56 + a)/(b - (42 + a)/(
b - (30 + a)/(
b - (20 + a)/(b - (12 + a)/(b - (6 + a)/(b - c)))))), (72 + a)/(
b - (56 + a)/(
b - (42 + a)/(
b - (30 + a)/(
b - (20 + a)/(b - (12 + a)/(b - (6 + a)/(b - c))))))), (90 + a)/(
b - (72 + a)/(
b - (56 + a)/(
b - (42 + a)/(
b - (30 + a)/(
b - (20 + a)/(b - (12 + a)/(b - (6 + a)/(b - c)))))))), (
110 + a)/(
b - (90 + a)/(
b - (72 + a)/(
b - (56 + a)/(
b - (42 + a)/(
b - (30 + a)/(
b - (20 + a)/(b - (12 + a)/(b - (6 + a)/(b - c)))))))))}


I suspect the continued fraction is probably a hypergeometric function of some sort.

• Some of the constants look suspicous: A002378 Oblong (or promic, pronic, or heteromecic) numbers: a(n) = n*(n+1). (Formerly M1581 N0616) oeis.org/… – flinty May 14 at 21:05
• ... in fact it's simpler than that - the constants in the fraction from bottom to top appear in Table[(n - 4) (n - 5), {n, 7, 50}] – flinty May 14 at 21:21

I wrote the recursion directly by solving for x[k] in terms of x[k-1]:

Clear[x];
x[k_] := x[k] = (a + k + k^2)/(b - x[k - 1])
x[1] = c;


This clearly gives a "continued fraction-like" answer:

x[#] & /@ Range[10]


Observing that the coefficients in each stack are the same:

coef={6, 12, 20, 30, 42, 56, 72, 90, 110}


I tried:

FindSequenceFunction[{6, 12, 20, 30, 42, 56, 72, 90, 110}]

2 + 3 #1 + #1^2 &


Of course this is not a proof of anything, but likely this pattern continues and might lead you to a relatively simple general form.