Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sympy definite integral

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

like image 766
John28 Avatar asked Jul 22 '17 19:07

John28


People also ask

How do you calculate integral in SymPy?

The SymPy package contains integrals module. It implements methods to calculate definite and indefinite integrals of expressions. The integrate() method is used to compute both definite and indefinite integrals. To compute an indefinite or primitive integral, just pass the variable after the expression.

How do you evaluate a definite integral in Python?

Definite integrals are the extension after indefinite integrals, definite integrals have limits [a, b]. It gives the area of a curve bounded between given limits. It denotes the area of curve F(x) bounded between a and b, where a is the lower limit and b is the upper limit.

Which function is used to determine the value of integration in SymPy?

integrate() method, we can find the integration of mathematical expressions in the form of variables by using sympy. integrate() method.


1 Answers

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.

like image 68
laolux Avatar answered Sep 21 '22 08:09

laolux