Name:	John Luker

Title:		Area between the curve y = f(x) and the x-axis 							using a Trapezoidal Approximation

Description:	
						The lesson successively draws the curve, shows the area, breaks the region into trapezoids, 										computes the area of one trapezoid, sums the 									areas of all the trapezoids and then computes 									the area using NIntegrate.

Area between the curve y = f(x) and the  x-axis
using a
Trazepoidal Approximation

Define a curve y = f(x) and take a look at its graph on a specified domain.

Clear[f,x,jump,a,b,c,d]
a = 0																								(*left limit of domain*)
b = 1.5																					(*right limit of domain*)
c = -1																							(*lower limit of range*)
d = 1																								(*upper limit of range*)
f[x_] = Sin[Pi x]
curveplot = Plot[f[x],{x,a,b},PlotRange->{c,d},
																PlotStyle->{Thickness[.006]},
																AxesOrigin->{0,0},
																AxesLabel->{"x","y"}];

Take a look at what constitutes the area between the curve y = f(x) and the x-axis.

Clear[number,jump,x,block,blockplot,k,ii,vline,
						vlineplot]
number = 15;
jump = (b-a)/number;
xpoints = Table[{x,0},{x,a,b,jump}]
points = Table[{x,f[x]},{x,a,b,jump}];

block[k_] := Graphics[{GrayLevel[.75],
																		Polygon[{xpoints[[k-1]],
																		xpoints[[k]],
                  points[[k]],
                  points[[k-1]]}]}]

blockplot[m_] := Table[block[ii],{ii,2,m}]

vline[k_]     := Graphics[Line[
																									{xpoints[[k]],points[[k]]}]]

vlineplot[m_] := Table[vline[ii],{ii,2,m}]

Do[
			Show[curveplot,blockplot[m]],{m,2,number+1}]

To approximate the area we will divide the region into a series of trapezoids, find the area of each individual trapezoid and then sum these areas.  First, define the number of trapezoids.

Clear[number,jump]
number = 9
jump = (b-a)/number

Now divide the x-axis into equally spaced regions, the number of regions equaling the number of trapezoids

xpoints = Table[{x,0},{x,a,b,jump}]
xpointsplot = ListPlot[xpoints,
													         	PlotStyle->{RGBColor[0,0,1],
													                     	PointSize[.015]},
													         	DisplayFunction->Identity]
Show[curveplot,xpointsplot];

Next we will compute and plot f(x) for each x.

points = Table[{x,f[x]},{x,a,b,jump}];
pointplot = ListPlot[Join[points,xpoints],
												PlotStyle->{RGBColor[0,0,1],PointSize[.015]},
												DisplayFunction-> Identity]
brokenlineplot = Graphics[Line[points]];
Show[curveplot,pointplot];

Now we can complete the trapezoids by joining appropriate points.

pointplot = ListPlot[Join[points,xpoints],
												PlotStyle->{RGBColor[0,0,1],PointSize[.015]},
												DisplayFunction-> Identity]
brokenlineplot = Graphics[Line[points]];
Clear[vline]
vline[k_] := Graphics[Line[{xpoints[[k]],points[[k]]}]];
Clear[ii]
vlineplot = Table[vline[ii],{ii,1,Length[xpoints]}]
	
Show[curveplot,pointplot,brokenlineplot,vlineplot];

Once the trapezoids have been formed we can compute the area of a specific trapezoid, say the 3rd trapezoid.

Clear[trap]
trap[x_] := Graphics[{GrayLevel[.75],
												Polygon[{{x,0},{x,f[x]},{x+jump,f[x+jump]},{x+jump,0}}]}]
Show[curveplot,pointplot,brokenlineplot,vlineplot,trap[2 jump]]
Area = N[(jump (f[2 jump] + f[2 jump+jump]))/2]

The idea, of course, is to compute the area of all the trapezoids and then sum them.

Area = N[Sum[jump (f[x] + f[x+jump])/2,{x,0,1-jump,jump}]]

Finally we can let Mathematica compute the area using its internal numerical routine and compare the answer to the one we obtained.

NIntegrate[f[x],{x,0,1}]