It is not always possible to determine whether an improper integral converges or diverges with a CAS. Nor is it always possible to determine the value of improper integral known to convergence. Still, many improper integrals can be evaluated exactly and others approximated numerically using commands we've already introduced. This page offers a few examples. Furthermore, a CAS may sometimes be of use in applying the limit comparison test. See the examples below.
>> syms x >> int( exp(-x), x, 0, inf ) ans = 1 >> int( 1/x, x, 0, inf ) ans = Inf >> int( sin(x), x, 0, inf ) ans = NaN >> int( 1/(1+x^2), x, 0, inf ) ans = pi/2 >> int( cos(x)/(1+x^2), x, 0, inf ) ans = (pi*exp(-1))/2 >> int( 3*exp(-x)*x^2*cos(x)/(1+x^2), x, 0, inf ) Warning: Explicit integral could not be found. ans = int((3*x^2*exp(-x)*cos(x))/(x^2 + 1), x == 0..Inf)
>> syms x >> int( 1/sqrt(x), x, 0, 1 ) ans = 2 >> int( tan(x), x, 0, sym('pi')/2 ) ans = Inf >> int( x*exp(-x)*tan(x), x, 0, sym('pi')/2 ) Warning: Explicit integral could not be found. ans = int(x*exp(-x)*tan(x), x == 0..pi/2)
Our attempt above to compute $\int_0^\infty 3x^2e^{-x}\frac{\cos{x}}{1+x^2}\,dx$ failed. However the limit comparison test may at least be used to show that this improper integral is absolutely convergent. (Recall we already know that $\int_0^\infty \frac{1}{1+x^2}\,dx$ is convergent.) And the numerical method integral() may be used to approximate its value.
>> syms x f g >> f = abs( 3*x^2*exp(-x)*cos(x)/(1+x^2) ); >> g = 1/(1+x^2); >> limit(f/g, x, inf) ans = 0 >> integral( @(x)3*exp(-x).*x.^2.*cos(x)./(1+x.^2), 0, inf ) ans = 0.0618
Our attempt above to compute $\int_0^{\frac{\pi}{2}} x e^{-x} \tan{x}\,dx$ failed. A limit comparison may be used to prove divergence. (Recall we know that $\int_0^{\frac{\pi}{2}} \tan{x}\,dx$ diverges to infinity.)
>> syms x f g >> f = x*exp(-x)*tan(x); >> g = tan(x); >> limit(f/g, x, sym('pi')/2) ans = (pi*exp(-pi/2))/2
Here's what happens if you attempt to compute this divergent integral numerically.
>> integral( @(x) x.*exp(-x).*tan(x), 0, pi ) Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.2e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy. > In funfun/private/integralCalc>iterateScalarValued at 372 In funfun/private/integralCalc>vadapt at 133 In funfun/private/integralCalc at 76 In integral at 89 ans = 0.1949
Notice that NIntegrate[] failed to generate a warning in the last computation above even though Integrate[] knows that $\int_0^{\frac{\pi}{2}}x e^{-x}\tan{x}\,dx$ diverges.
First some convergent integrals that Sage can compute exactly.
Now a convergent integral that Sage can't handle exactly.
Click the "Evaluate" button below to see what happens if you feed Sage a integral which it can determine to be divergent.