Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This code with a lambda function works. As you mentioned in the comment, it is still not what you want.

var('x')
n=var('n')
assume(n,'integer')
f = sin
P = lambda n,x:sum([(-1)^k*x^(2*k+1)/factorial(2*k+1) for k in range(n)]) 

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)