I want to plot power series with symbolic functions
See this worksheet on sagenb.org.
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)])
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)
Notice that they have to define a Python function in order for this to work. I could not get this to work with a Sage callable function like P(n,x) = sum([...])
for the life of me. I tried lambdas, everything.
Now, likely either
- I've already answered this question somewhere else on the Internet, or
- It's not possible.
But I'd like confirmation of this. It's really annoying that one has to use a Python function to do this.
Yes sage callable is giving an error, but a lambda function works well too.
Hmm, I couldn't get a lambda to work, at least not in conjunction with a callable. Can you post that as an answer? (Though I won't accept it, since I want to know how to jerry-rig the callable, I'd upvote it.)