Home > Enterprise >  how to Derivative and Integrals with steps in python?
how to Derivative and Integrals with steps in python?

Time:11-16

I have this piece of code to calculate the integral of the function given in the argument. I tried to search around the internet to find a solution, but i didn't find it. I want to see the step by step integral (and derivatives too) calculation.

import sympy
from sympy import sin, cos, tan, exp, log, integrate
from sympy.integrals.manualintegrate import manualintegrate


integrate(log(x))
manualintegrate(log(x), x)

CodePudding user response:

Use the integral_steps function:

from sympy import log, Symbol
from sympy.integrals.manualintegrate import integral_steps

x = Symbol('x')
steps = integral_steps(log(x), x)
print(steps)

Note that the steps are printed using the internal representation of the rules so you'll have to deduce yourself what are the rules. But it shouldn't be too difficult. For example, the example above prints

PartsRule(u=log(x), dv=1, v_step=ConstantRule(constant=1, context=1, symbol=x),
  second_step=ConstantRule(constant=1, context=1, symbol=x), context=log(x), symbol=x)
  • Related