Consider developing your code differently, in blocks. You should be surprised if such code worked on the first try. Debugging is one option, as @ tom10 said. Another option is to quickly prototype the code step by step in the interpreter, even better with ipython.
You expect b_1000 to be nonzero, since the input f(x) is a sine wave with 1000 in it. Do you also expect all other coefficients to be zero?
Then you should focus only on the function b(n, L, accuracy = 1000) . Looking at it, 3 things go wrong. Here are some suggestions.
- multiplication
dx is inside the loop. Sure what? - in the loop, should
i be an integer on the right? Is this an integer? by prototyping or debugging you will discover this. - be careful when you write
(1/L) or a similar expression. If you use python2.7 you are mistaken. If not, at least use from __future__ import division at the top of your source. Read this PEP if you don't know what I'm talking about.
If you solve these three points, b() will work. Then think of a same way.
gg349 source share