a=[]#
a.append(1)# #initial condition
a.append(2)# #initial condition
print 'for recurrence relation a(n)=5*a(n-1)-4*a(n-2)+n**2' #this is a second order recurrence relation with constant coefficients.It is non homogenous because of the n**2
for n in range(2,4):
a.append(5*a[n-1]-4*a[n-2]+n**2)
print 'Value of a(%d) is: %d \n'%(n,a[n])
a=[]#
a.append(1)# #initial condition
a.append(2)# #initial condition
print 'for recurrence relation a(n)=2*a(n-1)*a(n-2)+n**2' #this recurrence relation is not linear
for n in range(2,4):
a.append(2*a[(n-1)]*a[(n-2)]+n**2)
print 'Value of a(%d) is: %d \n'%(n,a[n])
a=[]#
a.append(1)# #initial condition
a.append(2)# #initial condition
print 'for recurrence relation a(n)=n*a(n-1)+3*a(n-2)' #this is a homogenous linear second order recurrence relation without constant coefficients because the coefficient of a[n-1] is n,not a constant
for n in range(2,4):
a.append(n*a[(n-1)]+3*a[(n-2)])
print 'Value of a(%d) is: %d \n'%(n,a[n])
a=[]#
a.append(1)# #initial condition
a.append(2)# #initial condition
a.append(1)# #initial condition
print 'for recurrence relation a(n)=2*a(n-1)+5*a(n-2)-6*a(n-3)' #this is a homogenous linear third order recurrence relation with constant coefficients.Thus we need three,not two,initial conditions to yield a unique solution of the recurrence relation
for n in range(2,4):
a.append(2*a[(n-1)]+5*a[(n-2)]-6*a[(n-3)])
print 'Value of a(%d) is: %d \n'%(n,a[n])
from numpy import mat
from sympy import symbols, solve
print 'recurrence relation of Fibonacci numbers f[n]=f[n-1]+f[n-2]'
x=symbols('x')
g=x**2-x-1
print 'characterstic equation of the recurrence relation is:',g
j=solve(g,x)#
print 'roots of the characterstic equation j1,j2 are :'
for x in j:
print x,'\t',
print '\n'
print 'for general equation fn=Ar**n+Br**n,values of Aand B respectively are calculated as:'
print 'initial condition at n=0 and n=1 respectively are:'
f1=1#
f2=1#
#putting the values of f1 and f2 we get the equations to solve
D=mat([[1.6180340, -0.618034],[(1.6180340)**2, (-0.618034)**2]])#
K=mat([[1, 1]])
c=[]#
c=D/K#
A=c[0]
B=c[1]
print A, B
print 'thus the solution is f[n]=0.4472136*((1.618034)**n-(- 0.4472136)**n)]'
from numpy import mat
from sympy import symbols, solve
print 'The recurrence relation t[n]=4(t[n-1]-t[n-2])'
x=symbols('x')
g=x**2-4*x+4
print 'characterstic polynomial equation for the above recurrence relation : ',g
j=solve(g, x)
print 'roots of the characterstic equation j1,j2 : '
for x in j:
print x,'\t'
print ''
print 'the general solution is t[n]=n*2**n'
print 'initial condition at n=0 and n=1 respectively are:'
t0=1#
t1=1#
#putting the values of t0 and t1 we get the equations to solve
D=mat([[1, 0],[2, 2]])
K=mat([[1, 1]])
from numpy.linalg import solve
c=solve(D,K)
for cc in c:
print c,'\t',
print ''
D=mat([[1, 0],[2, 2]])
K=mat([[1, 1]])
c=D/K#
c1=c[0]
c2=c[1]
print 'thus the solution is t{n}=2*n-n*2**(n-1)'
from numpy import mat
from sympy import symbols, solve
print 'The recurrence relation a[n]=2*a[n-1]-3a[n-2]'
x=symbols('x')
g=x**2-2*x-3
print 'characterstic polynomial equation for the above recurrence relation : ',g
from sympy import solve
j=solve(g, x)#
print 'roots of the characterstic equation j1,j2 : '
for x in j:
print x,'\t',
print ""
print 'the general solution is a[n]=c1*3**n+c2*(-1)**n'
print 'initial condition at n=0 and n=1 respectively are:'
#putting the values of t0 and t1 we get the equations to solve
a0=1#
a1=2#
D=mat([[1, 1],[3, -1]])
K=mat([[1, 2]])
c=D/K#
c1=c[0]
c2=c[1]
print c1, c2
print 'thus the solution is a[n]=0.75*(3**n)+0.25*(1**n)'
from numpy import mat
from sympy import symbols, solve
print 'The recurrence relation a[n]=11*a[n-1]-39*a[n-2]+45*a[n-3]'
x=symbols('x')
g=x**3-11*x**2+39*x-45
print 'characterstic polynomial equation for the above recurrence relation : ',g
j=solve(g, x)
print 'roots of the characterstic equation j1,j2 : '
for x in j:
print x,'\t',
print ''
print 'hence the general solution is:a[n]=c1*(3**n)+c2*n*(3**n)+c3*(5**n)'
print 'initial condition at n=0 and n=1 respectively are:'
#putting the values of t0 and t1 we get the equations to solve
a0=5#
a1=11#
a2=25#
D=mat([[1, 0 ,1],[3, 3, 5],[9, 18, 25]])
K=mat([[5, 11, 25]])
c=D/K#
c1=c[0]
c2=c[1]
c3=c[2]
print c1, c2, c3
print 'thus the solution is a[n]=(4-2*n)*(3**n)+5**n'