Python| sympy.Integral() 方法
借助sympy.Integral()方法,我们可以创建 SymPy 表达式的未计算积分。它与Integrate()方法具有相同的语法。要评估未评估的积分,请使用doit()方法。
Syntax: Integral(expression, reference variable)
Parameters:
expression – A SymPy expression whose unevaluated integral is found.
reference variable – Variable with respect to which integral is found.
Returns: Returns an unevaluated integral of the given expression.
示例 #1:
# import sympy
from sympy import *
x, y = symbols('x y')
expr = x**2 + 2 * y + y**3
print("Expression : {} ".format(expr))
# Use sympy.Integral() method
expr_intg = Integral(expr, x)
print("Integral of expression with respect to x : {}".format(expr_intg))
print("Value of the Integral : {} ".format(expr_intg.doit()))
输出:
Expression : x**2 + y**3 + 2*y
Integral of expression with respect to x : Integral(x**2 + y**3 + 2*y, x)
Value of the Integral : x**3/3 + x*(y**3 + 2*y)
示例 #2:
# import sympy
from sympy import *
x, y = symbols('x y')
expr = y**3 * x**2 + 2 * y*x + x * y**3
print("Expression : {} ".format(expr))
# Use sympy.Integral() method
expr_intg = Integral(expr, x, y)
print("Integral of expression with respect to x : {}".format(expr_intg))
print("Value of the Integral : {} ".format(expr_intg.doit()))
输出:
Expression : x**2*y**3 + x*y**3 + 2*x*y
Integral of expression with respect to x : Integral(x**2*y**3 + x*y**3 + 2*x*y, x, y)
Value of the Integral : x**2*y**2/2 + y**4*(x**3/12 + x**2/8)