In this laboratory we will explore the notion of Riemann midpoint sums and the trapezoidal rule.

The midpoint rule is given by the formula 


MP =   (Underoverscript[ ∑, (i=1), n])f((Subscript[x, i*]))   Δx = (∑_(i=1)^n)f(a + (i -1/2)(b-a)/n) ((b-a)/n)

The left hand end point formula is 

Lp=(Underoverscript[ ∑, (i=1), n])f((Subscript[x, i-1])) Δx = (∑_(i=1)^n)f(a + (i -1)(b-a)/n) ((b-a)/n)

The right hand end point formula is

(∑_(i=1)^n)f((Subscript[x, i])) Δx = (∑_(i=1)^n)f(a + i (b-a)/n) ((b-a)/n)

Now the trapezoidal rule is given by considering the area of the trapezoid 
given by computing the area of the trapezoid obtained from the points 

(Subscript[x, i-1, ]) (Subscript[x, i, ])f((Subscript[x, i-1]) ),f((Subscript[x, i]))

The formula is 

TR   =   (Underoverscript[ ∑, (i=1), n])(((f((Subscript[x, i-1])) + f((Subscript[x, i]))))/2)Δx


Each line of code in a notebook must be executed by either using the Evaluate cell tab under the 
heading of Evaluation in the Mast  or by selecting -shift-return on the keyboard.

F1[x_]:=Exp[x^2]/6
F1[x]
F2[x_]:=Sqrt[1-x^4]
F2[x]
F3[x_]:= Sin[x^2]
F3[x]

We may plot a function with the following command. Note the set backets that pair functions and also pair the limits.

Plot[{F1[x],F2[x],F3[x]},{x,-2,3}]

In this case the aspect ration is not quite correct.  We may force the aspect ratio by using the following:

Plot[{F1[x],F2[x],F3[x]},{x,-2,2}, AspectRatio -> Automatic]

Below, we give a graphic of the midpoint rule.

Show[DiscretePlot[F1[t],{t,0.0,2.0,0.1},ExtentSize->Full],Plot[Exp[t^2]/6,{t,0.0,2.0}]]
Show[DiscretePlot[F2[t],{t,0.0,1.5,0.3},ExtentSize->Full],Plot[Sqrt[1-t^4],{t,0.0,1.5}]]
Show[DiscretePlot[F3[t],{t,-Pi,Pi,Pi/6},ExtentSize->Full],Plot[Sin[t^2],{t,-Pi,Pi}]]

AF1:=Integrate[F[t],{t,0,x}]
AF1
AF2:=Integrate[G[t],{t,0,x}]
AF2
AF3:=Integrate[H[t],{t,0,x}]
AF3

We wish to now consider the problem of using numerical methos such as the Riemann midpoint sum which is ultimately the definition of the definte integral in the limit.

n:=3
a:=0.0
b:=2.0
IF1:= Integrate[F1[x],{x,a,b}]
MPA:=Sum[F1[a+ (i-0.5)*(b-a)/n]*(b-a)/n,{i,1,n}]
RPA:=Sum[F1[a+ (i)*(b-a)/n]*(b-a)/n,{i,1,n}]
LPA:=Sum[F1[a+ (i-1)*(b-a)/n]*(b-a)/n,{i,1,n}]
Print["...IA.......MPA........RPA........LPA"]
Print[IF1,"....",MPA,"....",RPA,".....",LPA]

TR :=Sum[(F[a+ i*(b-a)/n]+F[a+(i-1)*(b-a)/n])*(b-a)/(2*n),{i,1,n}]
Print["...IA..........MPA..........RPA.........LPA.........TR"]
Print[IA,".....",MPA,".....",RPA,".....",LPA,".....",TR]

We will compare the various methods. The percent error is

TPE:=Abs[(IA-TR)/IA]*100
MPE:=Abs[(IA-MPA)/IA]*100
LPE:=Abs[(IA-LPA)/IA]*100
RPE:=Abs[(IA-RPA)/IA]*100

Print["n........TPE...........MPE...........RPE...........LPE"]
Print[n,"......",TPE,"........",MPE,".......",RPE,"......",LPE]

Below we combine the results for ease of  use

n:=4
a:=0.0
b:=1.5
F[x_]:=F3[x]
IA:= Integrate[F[x],{x,a,b}]
TR :=Sum[(F[a+ i*(b-a)/n]+F[a+(i-1)*(b-a)/n])*(b-a)/(2*n),{i,1,n}]
MPA=Sum[F[a+ (i-1/2)*(b-a)/n]*(b-a)/n,{i,1,n}]
RPA:=Sum[F[a+ (i)*(b-a)/n]*(b-a)/n,{i,1,n}]
LPA:=Sum[F[a+ (i-1)*(b-a)/n]*(b-a)/n,{i,1,n}]
TPE:=Abs[(IA-TR)/IA]*100
MPE:=Abs[(IA-MPA)/IA]*100
LPE:=Abs[(IA-LPA)/IA]*100
RPE:=Abs[(IA-RPA)/IA]*100
Print[F[x], "  Integral=",IA,",    MPA=",MPA,",   RPA=",RPA,",   LPA=",LPA,",   TR=", TR]
Print["  n= ",n,",  Integral= ", IA,",   TPE= ",TPE,",   MPE= ",MPE,",   RPE= ",RPE,",   LPE= ",LPE]

Take n=4, 6, 9, 12, 20 above and fill in the chart below  for a= 0, b= 2,  and  F(x)=Exp[x^2]/6
n...................IA...............MPE................RPE...........LPE...........TPE 
4             2.7421             1.03                  27                22.9          2.07
6
9
12
20
................................................................................................................
a=  -1.0,  b= 1.0,  for F(x)=Sqrt[1-x^4]
n...................IA...............MPE................RPE...........LPE...........TPE 
4              1.74804            4.93                16.0            16.0           16.0                
6
9
12
20
................................................................................................................
a = 0.0,  b =  1.5,  for F(x)=Sin[x^2]
n...................IA...............MPE................RPE...........LPE...........TPE 
4                0.778             1.42                  15.9           21.6           2.84
6
9
12
20

Write here a short analysis of the various results above.


when finished email this completed file  to 

prcoulton@eiu.edu