1 | initial version |
This should do the job.
f=var('f')
ans=var('ans')
def T(f,n,x):
ans=0
for v in range(0,n):
ans=ans+binomial(n,v)*f(v+1)*(x)^v
return ans
print T(f,4,x)
2 | declare f as a symbolic function, remove redundant var('ans') |
This should do the job.
f=var('f')
ans=var('ans')
f=function('f')
def T(f,n,x):
ans=0
for v in range(0,n):
range(n+1):
ans=ans+binomial(n,v)*f(v+1)*(x)^v
return ans
print T(f,4,x)