I want to implement this integration in Python:
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)
I want to implement this integration in Python:
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)
On
I think you are looking for this:
import sympy as sm
x=sm.Symbol('x')
x=sm.integrate(sm.sin(x**2), x)
print(x)
You need to use the sin function from sympy lib instead of math lib.
On
One issue was that you didn't use the trig functions from sympy:
from sympy import sin
from sympy.abc import x
integrate(sm.sin(x**2), x)
This will return a complicated expression involving the Gamma function because sin(x^2) has no simple indefinite integral.
You can, however, directly compute the definite integral you are showing, simply by using the bounds as argument (and using sympy.oo for infinity):
from sympy import sin, oo
from sympy.abc import x
integrate(sin(x**2), (x, 0, oo))
(source: from the sympy documentation)
On
It helps a great deal to know what the answer is before you begin computing:
integral_0^∞ sin(x^2) dx = sqrt(π/2)/2≈0.626657
Referencing the other answers you don't need to use
trigintegratebut you do need to supply the integration limits when callingintegrateif it is a definite integral: