Mathematica's
 Symbolic Integration

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

Notebook Overview

Mathematica is able to calculate both definite and indefinite integrals symbolically.  It knows all the tricks you will learn in class (integration by substitution, integration by parts, trig substitutions) and some others you need not learn.  The only caution in using Mathematica's Integrate[.]  is that it might choose a inappropriate sign in a trig substitution.  This is discussed in Section 13.5 of the Main Text.

The command to evaluate a definite integral is

Integrate[ f[x], {x, a, b} ]

where a and b are the limits of integration.

To evaluate an indefinite integral, the command is

Integrate[ f[x], x ]

The second  x  in this commands tells Mathematica you want to antidifferentiate with respect to x.  The classical notation for this is contained in the differential, f[x] dx.

References to the Text

This NoteBook goes with Chapter 13 of the text.

Step-by-step

The Fundamental Theorem of Integral Calculus says that if we can find a function  F[x]  such that  F'[x] = f[x]  (or  dF[x] = f[x] dx), then

(∫_a^b) f[x] dx = F[b] - F[a]

For example, to integrate  f[x] = (x^2)

(∫_a^b) (x^2) dx

We observe that if  F[x] = ((x^3)/3), then F'[x]=((3 (x^2))/3) = (x^2) = f[x], so

(∫_a^b) (x^2) dx = 
        F[b] - F[a] = ((b^3)/3) - ((a^3)/3)

and specifically,

(∫_(-2)^5) (x^2) dx = 
        F[b] - F[a] = ((5^3)/3) + ((8^3)/3) = (133/3)

Try this with Mathematica:

Clear[x, a, b]; (∫_a^b) (x^2) \[DifferentialD]x

(∫_(-2)^5) (x^2) \[DifferentialD]x

The indefinite integral or antiderivative can be computed as follows:

∫(x^3) \[DifferentialD]x

Check your homework:

Any time you want to check your own hand computation of an integral, simply fill in the function, a and b in the following:

Clear[f, x]; \(f[x_] := x*Sin[x]; 
\(a = \(-\(π\/2\)\); \)\)b = (π/3); Print["The integral of ", f[x], " from ", a, " to ", b]; 
    (∫_a^b) f[x] \[DifferentialD]x

or for indefinite integrals

Clear[f, x]; f[x_]:=x*Sin[x];
Print["The antiderivative of ", f[x]]; ∫f[x] \[DifferentialD]x

These can be pretty horrible

Clear[f, x, a, b]; f[x_] := (1/Cos)[x]^3; Print["The antiderivative of ", f[x]]; ∫f[x] \[DifferentialD]x

and include parameters:

Clear[f, x, a, b]; f[x_] := Exp[a x] Cos[b x]; Print["The antiderivative of ", f[x]]; ∫f[x] \[DifferentialD]x

Example 13.10: Integrate f[x] = x Log[ x ] from a to b.

(∫_a^b) x Log[x] \[DifferentialD]x

Remember that the Mathematica notation for natural log is Log[x].

a = 1b = 2(∫_a^b) x Log[x] \[DifferentialD]x

Exercise 13.5.1(e):

Integrate f[x]  = ((3 (x^2) - 1)/(1 + (Sqrt[(x^3) - x]))) by the substitution

u = (x^3) - x 	du = 3 (x^2) - 1
	u[0] = 0	u[1] = 0

u = (x^3) - x  du = 3 (x^2) - 1

∫(du/(1 + (Sqrt[u]))) du from 0 to 0, so the answer is

WARNING: These integrals take Mathematica a VERY long time using the general-purpose algorithms.  Abort with <Alt>+<.> or quit kernel if you get tired of waiting.

f[x_] := ((3 (x^2) - 1)/(1 + (Sqrt[(x^3) - x]))); (∫_0^1) f[x] \[DifferentialD]x

∫f[x] \[DifferentialD]x

∫(1/((Sqrt[u]) + 1)) \[DifferentialD]u

Check Your Homework Drill Exercises

Exercise 13.2.1

a

∫7 (Sqrt[ x]) \[DifferentialD]x

b

∫5 (x^3) \[DifferentialD]x

c

∫(3/(x^2)) \[DifferentialD]x

d

∫(x^(3/2)) \[DifferentialD]x

Exercise 13.3.1

a

∫(5 (x^3) - 2) \[DifferentialD]x

b

∫((3/(x^2)) - (Sqrt[x])) \[DifferentialD]x

d

∫(5 Sin[x]  -  (E^(2 x))]) 
      \[DifferentialD]x

f

∫(Cos[5 x] - (5/x)) \[DifferentialD]x

Exercise 13.4.1

a

∫(1/(((3  x  - 2))^2)) \[DifferentialD]x

b

∫((2 t)/(Sqrt[1 - (t^2)])) \[DifferentialD]t

c

∫x (((3 + 7 (x^2)))^3) \[DifferentialD]x

d

∫((3 y)/(((2 + 2 (y^2)))^2)) \[DifferentialD]y

e

∫(((Cos[x]))^3) Sin[x] \[DifferentialD]x

f

∫Cos[Log[x]]/x \[DifferentialD]x

g

∫(E^Cos)[θ] Sin[θ] 
        \[DifferentialD]θ

h

\(Clear[a, b, x]; 
∫Sin[a\ x\  + \ b] \[DifferentialD]x\)

Exercise 13.5.1 	Change of Variable with Limits Drill

a

(∫_0^1) (x/((x^2) + 1)) \[DifferentialD]x

b

(∫_0^((π/6)))Sin[3 θ] 
        \[DifferentialD]θ

c

(∫_2^3)(( 2 x)/((((x^2) - 3))^2)) \[DifferentialD]x

d

\(Clear[a, b, x]; 

    ∫\_0\%1\((a\ x + \ b)\) \[DifferentialD]x\)

e

(∫_0^1)(( 3 (x^2) - 1)/(1 + (Sqrt[x - (x^3)]))) 
          dx  see above.  Mathematica has trouble without knowing the change of variable and differential. Try it and see.

(∫_0^1)(( 3 (x^2) - 1)/(1 + (Sqrt[x - (x^3)]))) 
        \[DifferentialD]x

f

(∫_0^1) x (e^(-(x^2))) \[DifferentialD]x

g

(∫_0^((π/2)))Cos[θ] Sin[θ] 
        \[DifferentialD]θ

Exercise 13.7.1   Integration by Parts Drill

Integrate the following functions.

a

∫θ Cos[θ] \[DifferentialD]θ

b

∫(θ^2) Sin[θ] \[DifferentialD]θ

c

(∫_0^((π/2)))θ Sin[θ] 
        \[DifferentialD]θ

d

(∫_0^((π/2)))θ Cos[θ] 
        \[DifferentialD]θ

e

∫x (E^(2 x)) \[DifferentialD]x

f

∫(x^2) (E^(2 x)) \[DifferentialD]x

g

∫(E^(5 x)) Sin[3 x] 
        \[DifferentialD]x

h

∫(E^(3 x)) Cos[5 x] 
        \[DifferentialD]x

Exercise 13.7.7   Combined Integration

Integrate the following functions.

a

∫x Cos[x] Sin[x] \[DifferentialD]x

b

(∫_0^((π/2)))θ (((Cos[θ]))^2) 
        \[DifferentialD]θ

c

∫((x^3)/(Sqrt[(x^2) - 1])) \[DifferentialD]x

d

∫(1/(x^3)) (Sqrt[(1/x) - 1]) \[DifferentialD]x

e

(∫_0^1) ArcTan[x] \[DifferentialD]x

f

(∫_0^1) x  ArcTan[x] \[DifferentialD]x

g

(∫_0^1) ArcTan[(Sqrt[x])] \[DifferentialD]x

h

(∫_4^9) Sin[(Sqrt[x])] \[DifferentialD]x

i

∫(((Log[x]))^2) \[DifferentialD]x

Problem 14.11  Arclength of an Ellipse

An ellipse is given parametrically by the pair of equations

x = 3 Cos[θ]
	y = 2 Sin[θ]

with -π < θ < π.

Find an integral formula for the length of the curve by "looking in an infinitesimal microscope," as we did in the computation of the length of a parametric curve above.  In a microscope we will see a right triangle with the change in x on the horizontal leg, the change in y on the vertical leg and the length along the hypotenuse.  The Pythagorean theorem says that the corresponding increment of length is given by

dL = (Sqrt[(dx^2) + (dy^2)])

This time, the length will NOT be equal to the change in the angle, dθ, because an ellipse is a circle that has been stretched different amounts in the x and y directions.  The changes in the coordinates are function changes

dx[θ] = x[θ + dθ] - x[θ]
	dy[θ] = y[θ + dθ] - y[θ]

Use the increment approximation for these changes to express them approximately in terms of dθ.  Substitute the approximations into the Pythagorean expression above.

Test your formula on the circle (where you know the answer) as well as the `parametric' equations

x=θ
	y = 2 (Sqrt[1 - ((((θ/3)))^2)])

(which can be compared to the explicit arclength formula L=(∫_a^b)((Sqrt[1+((f'[x])^2)]))dx.)

The (correct) arclength formula for the ellipse cannot be computed by antidifferentiation, so you must use numerical integration such as Mathematica NIntegrate[.].

Why is the parametric integral for the ellipse better behaved than the explicit formulas?

Non-Elementary Symbolic Computations

Functions whose antiderivatives cannot be expressed in "elementary" terms.

Remember that not all integrals can be evaluated by finding an antiderivative that is written in terms of classical functions.  Two things can happen if you ask Mathematica to evaluate an impossible integral.

∫(Sqrt[1 + (x^4)]) \[DifferentialD]x

(Sqrt[1 + (x^4)]) can not be "integrated" (antidifferentiated) in terms of elementary functions.  If you ask Mathematica to do it, it gives the answer in terms of special "Elliptic" functions.  In this case it really cannot be expressed in terms of "elementary" classical functions.

You CAN still find numerical values of its integrals:

NIntegrate[(Sqrt[1 + (x^4)]), {x, 0, π E}]

The other possible outcome is this: Mathematica may have a non-elementary answer. Try this one:

∫Exp[-x]/x \[DifferentialD]x

Some integrals are impossible to do, but come up so frequently in applications that they are given special names.  The integral of Exp[x]/x can not be expressed in terms of elementary functions, but it can be given a special name.  Mathematica has some of these special functions built in, so it may give you the name of a special function.  ExpIntegralEi[x] is simply defined to be the (complex) anti-derivative of Exp[x]/x.  The second half of the Fundamental Theorem and numerical integration gives us a way to approximately compute it.  A more elaborate algorithm is built in in Mathematica:

ExpIntegralEi[-1.0]

∫Sin[x]/x \[DifferentialD]x

The integral of Sin[x]/x comes up frequently in Fourier analysis and its antiderivative also cannot be expressed in elemenytary terms.  It is sometimes known as si[x], but Mathematica writes out its built in function SinIntegral[x].

SinIntegral[0]

SinIntegral[π]

N[SinIntegral[π]]

NIntegrate[Sin[x]/x, {x, 0, π}]

(∫_0^∞) Sin[x]/x \[DifferentialD]x

Further Examples

∫((Cos[x] - 1)/(x^2)) \[DifferentialD]x

∫Cos[(x^2)] \[DifferentialD]x

∫Sin[(x^2)] \[DifferentialD]x

The normal distribution of probability and statistics

Try this:

∫Exp[-(((x^2) s)/2)] \[DifferentialD]x

What?

((2 ∫Exp[-(x^2)] \[DifferentialD]x)/(Sqrt[π]))

"Erf" is a common name for the "Gaussian error function" and is Mathematica's built in function name.  This is the probability distribution function of the "normal" distribution of probability and statistics - the famous "bell shaped curve."  It is a central idea in statistics that averages of independent trials can be approximated by the normal probabilities.  Erf[x] cannot be expressed in terms of elementary classical functions.

Erf[0]

Erf[(Sqrt[2])]

N[Erf[(Sqrt[2])]]

NIntegrate[((2 Exp[-(x^2)])/(Sqrt[π])), {x, 0, (Sqrt[2])}]

Arclength of an ellipse is not elementary

This integral comes from the computation of the arclength of an ellipse.  Notice that Mathematica gets an answer in terms of an "Elliptic" function.

\(Clear[a, b, t]; 

    ∫\(\@\(a\ Sin[t]\^2 + b\ Cos[t]\^2\)\) \[DifferentialD]t\)

4 NIntegrate[(Sqrt[5 Sin[t]^2 + 2 Cos[t]^2]), {t, 0, (π/2)}]