Run the following example to see how to compute integrals with Sage:
var('x') print("Elementary integrals:") f = x^2 print(f.integrate(x)) print(integral(e^x,x)) print(integral(1/x,x)) print(integral(sinh(x), x)) print(integral(1/sqrt(1+x^2),x)) print("\nIntegration by parts:") print(integral(e^x*cos(x), x)) print(integral(sqrt(x^2-25)/x, x)) print("\nDefinite integral:") print(integral(1/(1+x^2), x, -1, 1)) print("\nImproper integral:") print(integral(1/(1+x^2), x, -infinity, infinity)) print("\nDivergent integral:") print(integral(1/(1-x), x, 1,2)) # Diverges
The results are shown in the following screenshot:
The function integrate
(or integral
) is used to compute integrals, and the methods called integrate
and integral
do exactly the same thing. We started out by showing that Sage knows about lots of the elementary integrals. We then showed that Sage easily handles functions that need to be integrated by parts, which can...