December 2017
Intermediate to advanced
386 pages
10h 42m
English
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 SinIn [9]: integrate(Exp(-x) * Sin(x), x)Out[9]: -exp(-x)*sin(x)/2 - exp(-x)*cos(x)/2In [10]: integrate(Exp(-x) * Sin(x), (x, 0, 1))Out[10]: -exp(-1)*sin(1)/2 - exp(-1)*cos(1)/2 + 1/2In [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.946083070367183In [15]: integrate(x**1, (x, 0, 1))Out[15]: 1/2
Integration over unbounded domains is also possible:
In [16]: from sympy import ...
Read now
Unlock full access