Calculate the Fourier series with the trigonometry approach

前端 未结 1 1438
挽巷
挽巷 2021-02-04 14:09

I try to implement the Fourier series function according to the following formulas:

\"enter

相关标签:
1条回答
  • 2021-02-04 14:46

    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.

    0 讨论(0)
提交回复
热议问题