I am trying to compute the result of a Fourier integral coefficient. When I use integrate() and print the result I get a Piecewise object with several arguments, one of them being the answer I'm looking for. However, I only need that argument and can't find a way to subtract it from the piecewise function.
I've read that each argument of the piecewise object is a 2-tuple defining the expression and a condition. I've tried using the item number but I get:
TypeError: 'Piecewise' object is not iterable
I've also tried converting the result into a list and it works, but I get a list of one item with the whole piecewise function so I get the same problem.
The code is fairly simple:
from sympy import *
x = Symbol('x')
w = Symbol('w')
func = exp(-abs(x))
a = integrate(func*cos(w*x), (x, -oo, oo))
print (a)
The result of the Fourier coefficient is 2/(w^2 +1), but the output is:
Piecewise((2/(w**2 + 1), Eq(2*Abs(arg(w)), 0)), (Integral(exp(-Abs(x))cos(wx), (x, -oo, oo)), True))
As you can see the function I'm looking for is there, in the first argument, but I can't find a way to take only the first argument from the objet and the take only the expression. I'm not experienced in python so I don't think I've tried all possible solutions, any ideas?