Techniques of Integration

This lab shows how Mathematica  can help us integrate complicated integrals and improper integrals.  There are times, however, when Mathematica  needs our help.  If we are attempting to integrate an improper integral that either has a discontinuity at one of the endpoints of the integral or has infinity (or minus infinity) as one of the endpoints Mathematica  can usually take care of it.  If Mathematica  gives us error messages, we may have to use limits to get the answer.  Mathematica  also has times when it cannot find an antiderivative for the function that we give it.  At these times, we can sometimes help Mathematica  by using a substitution first.

Before you begin working, review the Mathematica  commands Plot[ ],  Limit[ ],  Integrate[ ], and NIntegrate[ ] that are in both the hard copy and on-line versions of  "Mathematica Reference".   Mathematica now allows us to use  "Free-form input" to enter many commands.  Unfortunately, there are some things that we can’t do using "Free-form input" and it helps to learn the formal commands.

Some examples are done below.  Read the examples carefully to understand the commands.  Position your cursor anywhere on the first input line (the indented lines are input lines), click the mouse, and press the Enter key on the far right of the computer by the numeric keyboard or Shift+Enter (Shift+Return on a Macintosh) on the alphabetical keyboard to execute the commands.  Study the result and, after you understand what happened, move your cursor to the next input line and enter it.  Continue until you reach the end of the notebook.

Examples

Confusing or non-existent antiderivatives

EXAMPLE 1:  If you are using formal Mathematica, once you start typing a command it gives you a list of commands from which you can select one. Every time you ask Mathematica to carry out an operation, the Wolfram Predictive Interface gives you a Suggestions Bar that is relevant to the current output.  If the Suggestions Bar seems to have disappeared completely, click on the output cell and it will reappear.  Sometimes when we use Mathematica  to evaluate an indefinite integral, we get a confusing answer.  It doesn’t matter whether we use formal Mathematica or "Free-form input", we have no idea what "Erfi(x)" means.  The symbols for ∫f(x)dx and  (∫_a^b)f(x)dx can be found by pulling down Palettes to either Basic Math Assistant or Classroom Assistant.

Integrate[Exp[x^2],x]

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

Notice that when we used the "Free-form input", Mathematica showed us the formal input line below our typing.  Even if we try to evaluate the definite integral of this function on the interval  0 ≤ x ≤ 2, we still get a confusing expression.

Integrate[Exp[x^2],{x,0,2}]

N[%]

(∫_0^2)Exp[(x^2)]\[DifferentialD]x

To get a numerical approximation for this last answer you can use "numerical value" from the Suggestions Bar or N[%] where "%" stands for the last output.  If instead we had used NIntegrate[ ] for the definite integral we would find a numerical answer.

"Free-form input" doesn’t appear to help but if you click on the "+" in the upper right hand corner of the box around the command, then go to the box labeled "Definite integral", you see the answer 16.4526.  You can also click on "numerical value" from the Suggestions Bar or use N[%].

NIntegrate[Exp[(x^2)],{x,0,2}]

EXAMPLE 2:  Sometimes Mathematica has trouble finding an antiderivative, it make take a few minutes in this example but Mathematica will simply repeat the command.

∫(1+Cos[x])(Sqrt[1-(x+Sin[x])^2])\[DifferentialD]x

"Free-form input" is also unable to integrate this function, it simply repeats the command in formal Mathematica.

If we help Mathematica by making the substitution  u = x + sin(x), then  du = (1 + cos(x))dx  and we can rewrite the integral as ∫(Sqrt[1-(u^2)])du which does yield an answer.

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

Unfortunately, the answer is in terms of  u  instead of  x.  We can fix that by using the replacement command

%/.(u->1+cos(x))

You must be careful to use this command immediately after the last  output since  "%"  refers to the preceding output.

Improper Integrals - Infinite Limits

EXAMPLE 3:  Suppose we try to evaluate an improper integral that has infinity as one of its limits.  The symbol "∞" can be obtained by pulling  down the Palettes Menu to either Basic Math Assistant  or Classroom Assistant.

(∫_1^∞)(1/(x^2))\[DifferentialD]x

NIntegrate[1/(x^2),{x,1,Infinity}]

Mathematica did not have a problem.

EXAMPLE 4:  Let's try the following integral.

(∫_1^∞)(1/x)\[DifferentialD]x

NIntegrate[(1/x),{x,1,Infinity}]

This time using either the definite integral or "Free-form input",  Mathematica tells us that the integral does not converge while NIntegrate[ ] gave us an error message and a value for the integral.  The error message is a warning that we should look at the problem some more.  Because one of the limits is  ∞, we can try using a limit.

Limit[(∫_1^t)(1/x)\[DifferentialD]x,t->∞]

This tells us that the integral goes to Infinity; hence, does not converge.

Just looking at the graph of a function doesn't always tell us if an improper integral converges.  For example, the functions in the last two examples,  f(x) = 1/x and g(x) =1/(x^2), look very similar for x > 1.  The command AxesOrigin->{0,0} places the origin at the point (0, 0) and PlotRange->All tells Mathematica to show all the y-values in the following.

Plot[1/x,{x,1,50},AxesOrigin->{0,0},PlotRange->All]

Plot[1/(x^2),{x,1,50},AxesOrigin->{0,0},PlotRange->All]

We can even have Mathematica shade in the regions by adding a Filling statement to the Plot[ ] command and typing Plot[f[x], {x, a, b}, Filling->{1->0}] where "0" means the horizontal line y = 0 and "1" stands for the function we are graphing.  The two areas still look very similar.

Plot[1/x,{x,1,50},AxesOrigin->{0,0}, Filling->{1->0},PlotRange->All]

Plot[1/x^2,{x,1,50},AxesOrigin->{0,0}, Filling->{1->0},PlotRange->All]

Since both curves are above the x-axis, the integral gives us the area.  Example 3 and Example 4 tell us that the unbounded region between  f(x) = 1/x,  the x-axis, and  x > 1  has an infinite area while the unbounded region between  g(x) =1/(x^2), the x-axis, and  x > 1  has an area of one square unit!  That is difficult to believe.

EXAMPLE 5:  Suppose we want to see if the region between f(x) = ((x + 1)/(3(x^2)+ 1)) and the x- axis  is bounded or infinite for x > 2.  If we start by graphing f(x) on the interval  2 < x < 10, at first glance it looks like the graph crosses the x-axis near x = 9.

In fact, f(x) > 0  whenever  x > -1.  We get a better idea of what's happening if we place the origin at the point (0, 0) by using the command AxesOrigin->{0,0} as in the following.

Plot[((x+1)/(3(x^2)+1)),{x,2,10},AxesOrigin->{0,0}]

If we try to find the area with either of the following commands, it tell us the integral does not converge.  We can conclude the area is unbounded.

(∫_2^∞)((x+1)/(3(x^2)+1))\[DifferentialD]x

EXAMPLE 6:  If one of the limits is  - ∞  we can try using the improper integral below.

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

If we want a decimal approximation, we can use N[%] where  % stands for the last output or  click on "numerical value" from the Suggestions Bar.

N[%]

We could also have tried using NIntegrate[ ].   If you use "Free-form input",  click on the "+" in the upper right hand corner of the box around the command, then go to the box labeled "Definite integral"

NIntegrate[(2^x),{x,-Infinity,0}]

EXAMPLE 7:  If the limits are  ∞ and  - ∞  AND there are no discontinuities in the interval we can also use the definite integral or NIntegrate[ ], or "Free-form input".

(∫_(- ∞)^∞)((x^2)/(9 + (x^6)))\[DifferentialD]x

N[Pi/9]

NIntegrate[((x^2)/(9 + (x^6))),{x,- ∞,∞}]

Improper Integrals - Discontinuous Integrands

Mathematica does not always check for discontinuities.  We must look for them before setting up our integrals.  Discontinuities may occur at an endpoint of an interval or at a point inside the interval.  The next three examples deal with functions that are discontinuous on the interval of integration.

EXAMPLE 8:  Let's see what happens if the integrand, the function that we are integrating, has a discontinuity at one of the endpoints.

(∫_0^(π/2))Tan[x]\[DifferentialD]x

NIntegrate[Tan[x],{x,0,π/2}]

When we used  (∫_0^(π/2))Tan[x]dx  and the "Free-form input" we were told that the interval does not converge.  When we used the NIntegrate[ ] command we got 37.331 and no error messages.  Something is wrong.   If we look at the tangent function, we see that it is discontinuous at x = π/2.

If the function has a discontinuity on the interval, we need to take the limit as we approach the point of discontinuity.  In this case, we need to look at  (∫_0^t)tan(x) dx and take the limit as t approaches  π/2 from the left.  Mathematica uses "Direction->1" to mean approach from the left and "Direction->-1" to mean approach from the right.  Then (lim_(t → (SuperMinus[((ℼ/2))])))((∫_0^t)tan(x)dx) =

Limit[Integrate[Tan[x],{x,0,t}],t->π/2,Direction->1]

You can also try using the "Free-form input" line below.

These results are telling us the integral is unbounded or infinite.  The Integrate[ ] command usually works if the discontinuity is at an endpoint but NIntegrate[ ] may give us a wrong answer.

EXAMPLE 9:  Sometimes we try to integrate a function over an interval where the function has a discontinuity on the interior of the interval.  We must be careful to check for discontinuities before integrating.  If we look at f(x) = (1/(x - 2)) on the interval  0 < x < 3 we notice that it is discontinuous at  x  =  2.

Plot[1/(x-2),{x,0,3}]

NIntegrate[1/(x-2),{x,0,3}]

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

NIntegrate[ ]  gave us  a value for the definite integral along with some error messages while both the definite integral and the "Free-form input" seem to tell us that the integral does not converge.  We cannot trust the value NIntegrate[ ] gave us, Mathematica is suggesting that there may be a singularity (a point of discontinuity) .

Because this function has a discontinuity at x = 2 , we should break the integral into two integrals at the point of discontinuity (∫_0^3)(1/(x-2))dx  =(∫_0^2)(1/(x-2))dx + (∫_2^3)(1/(x-2))dx and then evaluate each integral, (∫_0^2)(1/(x-2))dx  and  (∫_2^3)(1/(x-2))dx, separately.  Both  (∫_0^2)(1/(x-2))dx and  (∫_2^3)(1/(x-2))dx must converge if  (∫_0^3)(1/(x-2))dx  is to converge.  We can find  (∫_0^2)(1/(x-2))dx by using:

Limit[Integrate[1/(x-2),{x,0,t}],t->2, Direction->1]

This limit is - ∞ so there is no need to continue, (∫_0^3)(1/(x-2))dx diverges.

Since ∫(1/(x-2))dx = ln | x - 2 | + c, we have (∫_0^t)(1/(x-2))dx = ln | t - 2 | - ln |-2 | and we could also have found (∫_0^2)(1/(x-2))dx by using:

Limit[Log[Abs[t-2]]-Log[2],t->2, Direction->1]

Again, the limit is  - ∞ so there is no need to continue, (∫_0^3)(1/(x-2))dx diverges.

EXAMPLE 10:  Sometimes, the discontinuity is not obvious from the graph as with f(x) = ((x - 1)/((x^2)- 1)) on the interval  0 < x < 3.

Plot[((x - 1)/((x^2)-1)),{x,0,3}]

Both graphs are misleading for two reasons.  The function has a removable discontinuity at x = 1 that does not show up; Mathematica does not show "holes" in the graphs, it simply connects the dots to the left and right of the hole.  Also, it appears that the graph hits the x-axis at approximately x = 3 and the y-axis starts at approximately  y = 0.2.   To see the true position of the function, use the Mathematica command AxesOrigin->{0,0} to get both axes to pass through the point (0, 0).

Plot[((x - 1)/((x^2)-1)),{x,0,3},AxesOrigin->{0,0}]

This time, all of the following give us the same answer, Log[4] or 1.38629 and no error messages so we can probably trust Mathematica.

Integrate[(x-1)/(x^2-1),{x,0,3}]

N[%]

NIntegrate[(x - 1)/(x^2 - 1),{x,0,3}]

Let's  break the integral into two integrals at the point of discontinuity so that 
				(∫_0^3)((x - 1)/((x^2)-1))dx  =(∫_0^1)((x - 1)/((x^2)-1))dx + (∫_1^3)((x - 1)/((x^2)-1))dx

and then evaluate each integral, (∫_0^1)((x - 1)/((x^2)-1))dx  and  (∫_1^3)((x - 1)/((x^2)-1))dx, separately as a limit as we did in the previous example.  Both  (∫_0^1)((x - 1)/((x^2)-1))dx and  (∫_1^3)((x - 1)/((x^2)-1))dx must converge if  (∫_0^3)((x - 1)/((x^2)-1))dx  is to converge.  You will find that each integral converges to Log[2] so the original integral converges to Log[2] + Log[2] = 2 Log[2] = Log[4].

Integrate[(x-1)/(x^2 -1),{x,0,1}]

Integrate[(x-1)/(x^2 -1),{x,1,3}]

Since each integral converges to Log[2], the original integral converges to Log[2] + Log[2] = 2 Log[2] = Log[4] ≈ 1.38629.

This example had a removable discontinuity at x = 1.  Can you make any conclusions about what happens when the point of discontinuity is a removable discontinuity?

If you want to type new command lines, move your cursor on the page until it becomes horizontal and click the mouse.   If you want to use formal Mathematica, simply begin typing.  Notice that if you are using formal Mathematica, once you start typing a command it gives you a list of commands from which you can select one.  If you want to use  "Free-form input",  press the equal sign and then begin typing.

Exercises - Your report should contain a cover page with the name of your instructor, your name and your partner's name, along with the title of the lab.  Your printouts should include the Mathematica commands, not just the outputs, for your graphs and any work that you used to arrive at the solutions to the problems.  You can write explanations by hand on the printed pages.  Include the numbers of the exercises!  No credit will be given without a write-up which shows all your work and gives clear explanations.

1.  Use Mathematica  to evaluate each of the following integrals and then use one of the integration procedures from the textbook (NOT a table) to evaluate the same integral.  Show the technique involved in evaluating the integral; if your answer does not look like Mathematica's answer simplify one, or both, to show that they are equal. 
     a)  ∫(((Log[x])^2)/(x^3))dx
     
     b)   ∫((sin^3)(x)-(cos^3)(x))dx 
     
     c) ∫(((x^2)+1)/((((x^2)-2 x+2))^2))dx
	
     d)   ∫(((x^5)+x-1)/((x^3)+1))dx

2.  Mathematica has problems with the following antiderivatives.  For each of the following, you will need to help Mathematica by suggesting a substitution.  On your work, indicate what you are letting  u  represent and what  du  equals.  Once Mathematica gets the integral in terms of  u  remember to convert the answer back in terms of  x.
      a)  ∫(1+(1/(2 (Sqrt[x])))) ((Sqrt[x])+x) (Sqrt[1+((((Sqrt[x])+x))^4)])dx    
      b) ∫(1-(2/(x^3))) (Sqrt[1-((((1/(x^2))+x))^2)])dx
      c) ∫((x sin(x)ln(x sin(x)) )/(1-(Sqrt[1-(Sqrt[x sin(x)])])))(x cos(x) + sin(x))dx

3. Each of the following is an improper integral.  Explain why the integral is an improper integral.  Determine whether each integral is convergent or divergent and evaluate those that are convergent.
     a)  (∫_2^∞)(1/((x^3) - 1))dx
     
     b) (∫_0^3)(x/(x - 3))dx
     
     c)  (∫_0^3)(1/((x^2)- 7x + 10))dx
     
     d)  (∫_(- ∞)^∞)(x^3)(e^(-(x^4)))dx
     
     e)  (∫_(- ∞)^∞)(e^(-3x))dx

4.   Let g(x) = (1/(-1 +  (e^(x^(1/3))))).  
     a)  Obtain a printout that shows g(x)  for  0 < x < 1  When you plot the function, use AxesOrigin -> {0, 0} in the plot command so that the axes pass through the point (0, 0).
     b)  Explain why (∫_0^1)((1/(-1 +  (e^(x^(1/3))))))dx   is an improper integral.
     c)  Determine the value of (∫_0^1)((1/(-1 +  (e^(x^(1/3))))))dx   if it exists or explain why it does not converge.

5.   Let f(x) = 
     a)  Obtain a printout that shows the function for 0.1 < x < 10.  
     b)  Explain why (∫_0^∞)((((sin^2)(x))/(x^2)))dx  is an improper integral.
     c)   Determine the value of (∫_0^∞)((((sin^2)(x))/(x^2)))dx  if it exists or explain why it does not converge.

6.  Find the value of the constant  C  for which the integral  (∫_0^∞)((x/((x^2) + 1)) - (C/(3x + 1)))dx converges.  Evaluate the integral for this value of  C.

7.  The probability of an event is a number between   0  and  1  that specifies the likelihood of the event.  In particular, the probability is the fraction of the time the event can be expected to occur if the experiment is repeated a large number of times.  A probability density function for a continuous random variable  x  is a non-negative function  f(x)  such that the probability that  x  is between  a  and  b  is   (∫_a^b) f(x)dx. If  x ≥ 0, the expected (or mean) value of  x  is  (∫_0^∞)x f(x)dx.

The probability density function for the duration of telephone calls in a certain city is  
			f(x)  = (((0.5))^6) (x^5) (e^(-(((0. 5x))^2)))  
where  x  denotes the duration (in minutes) of a randomly selected call (x ≥ 0).
     a)  Find the probability that a  randomly selected call will last between  2  and  3  minutes.
     b)  Find the probability that a randomly selected call will last at least  2  minutes.
     c)   Find the probability that a randomly selected call will last less than  2  minutes.
     d)  What happens when you add your answers to parts  b  and  c?  Explain.
     e)  Find the expected duration of a telephone call.