Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to define a recursive sequence on Sage?

Hi, can someone tell me how to define a recurrence relation? I've tried this

def a(n):
if n==1:
        return 1
              return a(n-1)+1/a(n-1)^2

It gives the following error:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "", line 10, in <module>
        exec compile(u'open("","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZGVmIGEobik6CiAgICBpZiBuPT0xOgogICAgICAgIHJldHVybiAxCiAgICAgICAgZWxzZQogICAgICAgIHJldHVybiBhKG4tMSkrMS9hKG4tMSleMg=="),globals())+"\\n"); execfile(os.path.abspath(""))
      File "", line 1, in <module>

  File "/private/var/folders/u5/u5DFi45LFQ4s8DR+4Sy8NE+++TI/-Tmp-/tmpaYysvY/", line 6
SyntaxError: invalid syntax

thanks before.