| 1 | initial version |
The function rsolve (from sympy) can deal with linear recurrence relations.
To get the documentation:
sage: from sympy import rsolve
sage: rsolve?
The recurrence relation you are interested in has squares, but you could set b(n) = a(n)^2.
This way you need to solve a linear recurrence relation to find b(n).
sage: from sympy import Function, rsolve
sage: from sympy.abc import n
sage: y = Function('y')
sage: f = y(n+2) - 5*y(n+1) + 6*y(n) - 7*n
sage: rsolve(f, y(n))
2**n*C0 + 3**n*C1 + 7*C0*n
sage: b = rsolve(f, y(n), {y(0): 1, y(1): 1})
sage: b
-2**n/3 + 4*3**n/3 - 7*n/3
From there you need to check that this b(n) is always non-negative.
Finding a(n) then just amounts to picking, for each n, one of the two possible square roots of b(n).
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.