# Revision history [back]

The best I could come up with was

var('x')
f = sin
# note the different, symbolic convention for calling sum,
# *not* the standard python give-it-a-list way.
P(n,x)=sum((-1)^k*x^(2*k+1)/factorial(2*k+1), k, 0, n-1)

sinplot = plot(f(x),(x,-2*pi,2*pi),color='red')

@interact
def _(n=(1..10)):
seriesplot = plot(P(n,x),(x,-2*pi,2*pi),color='blue')
html('$P(%s,x) = %s$'%(latex(n),latex(P(n,x))))
show(sinplot+seriesplot,ymin=-4,ymax=4)


However, I was still getting errors. It's odd that this doesn't work:

sage: var('i,x,k,n')
(i, x, k, n)
sage: a=(-1)^k*x^(2*k+1)/factorial(2*k+1)
sage: b=a.sum(k,0,n-1)
sage: b.subs(n=3,x=5)
sum((-1)^k*5^(2*k + 1)/factorial(2*k + 1), k, 0, 2)
sage: (b.subs(n=3,x=5)).n()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/grout/<ipython-input-14-3dd82cd01b78> in <module>()
----> 1 (b.subs(n=3,x=5)).n(
2 )

/Users/grout/sage-trees/sage-5.0.beta12/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression._numerical_approx (sage/symbolic/expression.cpp:18440)()

TypeError: cannot evaluate symbolic expression numerically