简体   繁体   English

使用 sympy 积分指数函数

[英]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:我正在尝试使用sympye^(-x)0集成到1但出现以下错误:

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.按照 文档,唯一的问题是您建立的元组作为限制(exp(-x), 0, 1) ,因为它必须是(x, 0, 1)遵循前面提到的结构。

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:我很确定你想对 x 进行积分,而不是 e^-x,所以这将是:

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来源: 整合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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