1 | initial version |
What's about assigning a python function to a sage callable function?
var('x')
f = sin
def P(n,x):
return sum([(-1)^k*x^(2*k+1)/factorial(2*k+1) for k in range(n)])
print 'type(P)',type(P)
sinplot = plot(f(x),(x,-2*pi,2*pi),color='red')
@interact
def _(n=(1..10)):
p(x) = P(n,x)
print 'type(p)',type(p)
print 'p.parent()', p.parent()
seriesplot = plot(p,(-2*pi,2*pi),color='blue')
html('$P(%s,x) = %s$'%(latex(n),latex(p(x))))
show(sinplot+seriesplot,ymin=-4,ymax=4)