Ask Your Question
1

How to solve non_homogenous recurrence in sage using rsolve functions?

asked 2016-11-17 15:27:48 +0200

M95 gravatar image

updated 2016-11-18 17:41:47 +0200

a(n+1)^2-5a(n+1)^2+6a(n)^2=7n a0=a1=1 I've used rsolve for this recurrence relation but I got the error min() arg is an empty sequence any help would be appreciated.from sympy import Function, rsolve,Poly from sympy.abc import n b=Function('b') a=Function('a') f=(b(n+2))^2-5*(b(n+1))^2+6*(b(n))^2-7*n inits={b(0):1,b(1):1} b(n)=rsolve(f,b(n),inits) b(n) the error is:ValueError: min() arg is an empty sequence

edit retag flag offensive close merge delete

Comments

Please post the code you are using and the error you are getting.

To display blocks of code, either indent them with 4 spaces, or select the corresponding lines and click the "code" button (the icon with '101 010').

slelievre gravatar imageslelievre ( 2016-11-18 17:19:49 +0200 )edit

@M95, did you mean a(n+2)^2 - 5*a(n+1)^2 + 6a(n)^2 = 7*n?

You wrote a(n+1)^2 twice.

slelievre gravatar imageslelievre ( 2016-11-18 17:21:47 +0200 )edit

@slelievre Yes ,you're right sorry.

M95 gravatar imageM95 ( 2016-11-18 17:30:45 +0200 )edit

Here is the code:from sympy import Function, rsolve,Poly from sympy.abc import n b=Function('b') a=Function('a') f=(b(n+2))^2-5*(b(n+1))^2+6*(b(n))^2-7*n inits={b(0):1,b(1):1} b(n)=rsolve(f,b(n),inits) b(n)

M95 gravatar imageM95 ( 2016-11-18 17:42:39 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-11-18 17:41:06 +0200

slelievre gravatar image

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).

edit flag offensive delete link more

Comments

Thank you .I also tried this ,but the answer is not the thing that I've calculated with the characteristic function method!

M95 gravatar imageM95 ( 2016-11-18 17:49:56 +0200 )edit

What did you find with the characteristic function method?

slelievre gravatar imageslelievre ( 2016-11-18 20:39:40 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-11-17 15:27:48 +0200

Seen: 1,992 times

Last updated: Nov 18 '16