Lab 03: Integrals and Aproximations

1. Computer Algebra Systems (CAS)

Consider the following integral

∫((1+Log[x])/(Sqrt[1-(((x*Log[x]))^2)]))\[DifferentialD]x

Notice that Mathematica could not determine the proper substitution/method for solving this problem.  Sometimes a CAS needs a little help in getting the first step of an integral.  As in class, with integrals involving logarithms we usually make a substitution u=Log[x] , then du=(1/x)dx (which can be written as (e^u)du=dx ).  Substituting into the integral gives:

∫((1+u)/(Sqrt[1-(((u*(E^u)))^2)]))*(E^u)\[DifferentialD]u

Notice: that again, Mathematica choked.  However, if we then make the substitution w=u*(e^u), then we get

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

After some back substitutions, we get the answer to the problem.

Try this type of substituion on problem 46 in section 7.6 of our book.

2. Numerical Approximations

Recall in class that we talked about the Midpoint, Trapeziodal, and Simpson’s Methods for approximating Integrals.  As a first step in exploring these methods using Mathematica, either execute or copy and execute the following code:

MidPointMethod[funct_,a_,b_,n_]:=
Module[{f=funct,x0=a,xn=b,n0=n},
dx=(xn-x0)/n0;
output=Sum[f[x0+(k-1/2)*dx],{k,1,n0}]*dx
]

TrapMethod[funct_,a_,b_,n_]:=
Module[{f=funct,x0=a,xn=b,n0=n},
dx=(xn-x0)/n0;
output=((f[x0]+f[xn])/2+Sum[f[x0+k*dx],{k,1,n0-1}])*dx
]

SimpMethod[funct_,a_,b_,n_]:=
Module[{f=funct,x0=a,xn=b,n0=n},
dx=(xn-x0)/n0;
output=(f[x0]+f[xn]+4*Sum[f[x0+k*dx],{k,1,n0-1,2}]+2*Sum[f[x0+k*dx],{k,2,n0-2,2}])*dx/3
]

PlotMP[funct_,a_,b_,n_]:=
Module[{f=funct,x0=a,xn=b,n0=n},
dx=(xn-x0)/n0;
part=Table[x0+k*dx,{k,0,n0}];
midpoints=Table[x0+(2*k-1)*dx/2,{k,1,n0}];
p1=Plot[f[x],{x,x0,xn},PlotStyle->{Blue,Thick}];
p2=Graphics[{Table[
{EdgeForm[Black],Opacity[.3],Rectangle[{part[[k]],0},{part[[k+1]],f[midpoints[[k]]]}]},{k,1,n0}]}];
Show[p1,p2,AxesOrigin->{x0,0}]
]

PlotTrap[funct_,a_,b_,n_]:=
Module[{f=funct,x0=a,xn=b,n0=n},
dx=(xn-x0)/n0;
part=Table[x0+k*dx,{k,0,n0}];
p1=Plot[f[x],{x,x0,xn},PlotStyle->{Blue,Thick}];
p2=Graphics[{Table[
{EdgeForm[Black],Opacity[.3],Polygon[{{part[[k]],0},{part[[k]],f[part[[k]]]},{part[[k+1]],f[part[[k+1]]]},{part[[k+1]],0}}]},{k,1,n0}]}];
Show[p1,p2,AxesOrigin->{x0,0}]
]

This code sets up five commands: the first three perform the Midpoint, Trapezoidal, and Simpson’s Methods; the last two generate graphs of the rectangles and trapezoids used in those methodes.

Examples of these commands follow:

f[x_]=Sin[Exp[x]]^2

PlotMP[f,0,2,10]

area=MidPointMethod[f,0,2,10]
N[area,12]

Here we graphed the function f on the interval [0, 2] along with the rectangles used in the Midpoint Method approximation with 10 subintervals.  Then calculated the approximation (and converted it to a 12 digit floating-point number.

The other commands opperate in a similar fashion: 
	Command[ function_name, left_endpoint, right_endpoint, #_invervals].

Task

We will now use these commands to approximate (∫_1^2)(e^(1/x))dx .

1.  Define f(x)=(e^(1/x)) as a Mathematica function (recall that you can use the Math Assistant Palette or the Exp[] command).  Use the built in NIntegrate[] or N[] and Integrate[] commands to get a good approximation to the integral.

2.  Generate graphs of the function f showing the rectangles and trapezoids used to approximate the integral using 4 subintervals.

3.  Using the above commands complete the following chart:

({{n, Midpoint Method, Trapezoidal Method, Simpson's  Method}, {4, □, □, □}, {8, □, □, □}, {12, □, □, □}, {16, □, □, □}, {20, □, □, □}, {24, □, □, □}})

4.  How many decimal places of accuracy do we get (compared to the “exact” answer given in (1) for each method for 24 subintervals?

	Midpoint: 		Trapezoidal:			Simpson’s:

5.  Simpson’s Rule yields better results.  How large does the n need to be chosen to get the same amount of accuracy for the Trapezoidal Rule?