You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe this is intended behavior? I want to calculate a Fourier series for a simple repeated sawtooth function:
f(x) = x, 0 <= x <= 1; f(x + 1) = f(x)
In sympy, I tried
from sympy import fourier_series
from sympy.abc import x
fourier_series(x, (x, 0, 1)).truncate()
This gives a Fourier series that is missing the a_0 = 1/2 term. When I look at the fourier_series source code, this seems to be because fourier_series identifies the function x as an odd function, so then it only calculates the sine sequence (the b_n terms). However, this skips calculating a_0, which is normally generated along with the cosine sequence.
I can work around this by modifying the function, e.g., this gives expected behavior:
from sympy import fourier_series, Heaviside as u
from sympy.abc import x
fourier_series(x*(u(x)-u(x-1)), (x, 0, 1)).truncate()
But this makes the fourier_series several times slower, because it now has to do integrals with x*(u(x)-u(x-1)) instead of just x. And it seems like this adjustment shouldn't be needed, because the limits already indicate that this is not an odd function.
Is it possible to update fourier_series to check whether the limits are symmetrical at the same time as it checks whether the function is odd? With asymmetrical limits, it should always calculate the a_0 term, even if the function is odd.
The text was updated successfully, but these errors were encountered:
Maybe this is intended behavior? I want to calculate a Fourier series for a simple repeated sawtooth function:
In
sympy
, I triedThis gives a Fourier series that is missing the
a_0 = 1/2
term. When I look at thefourier_series
source code, this seems to be becausefourier_series
identifies the functionx
as an odd function, so then it only calculates the sine sequence (theb_n
terms). However, this skips calculatinga_0
, which is normally generated along with the cosine sequence.I can work around this by modifying the function, e.g., this gives expected behavior:
But this makes the
fourier_series
several times slower, because it now has to do integrals withx*(u(x)-u(x-1))
instead of justx
. And it seems like this adjustment shouldn't be needed, because the limits already indicate that this is not an odd function.Is it possible to update
fourier_series
to check whether the limits are symmetrical at the same time as it checks whether the function is odd? With asymmetrical limits, it should always calculate thea_0
term, even if the function is odd.The text was updated successfully, but these errors were encountered: