Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fourier_series omits a_0 for odd functions truncated at limits #19375

Closed
mfripp opened this issue May 20, 2020 · 0 comments · Fixed by #19382
Closed

fourier_series omits a_0 for odd functions truncated at limits #19375

mfripp opened this issue May 20, 2020 · 0 comments · Fixed by #19382
Labels

Comments

@mfripp
Copy link

mfripp commented May 20, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants