如何以符号方式求解 python 中的差分方程

How to solve Difference equations in python symbolically

我这样解方程 y_n+1 = -5*y_n - 1

import numpy as np
import matplotlib.pyplot as plt
N = 10
index_set = range(N+1)
x = zeros(len(index_set))
x[0] = 7/4
for n in index_set[1:]:
    x[n] = -5*x[n-1] 
plt.plot(index_set, x)

但是我怎样才能得到一个象征性的解决方案呢?

解决方法是:2*(5)^t - 1/4

我猜,可以这样处理:

from sympy import Function, rsolve
from sympy.abc import n
x = Function("x");
f = x(n+1) - 5*x(n) - 1 ;
sol = rsolve(f, x(n), {x(0):7/4});
sol