Lab 4: Integration

MAT 229, Spring 2025

You asked for it, Rylee, and here it is! How do we integrate in Mathematica? It’s easy -- a lot easier than doing your own trig substitutions, etc. But let’s see how we can put Mathematica to use.

Our key new commands this week include one that I should have mentioned last time:
	Clear  -- clears the definition of a variable, function, etc.
	Integrate

1. The Quiz....

Let’s begin by checking our answers on the quiz you all just took. Here are the four integrals:

ToExpression["\\int^{0.1}_{-0.1} \\sin^{-1}(x) \, dx", TeXForm,HoldForm]

Let’s begin by plotting this one, and then we’ll integrate:

(∫_(-0.1`)^(0.1`))ArcSin[x]\[DifferentialD]x

Plot[ArcSin[x],{x,-0.1,0.1}]

Integrate[ArcSin[x],{x,-0.1,0.1}]

ToExpression["\\int^{0}_{1} x^2 E^{x^3} \, dx", TeXForm,HoldForm]

For this one (and the following) let’s begin by defining a function f[x], defining a and b as the lower and upper limits, and then integrate:

(∫_1^0)(x^2) (E^(x^3))\[DifferentialD]x

f[x_]:=(x^2) (E^(x^3))
a=1;
b=0;
Plot[f[x],{x,a,b}]
Integrate[f[x],{x,a,b}]

ToExpression["\\int_{-1}^0 \\frac{3}{2+2x^2} \\, dx",TeXForm,HoldForm] (* Note that I needed the escaped slash before the comma for this one...?  *)

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

f[x_]:=(3/(2+2 (x^2)))
a=1;
b=0;
Plot[f[x],{x,a,b}]
Integrate[f[x],{x,a,b}]

ToExpression["\\int x \\sin(x) \, dx",TeXForm,HoldForm]

This one has no lower and upper limits, so we simply integrate (and notice that a particular anti-derivative is given):

∫x Sin[x]\[DifferentialD]x

f[x_]:=x Sin[x]
Integrate[f[x],x]

Once we’re done with these exercises, we might use the “Clear” command to eliminate the definitions of a and b, as follows:

a 
b
Clear[a,b]
a
b

(Notice that I checked to see if a and b were really cleared!)

2. Exercises

Exercise 1

Evaluate ∫x (sec^2)(x)d x. You will want to use more than one technique of integration. Then check your answer with Mathematica.

Integrate[x Sec[x]^2,x]

Exercise 2

Evaluate (∫_0^(π/2))(sin^3)(x)(cos^3)(x)d x.

But first plot the integrand over this interval.

Plot[Sin[x]^3 Cos[x]^3,{x,0,Pi/2}]
Integrate[Sin[x]^3 Cos[x]^3,{x,0,Pi/2}]

Yesterday we used the substitution u=sin(x), and confirmed that we got the same answer as Mathematica.

Today use the double angle formula for sine to first reduce the integrand to a “sin(2x)  cubed”, and then use the Pythagorean identity to simplify to an expression where the substitution u=cos(2x) works.

Do you get the same answer?

Exercise 3

Consider the indefinite integral  ∫sec(x)d x. In our materials for the week, you might have witnessed a sly move to evaluate this integral: first write the integrand sec(x) as sec(x) ((sec(x)+tan(x))/(sec(x)+tan(x))). 
(Who would think of this? Very mysterious (perhaps space aliens). But the trick works!)

Multiply the sec(x) times the numerator of that ratio ((sec(x)+tan(x))/(sec(x)+tan(x))) (which is just a special form of one); notice that the resulting numerator is just the derivative of the denominator, and suggest a suitable u-substitution.

Now evaluate the integral. Your answer should have an absolute value in it. (If not, figure out where one goes! Ask us for help, if you don’t know.)

g[x_]=Log[Abs[Sec[x]+Tan[x]]]

Define the function g(x) as the particular antiderivative of sec(x) you found which passes through the origin (in other words, choose the arbitrary constant C so that your answer satisfies g(0)=0).

Once you’ve defined g(x), execute the following Mathematica command. You should see three functions:

Mathematica's solution to the antiderivative of sec(x) (in Blue),

your solution ({Dashed,Red}), and

the original function  sec(x) (the integrand, "Thin").

(* Mathematica's solution: note the use of "=", rather than ":=" in the definition of f: *)f[x_]=Integrate[Sec[x],x]  
Plot[{f[x],g[x],Sec[x]},{x,-1.2Pi,1.2Pi},PlotStyle->{Blue,{Dashed,Red},Thin}]

What’s wrong with Mathematica’s “solution”, and why is yours better?

Exercise 4

Let g(x)=sin(x).

What is a range of x-values that give one arch of this sine curve above the x-axis?

Rotate the region between the x-axis and this arch about the horizontal line y=-1 to get a solid of revolution.

What is the shape of the cross sections?

Set up the integral that gives the volume of this solid.

Using an appropriate integration technique, compute this integral by hand to find the volume of this solid.

To make sure your answer is reasonable, approximate this solid with a solid cylinder that has had a core cylinder removed; just compute its volume using the volume of cylinder formula V=π (r^2)h.

GraphicsGrid[{{Show[RegionPlot[0≤y≤Sin[x]&&0≤x≤π,{x,0,π},{y,0,1},PlotStyle->LightGray],RegionPlot[0≤y≤0.5&&0≤x≤π,{x,0,π},{y,0,1},PlotStyle->{White,Opacity[0]},BoundaryStyle->{White,Opacity[0]}],Plot[{Sin[x],0.5},{x,0,π},PlotStyle->{Black,{White,Opacity[0]}}],Graphics[{Gray,Dashed,Line[{{-1,-1},{4,-1}}]}],PlotRange->{{-1,4},{-2,2}},Axes->True,Frame->False],Show[RegionPlot[0≤y≤Sin[x]&&0≤x≤π,{x,0,π},{y,0,1},PlotStyle->{White,Opacity[0]},BoundaryStyle->{White,Opacity[0]}],RegionPlot[0≤y≤0.5&&0≤x≤π,{x,0,π},{y,0,1},PlotStyle->LightGray],Plot[{Sin[x],0.5},{x,0,π},PlotStyle->{{White,Opacity[0]},Black}],Graphics[{Gray,Dashed,Line[{{-1,-1},{4,-1}}]}],PlotRange->{{-1,4},{-2,2}},Axes->True,Frame->False]},{Show[Graphics3D[{Dashed,Line[{{-2,-1,0},{5,-1,0}}]}],RegionPlot3D[1≤(((y+1))^2)+(z^2)≤(1+Sin[x])^2&&0≤x≤π,{x,-1,4},{y,-3,3},{z,-3,3},PlotPoints->{10,100,100},PlotRange->{{-1,4},{-3,3},{-3,3}},BoxRatios->Automatic]],Show[Graphics3D[{Dashed,Line[{{-2,-1,0},{5,-1,0}}]}],RegionPlot3D[1≤(((y+1))^2)+(z^2)≤2.25&&0≤x≤π,{x,-1,4},{y,-3,3},{z,-3,3},PlotPoints->{10,100,100},PlotRange->{{-1,4},{-3,3},{-3,3}},BoxRatios->Automatic]]}},Dividers->{All,{True,False,True}}]

3. An application from statistics:

This normal distribution’s probability function cannot be evaluated analytically by any of our methods -- the famous “bell curve”, or normal distribution, which is essential in statistics. The function defined below, which I’m calling pdf, is the normal probability density function, or PDF, with a mean of 0 and a standard deviation of 1:

pdf[x_]:=E^(-((x^2)/2))/(Sqrt[2π])

cdf[x_]=Integrate[pdf[y],{y,-∞,x}]
Plot[{pdf[x],cdf[x]},{x,-2,2}]
Integrate[pdf[x],{x,-1,1}]
N[%]
Integrate[pdf[x],{x,0,10}]
N[%]
g[10]
N[%]
p[a_,b_]:=N[cdf[b]-cdf[a]]
(* Results from "the Empirical Rule": *)
p[-1,1]
p[-2,2]
p[-3,3]

Our objective is to compute the integral p(a,b)=(∫_a^b)f(x) d x, which represents the probability of values between a and b.

Define the function  cdf(y)=(∫_∞^y)f(x) d x as an integral using Mathematica. This is called the cumulative distribution function, or CDF.

Plot both pdf(x) and cdf(x) on the same graph.

Use cdf(y) to define the probability function (a function of two variables, by the way!), which gives the probability p of a value of x falling between a and b.

Now we can ask for particular probabilities. For example, we can ask for the probability that

a value of x falls between -1 and 1 (within a standard deviation of the mean);

a value of x falls between -2 and 2 (within two standard deviations of the mean);

a value of x falls between -3 and 3 (within three standard deviations of the mean). Together these will produce the so-called “Empirical rule” in statistics.

We can ask for the x value at which a particular probability occurs. For example, we can use “Solve” to find the probability that

p[0,x]=0.3 (i.e. the value of x which contains 30% of the area (probability) under the distribution from the mean;

Solve[p[0,x]==0.30,x]

p[x,∞]=0.05 (i.e. the value of x at which the right tail contains 5% of the area (probability) under the distribution.

Solve[p[x,∞]==0.05,x]