# 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?

edit retag close merge delete

It is the sum that Maxima doesn't like, and it's z=2 where the error is triggered because:

w = sum((limit(q,n=z))*sin(z*pi*x/L), z, 1, 2)


gives the same error.

It seems you're right, I tried computing the sum

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


and now it works fine, the the limit is only really necessary for n=2 so the problem persists(the above previously had not worked due to an error of mine so I've edited this comment). Is there perhaps another way of doing this if the sum won't work, perhaps outputting all the limits into a set and doing a matrix multiplication with a set of "sin(npix/L)"s to get the addition? Or some other method