I am trying to calculate the Fourier series for $$s(x) = (x+ix_i)^p = \sum_{n=\infty}^\infty A_n \exp(ik_x x),$$ where $$k_x = \frac{n\pi}{l_x},$$ $$s \in [-l_x, l_x],$$ $$p = -1.$$ I have tried doing this in maple with the code below. It gives a terrible approximation and I don't know why. The code seems to be okay for $p \ge 0$.
> restart;
> x_i := 1
> l_x := 5*x_i
> k_x := n*Pi/l_x
> p := -1
> A_n := 1/(2*l_x)*evalf(int((x + x_i*I)^p*exp(-I*k_x*x), x = -l_x .. l_x))
> A_0 := 1/(2*l_x)*evalf(int((x + x_i*I)^p, x = -l_x .. l_x))
> plot([Re(sum(A_n*exp(k_x*x*I), n = -100 .. -1) + A_0 + sum(A_n*exp(k_x*x*I), n = 1 .. 100)), Re((x + x_i*I)^p)], x = -l_x .. l_x)
Here is the outputted figure (blue is $\Re(s(x))$ and red is the approximation).

I don't understand why you are trying to use
intandsuminstead ofIntandadd, for adding up a finite number of expressions and performing numeric integration. I suspect one or both was the cause of trouble.Let me know if this is quick enough. (You could also utilize a coarser tolerance in the Int calls, using say
epsilon=1e-5or some such.)Try to make the following procedure quick (but flexible if you want to adjust options).
And now to compute some coefficients numerically.
And plot that,