Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error using limits in Sage

I have been using sage to plot some graphs of Fourier Series and I tried using this code

x,n,z = var('x n z')
F = (cos(x) + 2*x/pi -1)
L = 2*pi
q = integral((((2/L)*(F))*(sin((pi*n*x)/L))), x, 0, L)
w = sum((limit(q,n=z))*sin(z*pi*x/L), z, 1, 100)
e = plot(F, x,-pi,2*pi)
r = plot(w ,x,-pi,2*pi, rgbcolor=hue(0.3))
show(e+r)

I keep getting an error because of a zero that occurs in the denominator of the integral when n=2. To bypass this I tried taking the limit as seen above but this doesn't get rid of the error. When I separate the n=2 term like so:

w = sum((q*sin(n*pi*x/L), n, 3, 100) + limit(q,n=2)*sin(x)

It computes the limit properly and I get the result I require. Could anybody let me know why the original code isn't working?