rsolve not giving full solution to 2nd order difference equation

10 views
Skip to first unread message

Kaloyan Ganev

unread,
Nov 9, 2016, 1:55:03 AM11/9/16
to sympy
Hi there,

I am trying to solve a simple 2nd order difference equation using rsolve (for demonstration purposes). This is my code:


from sympy import Function, rsolve
from sympy.abc import n
y
= Function('y')

f
= y(n + 2) - 4.75*y(n + 1) + 4*y(n) - 150

sol2
= rsolve(f, y(n))
print(sol2)

The solution that is reported is not the full one but only: 3.65586884574495**n*C0 + 600.0, i.e. the larger root is taken into account only, and the particular solution.

When I run the following, things are getting OK (but not quite, because every time you have to guess the appropriate integers for your fraction):

from fractions import Fraction
from sympy import Function, rsolve
from sympy.abc import n
y
= Function('y')

f
= y(n + 2) - Fraction(19,4)*y(n + 1) + Fraction(4,1)*y(n) - 150

sol
= rsolve(f, y(n))
print(sol)

The solution now is as expected: C0*(-sqrt(105)/8 + 19/8)**n + C1*(sqrt(105)/8 + 19/8)**n + 600

What could I be doing wrong in my first example?

Reply all
Reply to author
Forward
0 new messages