Sympy definite integral
Asked Answered
T

1

8

I want to integrate the equation:

f(x) = integral(E^(-i * omega * t)), from -a to a.

I wrote the following code:

from sympy import *
from sympy.abc import a, omega, t

init_printing(use_unicode=False, wrap_line=False, no_global=True)


f = E**(-I * omega * t)    

integrate(f, (omega, -a, a))

But the result is just the entered definite integral. When I change the integrally limits to 0 to a I get a result... Does anyone know how to get a solution from -a to a?

Many thanks in advance.

John

Tope answered 22/7, 2017 at 19:18 Comment(0)
W
12

Sympy does not know about all the things you assume about your variables, so you need to tell sympy explicitly. For example a is supposed to be a positive (and hence real) number. If I tell this to sympy, then I get a nice answer. Try

a = symbols('a', positive=True)

right before

integrate(f, (omega, -a, a))

And make sure you use a sufficiently recent version of sympy. 1.0 works for me.

Winburn answered 23/7, 2017 at 19:58 Comment(1)
That's it! Thanks a lot!Tope

© 2022 - 2024 — McMap. All rights reserved.