How it works...

Let's try something more complicated—the definite integral of the f(x) = e-xsinx function on the [0,1] interval:

In [8]: from sympy import N, exp as Exp, sin as Sin
In [9]: integrate(Exp(-x) * Sin(x), x)
Out[9]: -exp(-x)*sin(x)/2 - exp(-x)*cos(x)/2
In [10]: integrate(Exp(-x) * Sin(x), (x, 0, 1))
Out[10]: -exp(-1)*sin(1)/2 - exp(-1)*cos(1)/2 + 1/2
In [11]: N(_)
Out[11]: 0.245837007000237

Symbolic integration, when it works, treats singularities the right way, as follows:

In [12]: integrate(Sin(x) / x, x)
Out[12]: Si(x)
In [13]: integrate(Sin(x) / x, (x, 0, 1))
Out[13]: Si(1)
In [14]: N(_)
Out[14]: 0.946083070367183
In [15]: integrate(x**1, (x, 0, 1))
Out[15]: 1/2

Integration over unbounded domains is also possible:

In [16]: from sympy import oo
In [17]: integrate(Exp(-x**2), (x,0,+oo))
Out[17]: sqrt(pi)/2
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset