Ask Your Question
0

How to declare variable for a function with other variable?

asked 2015-12-19 12:16:58 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

n=var("n")
def T(n):
    a=1
    b=x
    if n==0:
        return a
    if n==1:
        return b
    else:
        for i in [2..n]:
            b=2*x*b-a
            a=(a+b)/(2*x)
    return b

Could you help me to compute T(i) at x=1 or anything ?Mean that I want to declare x is a variable of T(i), but I can't. Thank you so much

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-12-19 20:03:57 +0100

vdelecroix gravatar image

As far as I understand this is what you want

def T(n):
    x = polygen(ZZ)     # or alternatively x = var("x")
    a=1
    b=x
    if n==0:
        return a
    if n==1:
        return b
    else:
        for i in [2..n]:
            b=2*x*b-a
            a=(a+b)/(2*x)
    return b
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-12-19 12:16:58 +0100

Seen: 694 times

Last updated: Dec 19 '15