Sympy 分步求解积分

Sympy step by step solution of integrals

在 sympy http://docs.sympy.org/latest/modules/integrals/integrals.html 的文档中,我们可以阅读:

The manualintegrate module has functions that return the steps used (see the module docstring for more information).

但是调用 help(sympy.integrals.manualintegrate) 我们得到:

Help on function manualintegrate in module sympy.integrals.manualintegrate:

manualintegrate(f, var)
manualintegrate(f, var)

Compute indefinite integral of a single variable using an algorithm that
resembles what a student would do by hand.

Unlike ``integrate``, var can only be a single symbol.

Examples
========

>>> from sympy import sin, cos, tan, exp, log, integrate
>>> from sympy.integrals.manualintegrate import manualintegrate
>>> from sympy.abc import x
>>> manualintegrate(1 / x, x)
log(x)
>>> integrate(1/x)
log(x)
>>> manualintegrate(log(x), x)
x*log(x) - x
>>> integrate(log(x))
x*log(x) - x
>>> manualintegrate(exp(x) / (1 + exp(2 * x)), x)
atan(exp(x))
>>> integrate(exp(x) / (1 + exp(2 * x)))
RootSum(4*_z**2 + 1, Lambda(_i, _i*log(2*_i + exp(x))))
>>> manualintegrate(cos(x)**4 * sin(x), x)
-cos(x)**5/5
>>> integrate(cos(x)**4 * sin(x), x)
-cos(x)**5/5
>>> manualintegrate(cos(x)**4 * sin(x)**3, x)
cos(x)**7/7 - cos(x)**5/5
>>> integrate(cos(x)**4 * sin(x)**3, x)
cos(x)**7/7 - cos(x)**5/5
>>> manualintegrate(tan(x), x)
-log(cos(x))
>>> integrate(tan(x), x)
-log(sin(x)**2 - 1)/2

See Also
========

sympy.integrals.integrals.integrate
sympy.integrals.integrals.Integral.doit
sympy.integrals.integrals.Integral

我没有看到一步一步的解决方案。

您正在查看 function manualintegrate 的文档字符串,而不是 module manualintegrate 的文档字符串。该模块是 here,上面写着

This module also provides functionality to get the steps used to evaluate a particular integral, in the integral_steps function. This will return nested namedtuples representing the integration rules used.

integral_steps 函数记录如下:

Returns the steps needed to compute an integral. This function attempts to mirror what a student would do by hand as closely as possible. SymPy Gamma uses this to provide a step-by-step explanation of an integral. The code it uses to format the results of this function can be found at https://github.com/sympy/sympy_gamma/blob/master/app/logic/intsteps.py.

除非您使用 SymPy Gamma,否则 integral_steps 的输出将难以阅读。示例:

from sympy.integrals.manualintegrate import integral_steps
integral_steps(x*sin(3*x), x)

returns

PartsRule(u=x, dv=sin(3*x), v_step=URule(u_var=_u, u_func=3*x, constant=1/3, substep=ConstantTimesRule(constant=1/3, other=sin(_u), substep=TrigRule(func='sin', arg=_u, context=sin(_u), symbol=_u), context=sin(_u), symbol=_u), context=sin(3*x), symbol=x), second_step=ConstantTimesRule(constant=-1/3, other=cos(3*x), substep=URule(u_var=_u, u_func=3*x, constant=1/3, substep=ConstantTimesRule(constant=1/3, other=cos(_u), substep=TrigRule(func='cos', arg=_u, context=cos(_u), symbol=_u), context=cos(_u), symbol=_u), context=cos(3*x), symbol=x), context=-cos(3*x)/3, symbol=x), context=x*sin(3*x), symbol=x)

SymPy Gamma site 上更易读。