tos1
tos1

Reputation: 3

sympy integral of summation

I am new to sympy, and I was experimenting with some code. I was trying to implement the following

from sympy import *
F = Function('F')
domega = symbols('\Delta\omega', real = True , positive=True,nonzero=True)
omega = symbols('omega', real = True , positive=True,nonzero=True)
T = symbols('T', real = True , positive=True,nonzero=True)
N = symbols('N', integer = True, positive=True ,nonzero=True)
k = symbols('k', integer = True ,positive=True )
t = symbols('t', real = True, positive=True)

T = 2 * pi / N / domega

SF =  Sum(F(domega*k) * cos(t*domega*k),(k,0,N) )
integrate(SF,(t,0,T))

I am struggling to make sympy actually perform the integration, which is left undone outside the summation. I can manage to make it work only if I switch manually the sum and the integral

Sum( integrate(F(domega*k) * cos(t*domega*k) ,(t,0,T)),(k,0,N) )

I feel the problem could be due to the way k is defined, but I cannot figure out how to do it correctly.

Upvotes: 0

Views: 285

Answers (1)

Oscar Benjamin
Oscar Benjamin

Reputation: 14480

This is fixed in sympy master since the last release (1.5).

With 1.5:

   ...: integrate(SF,(t,0,T))                                                                                                     
Out[1]: 
     2⋅π                                                       
──────────────                                                 
N⋅\Delta\omega                                                 
      ⌠                                                        
      ⎮          N                                             
      ⎮         ___                                            
      ⎮         ╲                                              
      ⎮          ╲                                             
      ⎮          ╱   F(\Delta\omega⋅k)⋅cos(\Delta\omega⋅k⋅t) dt
      ⎮         ╱                                              
      ⎮         ‾‾‾                                            
      ⎮        k = 0                                           
      ⌡                                                        
      0 

With master:

   ...: integrate(SF,(t,0,T))                                                                                                     
Out[1]: 
  N                               
_____                             
╲                                 
 ╲                                
  ╲                        ⎛2⋅π⋅k⎞
   ╲  F(\Delta\omega⋅k)⋅sin⎜─────⎟
   ╱                       ⎝  N  ⎠
  ╱   ────────────────────────────
 ╱           \Delta\omega⋅k       
╱                                 
‾‾‾‾‾                             
k = 0  

Upvotes: 1

Related Questions