2011/4/17 raman <raman.kurdi2...@gmail.com>: > Hello Dears > could you please tell me how I can write the recurrence relation by > sage? > > for example > p(n)=2p(n-1)+p(n-2) where p(0)=1 and p(1)=3
you could do this: def p(n): if n == 0: return 1 if n == 1: return 3 l = (1,3) for i in xrange(n-1): l = (l[1],l[0]+2*l[1]) return l[1] -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org