I'm working on writing an application which has to solve some recurrence relations but there are some relation which can't be analytically solved by using the rsolve method of sympy. It just returns None. Is there a way I can force sympy to solve them numerically?
I have something like this:
from sympy import *
ctx = {
"f": Function("f"),
"x": var("x",integer=True)
}
initial_conditions = {
0: 1,
1: 1,
2: 1,
3: 1
}
f = sympify("-2*f(x-1)+11*f(x-2)+12*f(x-3)-36*f(x-4) +41**(x-4)+3 -f(x)", ctx)
# calculate f(10) here without creating a closed from
# The code below will not work rsolve returns None
solve_for = sympify("f(x)", ctx)
solved = rsolve(f, solve_for, initial_conditions)
I hope someone can help me!
from sympy calculate nth recurrence without using rsolve
No comments:
Post a Comment