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

trig series can be summed with Euler's formula #12107

Open
AlDanial opened this issue Jan 28, 2017 · 0 comments
Open

trig series can be summed with Euler's formula #12107

AlDanial opened this issue Jan 28, 2017 · 0 comments
Labels

Comments

@AlDanial
Copy link

Hi. I'm very impressed by sympy, terrific stuff. I recently tried to sum the series
sin( pi*(k-1)/N )
for k = 1..N but invoking .doit() just returns the original equation:

In [29]: from sympy import I, pi, symbols, Sum, cos, sin, exp
In [30]: N, k = symbols('N k')       
In [31]: Sum( sin(pi*(k-1)/N), (k, 1, N) ).doit()   
Out[31]: Sum(sin(pi*(k - 1)/N), (k, 1, N))

However, knowing exp(I*x) = cos(x) + I*sin(x), one can replace sin(pi*(k-1)/N) with exp(I*pi*(k-1)/N) and just keep the imaginary part of that sum. Thankfully sympy has no issue summing with exp():

In [35]: Sum( exp(I*pi*(k-1)/N), (k, 1, N) ).doit()   
Out[35]: Piecewise((N, Eq(exp(I*pi/N), 1)), ((exp(I*pi/N) - exp(I*pi/N)**(N + 1))/(-exp(I*pi/N) + 1), True))*exp(-I*pi/N)

so we just need to keep the imaginary parts of that answer. In my application I coded up the above equation numerically then just pulled out the ().imag part--worked great.

Is this a trick that can be coded into sympy's smarts so that the original series with the sine yields the answer like Imag(Piecewise((N, Eq(exp(I*pi/N), 1)), ((exp(I*pi/N) - exp(I*pi/N)**(N + 1))/(-exp(I*pi/N) + 1), True))*exp(-I*pi/N))? For the record I didn't arrive at this myself; my colleague Alain Sei showed me the technique and the sum which he derived himself.

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

No branches or pull requests

2 participants