Hello everyone,

Today I decided to refresh my knowledge of Fourier Expansion. I tried to 
use Sympy but I'm not sure if the result is correct or if I did something 
wrong, so I need a fresh pair of eyes on this :)
I was following the "Fourier Series of a Square Wave" in the Wolfram 
documentation [1], and I compare the result with Sympy. Here is the code 
and the picture.

x, n = symbols("x, n")
N = 10
expr = 2 * (Heaviside(x / 2) - Heaviside(x / 2 - 1)) - 1
fs = expr.fourier_series()
wolfram = 4 / pi * sin(n * pi * x / 2) / n
wolfram_expr = 0
for i in range(1, N + 1):
    if i % 2 != 0:
        wolfram_expr += (4 / pi * sin(n * pi * x / 2) / n).subs(n, i)
plot(expr, fs.truncate(N), wolfram_expr, (x, -5, 5))

[image: Figure 70.png]



Did I do something wrong?
Thanks for you time! :)

[1] https://mathworld.wolfram.com/FourierSeriesSquareWave.html

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/dad93cf5-ddc4-4d54-a163-565552dcc6a5o%40googlegroups.com.

Reply via email to