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
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():
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.
The text was updated successfully, but these errors were encountered:
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:However, knowing
exp(I*x) = cos(x) + I*sin(x)
, one can replacesin(pi*(k-1)/N)
withexp(I*pi*(k-1)/N)
and just keep the imaginary part of that sum. Thankfully sympy has no issue summing withexp()
: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.The text was updated successfully, but these errors were encountered: