ClearAll;
$DefaultFont = {"Times-Roman",10};
Needs["Graphics`Graphics`"];
njags = 100;
L = 0.5; R = 1.5;
ftl[x_]:= 1+x^(5/2);
ftr[x_]:= 5 - (x-2)^2;
fbl[x_]:= (x-2)^2 + 1;
fbr[x_]:= 5 - x^2;
nftl[x_]:= -(1+x^(5/2));
nftr[x_]:= -5 + (x-2)^2;
nfbl[x_]:= - (x-2)^2 - 1;
nfbr[x_]:= - 5 + x^2;

linetr = Graphics[{Dashing[{0.001,0.01}],Line[{{L,ftr[L]},{R,ftr[L]}}]}];
linebr = Graphics[{Dashing[{0.001,0.01}],Line[{{L,fbr[R]},{R,fbr[R]}}]}];
nlinetr = Graphics[{Dashing[{0.001,0.01}],Line[{{L,nftr[L]},{R,nftr[L]}}]}];
nlinebr = Graphics[{Dashing[{0.001,0.01}],Line[{{L,nfbr[R]},{R,nfbr[R]}}]}];
shadetl = Graphics[{GrayLevel[0.35],Polygon[Join[Table[{L+i(R-L)/njags,ftl[L+i(R-L)/njags]},{i,0,njags}],
     			{{R,0},{L,0}}]]}];
shadetr = Graphics[{GrayLevel[0.35],Polygon[Join[Table[{L+i(R-L)/njags,ftr[L+i(R-L)/njags]},{i,0,njags}],
     			{{R,0},{L,0}}]]}];
shadebl = Graphics[{GrayLevel[0.35],Polygon[Join[Table[{L+i(R-L)/njags,fbl[L+i(R-L)/njags]},{i,0,njags}],
     			{{R,0},{L,0}}]]}];
shadebr = Graphics[{GrayLevel[0.35],Polygon[Join[Table[{L+i(R-L)/njags,fbr[L+i(R-L)/njags]},{i,0,njags}],
     			{{R,0},{L,0}}]]}];
nshadetl = Graphics[{GrayLevel[0.35],Polygon[Join[Table[{L+i(R-L)/njags,nftl[L+i(R-L)/njags]},{i,0,njags}],
     			{{R,0},{L,0}}]]}];
nshadetr = Graphics[{GrayLevel[0.35],Polygon[Join[Table[{L+i(R-L)/njags,nftr[L+i(R-L)/njags]},{i,0,njags}],
     			{{R,0},{L,0}}]]}];
nshadebl = Graphics[{GrayLevel[0.35],Polygon[Join[Table[{L+i(R-L)/njags,nfbl[L+i(R-L)/njags]},{i,0,njags}],
     			{{R,0},{L,0}}]]}];
nshadebr = Graphics[{GrayLevel[0.35],Polygon[Join[Table[{L+i(R-L)/njags,nfbr[L+i(R-L)/njags]},{i,0,njags}],
     			{{R,0},{L,0}}]]}];
polytl = Graphics[{GrayLevel[0.65],Polygon[{{L,0},{L,ftl[L]},{R,ftl[R]},{R,0}}]}];
polytr = Graphics[{GrayLevel[0.65],Polygon[{{L,0},{L,ftr[L]},{R,ftr[R]},{R,0}}]}];
polybl = Graphics[{GrayLevel[0.65],Polygon[{{L,0},{L,fbl[L]},{R,fbl[R]},{R,0}}]}];
polybr = Graphics[{GrayLevel[0.65],Polygon[{{L,0},{L,fbr[L]},{R,fbr[R]},{R,0}}]}];
npolytl = Graphics[{GrayLevel[0.65],Polygon[{{L,0},{L,nftl[L]},{R,nftl[R]},{R,0}}]}];
npolytr = Graphics[{GrayLevel[0.65],Polygon[{{L,0},{L,nftr[L]},{R,nftr[R]},{R,0}}]}];
npolybl = Graphics[{GrayLevel[0.65],Polygon[{{L,0},{L,nfbl[L]},{R,nfbl[R]},{R,0}}]}];
npolybr = Graphics[{GrayLevel[0.65],Polygon[{{L,0},{L,nfbr[L]},{R,nfbr[R]},{R,0}}]}];

tl = Show[Plot[ftl[x],{x,0,2},PlotRange->{{-1,2.5},{-1,6}},
		  PlotLabel->"INCREASING, CONCAVE UP",
		  AxesOrigin->{-0.5,0},  
		  Axes->True,Ticks->{{{L,"L"},{R,"R"}},{{ftl[L],"f(L)"},{ftl[R],"f(R)"}}},
		  AxesLabel->{"x"," "}],polytl,shadetl];
tr = Show[Plot[ftr[x],{x,0,2},PlotRange->{{-1,2.5},{-1,6}},
		  PlotLabel->"          INCREASING, CONCAVE DOWN",
		  AxesOrigin->{-0.5,0},   
		  Axes->True,Ticks->{{{L,"L"},{R,"R"}},{{ftr[L],"f(L)"},{ftr[R],"f(R)"}}},
		  AxesLabel->{"x"," "}],shadetr,polytr,linetr];
bl = Show[Plot[fbl[x],{x,0,2},PlotRange->{{-1,2.5},{-1,6}},
		  PlotLabel->"DECREASING, CONCAVE UP",
		  AxesOrigin->{-0.5,0},   
		  Axes->True,Ticks->{{{L,"L"},{R,"R"}},{{fbl[L],"f(L)"},{fbl[R],"f(R)"}}},
		  AxesLabel->{"x"," "}],polybl,shadebl];
br = Show[Plot[fbr[x],{x,0,2},PlotRange->{{-1,2.5},{-1,6}},
		  PlotLabel->"          DECREASING, CONCAVE DOWN",
		  AxesOrigin->{-0.5,0},   
		  Axes->True,Ticks->{{{L,"L"},{R,"R"}},{{fbr[L],"f(L)"},{fbr[R],"f(R)"}}},
		  AxesLabel->{"x"," "}],shadebr,polybr,linebr];
ntl = Show[Plot[nftl[x],{x,0,2},PlotRange->{{-1,2.5},{-6,1}},
		  PlotLabel->"          DECREASING, CONCAVE DOWN",
		  AxesOrigin->{-0.5,0},  
		  Axes->True,Ticks->{{{L," "},{R," "}},{{nftl[L],"f(L)"},{nftl[R],"f(R)"}}},
		  AxesLabel->{"x"," "}],npolytl,nshadetl];
ntr = Show[Plot[nftr[x],{x,0,2},PlotRange->{{-1,2.5},{-6,1}},
		  PlotLabel->"DECREASING, CONCAVE UP",
		  AxesOrigin->{-0.5,0},   
		  Axes->True,Ticks->{{{L," "},{R," "}},{{nftr[L],"f(L)"},{nftr[R],"f(R)"}}},
		  AxesLabel->{"x"," "}],nshadetr,npolytr,nlinetr];
nbl = Show[Plot[nfbl[x],{x,0,2},PlotRange->{{-1,2.5},{-6,1}},
		  PlotLabel->"          INCREASING, CONCAVE DOWN",
		  AxesOrigin->{-0.5,0},   
		  Axes->True,Ticks->{{{L," "},{R," "}},{{nfbl[L],"f(L)"},{nfbl[R],"f(R)"}}},
		  AxesLabel->{"x"," "}],npolybl,nshadebl];
nbr = Show[Plot[nfbr[x],{x,0,2},PlotRange->{{-1,2.5},{-6,1}},
		  PlotLabel->"INCREASING, CONCAVE UP",
		  AxesOrigin->{-0.5,0},   
		  Axes->True,Ticks->{{{L," "},{R," "}},{{nfbr[L],"f(L)"},{nfbr[R],"f(R)"}}},
		  AxesLabel->{"x"," "}],nshadebr,npolybr,nlinebr];

over = Show[GraphicsArray[{{tl,ntr},{bl,nbr}}],
	PlotLabel->"Trapezoidal Overestimates of Int(f,[L,R])"];
under = Show[GraphicsArray[{{tr,ntl},{br,nbl}}],
	PlotLabel->"Trapezoidal Underestimates of Int(f,[L,R])"];	
	
Show[GraphicsArray[{{over},{under}}],
	PlotLabel->"Figure 12.7"]