简体   繁体   中英

Integrate exponential function using sympy

I am trying to integrate e^(-x) from 0 to 1 using sympy but I am getting the following error:

ValueError: Invalid limits given: ((exp(-x), 0, 1),)

Here is my code:

from sympy import *
x = Symbol('x')
exact_value = integrate(exp(-x), (exp(-x), 0, 1))

Following the documentation the only problem is the tuple you establish as a limit (exp(-x), 0, 1) , since it has to be (x, 0, 1) following the previously mentioned structure.

So the edited code would be:

from sympy import *
x = Symbol('x')

exact_value = integrate(exp(-x), (x, 0, 1))

I'm pretty sure you want to integrate over x, not e^-x, so that would be:

exact_value = integrate(exp(-x), (x, 0, 1))

The results is:

1 - exp(-1)

The correct way to do this is:

>>> from sympy import *
>>> x = symbols('x')
>>> integrate(exp(-x), (x, 0, 1))
1 - exp(-1)

Source: integrate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM