Skip to content Skip to sidebar Skip to footer

Calculate The Fourier Series With The Trigonometry Approach

I try to implement the Fourier series function according to the following formulas: ...where... ...and... Here is my approach to the problem: import numpy as np import pylab a

Solution 1:

Consider developing your code in a different way, block by block. You should be surprised if a code like this would work at the first try. Debugging is one option, as @tom10 said. The other option is rapid prototyping the code step by step in the interpreter, even better with ipython.

Above, you are expecting that b_1000 is non-zero, since the input f(x) is a sinusoid with a 1000 in it. You're also expecting that all other coefficients are zero right?

Then you should focus on the function b(n, L, accuracy = 1000) only. Looking at it, 3 things are going wrong. Here are some hints.

  • the multiplication of dx is within the loop. Sure about that?
  • in the loop, i is supposed to be an integer right? Is it really an integer? by prototyping or debugging you would discover this
  • be careful whenever you write (1/L) or a similar expression. If you're using python2.7, you're doing likely wrong. If not, at least use a from __future__ import division at the top of your source. Read this PEP if you don't know what I am talking about.

If you address these 3 points, b() will work. Then think of a in a similar fashion.

Post a Comment for "Calculate The Fourier Series With The Trigonometry Approach"