# Recurrence equation value error

Hello, As an anxious student I tried googling for an answer for 2hours without any result. I'm new Sagemath user.

I have to solve equation:

a[n+2]-4*a[n+1]+4*a[n]=2^n+cos(n*pi/2), a=1, a=2


My sage input is:

from sympy import *
y = Function('y')
n = Symbol('n',integer=True)

rsolve(y(n+2)-4*y(n+1)+4*y(n)-2^n-cos(n*pi/2), y(n), {y(0):1,y(1):2})


But I'm getting an error:

ValueError: 'y' expected, got 'cos'

Sage has some problems with cosine function, any idea how to solve it?

edit retag close merge delete

This is really a sympy question. Hopefully someone can help, but you may also want to ask at http://groups.google.com/group/sympy for a backup.

Also, it's conceivable that when you imported *everything* from Sympy that some Sage object was clobbered, or maybe Sympy doesn't expect more than one type of function in its recurrences, or something.

Sort by » oldest newest most voted

After importing * from sympy, I get

sage: rsolve?
Definition:     rsolve(f, y, init=None)
Docstring:
Solve univariate recurrence with rational coefficients.

Given k-th order linear recurrence Ly = f, or equivalently:


and nothing says f can be a trig function...

more