Search code examples
pythonmathsympysymbolic-integration

Integration of sin x dx problem in python programming implementation


I want to implement this integration in Python:

Equation

So far I did the code below but it is not making sense. What am I doing wrong?

import sympy as sm
x=sm.Symbol('x')
x=sm.integrate(math.sin(x)**2, 2*x)

Solution

  • Referencing the other answers you don't need to use trigintegrate but you do need to supply the integration limits when calling integrate if it is a definite integral:

    In [31]: from sympy import integrate, sin, oo, Symbol
    
    In [32]: x = Symbol('x')
    
    In [33]: integrate(sin(x**2), (x, 0, oo))
    Out[33]: 
    √2⋅√π
    ─────
      4  
    
    In [34]: _.n()
    Out[34]: 0.626657068657750