【问题标题】:Fourier series of Piecewise PYTHONPiecewise PYTHON的傅里叶级数
【发布时间】:2018-06-10 10:56:05
【问题描述】:

我试图找到傅里叶级数

简单的喜欢:

p = Piecewise((sin(t), 0 < t),(sin(t), t < pi), (0 , pi < t), (0, t < 2*pi))
fs = fourier_series(p, (t, 0, 2*pi)).truncate(8)

但它似乎不起作用。它卡在 * 中(循环?)。有没有办法解决这个问题?也许是另一种选择?非常感谢

【问题讨论】:

    标签: python python-3.x fft sympy piecewise


    【解决方案1】:

    我明白了,延迟一两秒:

    In [55]: fourier_series(p,(t,0,2*pi))
    Out[55]: FourierSeries(Piecewise((sin(t), (t > 0) | (t < pi)), (0, (pi < t) | (t < 2*pi))), (t, 0, 2*pi), (0, SeqFormula(Piecewise((0, Eq(_n, -1) | Eq(_n, 1)), (cos(2*_n*pi)/(_n**2 - 1) - 1/(_n**2 - 1), True))*cos(_n*t)/pi, (_n, 1, oo)), SeqFormula(Piecewise((-pi, Eq(_n, -1)), (pi, Eq(_n, 1)), (sin(2*_n*pi)/(_n**2 - 1), True))*sin(_n*t)/pi, (_n, 1, oo))))
    

    这只是设置而已。

    _.truncate(8) 花费(太)长。那一定是在做评估。

    不同的截断效果更好吗?我没有看到任何其他控件。


    .truncate(1) 返回sin(t).truncate(2) 挂起。将这个简单的sin(t) 与一个扁平段混合起来一定会设置一个分析困难的困难案例。但我对这方面的数学有点生疏了。

    用我发现的 numpy 寻找傅立叶级数:

    How to calculate a Fourier series in Numpy?


    对于在 (0,pi) fs1 = fourier_series(p, (t, 0, pi)) 上定义的 FS:

    In [5]: fs1.truncate(1)
    Out[5]: 2/pi
    In [6]: fs1.truncate(2)
    Out[6]: -4*cos(2*t)/(3*pi) + 2/pi
    In [7]: fs1.truncate(3)
    Out[7]: -4*cos(2*t)/(3*pi) - 4*cos(4*t)/(15*pi) + 2/pi
    In [8]: fs1.truncate(4)
    Out[8]: -4*cos(2*t)/(3*pi) - 4*cos(4*t)/(15*pi) - 4*cos(6*t)/(35*pi) + 2/pi
    In [9]: fs1.truncate(5)
    Out[9]: -4*cos(2*t)/(3*pi) - 4*cos(4*t)/(15*pi) - 4*cos(6*t)/(35*pi) - 4*cos(8*t)/(63*pi) + 2/pi
    

    哪个情节(在 numpy 中)符合预期:

    Fourier Series 的表格中,我找到了这个公式(以numpy 术语),用于整流正弦波:

    z8 = 1/pi + 1/2*sin(t)-2/pi*np.sum([cos(2*i*t)/(4*i**2-1) for i in range(1,8)],axis=0)
    

    这有一个类似的cos 系列术语,但添加了sin 术语。这对我来说意味着你可以将这个半罪近似为a*sin(t)+b(sin(2*t))(或类似的东西)的总和。我想像sympy 那样,有一些数学课本或论文探讨了推导傅立叶级数的困难。你看过 Mathworld 链接吗?

    比较整流半正弦与整流全正弦的 FS

    半正弦:

    In [434]: z3 = 1/pi + 1/2*sin(t)-2/pi*np.sum([cos(2*i*t)/(4*i**2-1) for i in range(1,3)],axis=0)
    

    全正弦:

    In [435]: w3 = 1/pi -2/pi*np.sum([cos(2*i*t)/(4*i**2-1) for i in range(1,3)],axis=0)
    
    In [438]: plt.plot(t,sin(t)/2)
    In [439]: plt.plot(t,w3)
    In [440]: plt.plot(t,z3)
    In [441]: plt.plot(t,w3+sin(t)/2)  # full sine + sine/2 == half sine
    

    我可以想象将这样的见解转移回sympy,以一种不需要很长时间(或可能挂起)的方式重新定义周期函数。

    【讨论】:

      猜你喜欢
      • 2019-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      • 2023-03-25
      相关资源
      最近更新 更多