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
else
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 "_sage_input_10.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZGVmIGEobik6CiAgICBpZiBuPT0xOgogICAgICAgIHJldHVybiAxCiAgICAgICAgZWxzZQogICAgICAgIHJldHVybiBhKG4tMSkrMS9hKG4tMSleMg=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/private/var/folders/u5/u5DFi45LFQ4s8DR+4Sy8NE+++TI/-Tmp-/tmpaYysvY/___code___.py", line 6
else
^
SyntaxError: invalid syntax
thanks before.