Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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 * 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.