Ask Your Question
0

How to declare variable for a function with other variable?

asked 9 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 9 years ago

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
Preview: (hide)
link

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: 9 years ago

Seen: 754 times

Last updated: Dec 19 '15