#範例11-3:比較不同n級數的傅立葉級數Fourier Series去模擬指數函數exp(x)的線型效果 #(1)若是n級數太少(n=5),就會形成鋸齒狀模擬結果 #(2)若是n級數夠大(n=50)),就會形成平滑化的模擬結果 from sympy import * x = symbols('x') f = Function('f')(x) f = exp(x) s = fourier_series(f, (x, -pi, pi)) fs5 = s.truncate(n=5) fs50 = s.truncate(n=50) p1 = plot(fs5, fs50, show=False) p1[0].line_color = 'red' p1[1].line_color = 'green' p1[0].label = '$fourier(n=5)$' p1[1].label = '$fourier(n=50)$' p1.legend = True p1.show()