Section 4.1
Calculus I
Andy Long

(* Example of Section 4.1: areas and distances *)
Minutes={0, 1,2,3,4,5,6,7,8,9,10}
Speeds={0,30,45,30,70,65,70,70,45,30,35}
Data=Transpose[{Minutes,Speeds}];
ListPlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}]
ListLinePlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}]
n=Length[Speeds] ;
DeltaX=1;
RRR=N[DeltaX*Sum[Speeds[[i]],{i,2,n}]]
LRR=N[DeltaX*Sum[Speeds[[i]],{i,1,n-1}]]
TRAP=(RRR+LRR)/2

But what are the units of our answer? And what should they be?

RRR=N[Sum[Speeds[[i]],{i,2,n}]]/60
LRR=N[Sum[Speeds[[i]],{i,1,n-1}]]/60
TRAP=(RRR+LRR)/2

p1=ListPlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}]
times=Flatten[Table[{Minutes[[i]],Minutes[[i]]},{i,2,n-1}]]
times=Flatten[{Minutes[[1]],times,Minutes[[n]]}]
rights=Flatten[Table[{Speeds[[i]],Speeds[[i]]},{i,2,n}]]
lefts=Flatten[Table[{Speeds[[i]],Speeds[[i]]},{i,1,n-1}]]
Data=Transpose[{times,lefts}];
p2=ListLinePlot[Data,Filling->Axis,FillingStyle->Orange,PlotStyle->{Thick,PointSize[Large]}]
Data=Transpose[{times,rights}];
p3=ListLinePlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}]
Show[p2,p3,p1]

(* #14, p. 294 *)
Minutes=12*{0, 1,2,3,4,5}
Speeds={30,28,25,22,24,27}
Data=Transpose[{Minutes,Speeds}];
ListPlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]},AxesOrigin->{0,0}]
n=Length[Speeds] ;
DeltaX=12;
RRR=N[Sum[Speeds[[i]],{i,2,n}]]*DeltaX
LRR=N[Sum[Speeds[[i]],{i,1,n-1}]]*DeltaX
TRAP=(RRR+LRR)/2

p1=ListPlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}]
times=Flatten[Table[{Minutes[[i]],Minutes[[i]]},{i,2,n-1}]]
times=Flatten[{Minutes[[1]],times,Minutes[[n]]}]
rights=Flatten[Table[{Speeds[[i]],Speeds[[i]]},{i,2,n}]]
lefts=Flatten[Table[{Speeds[[i]],Speeds[[i]]},{i,1,n-1}]]
Data=Transpose[{times,lefts}];
p2=ListLinePlot[Data,Filling->Axis,FillingStyle->Orange,PlotStyle->{Thick,PointSize[Large]}]
Data=Transpose[{times,rights}];
p3=ListLinePlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}]
Show[p2,p3,p1]

Again,  what are the units of our answer?

Also, can we assert (confidently) that any answers are over- or under-estimates?

(* #6, p. 293 *)
f[x_]:=1/(1+x^2)
P1=Plot[f[x],{x,-2,2},AxesOrigin->{0,0}];

DeltaX=1
Minutes=Table[i,{i,-2,2,DeltaX}];
Speeds=f[Minutes];
Data=Transpose[{Minutes,Speeds}];
P2=ListPlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]},AxesOrigin->{0,0}];
n=Length[Speeds] 
RRR=N[DeltaX*Sum[Speeds[[i]],{i,2,n}]]
LRR=N[DeltaX*Sum[Speeds[[i]],{i,1,n-1}]]
TRAP=(RRR+LRR)/2
MID=N[DeltaX*Sum[f[Minutes[[i]]+DeltaX/2],{i,1,n-1}]]
SIMP=(2*MID+TRAP)/3
Show[P1,P2]

Let’s look at the midpoint method:

mids=Flatten[Table[{f[Minutes[[i]]+DeltaX/2],f[Minutes[[i]]+DeltaX/2]},{i,1,n-1}]]
times=Flatten[Table[{Minutes[[i]],Minutes[[i]]},{i,2,n-1}]]
times=Flatten[{Minutes[[1]],times,Minutes[[n]]}]
Data=Transpose[{times,mids}];
p3=ListLinePlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}];
Show[P1,p3]

(* Ultimately this is what we'll do using a CAS: *)
Integrate[f[x],{x,-2,2}]
N[%]

(* #15: Example of Section 4.1: areas and distances *)
Hours={0, 2,4,6,8,10}
Rates={8.7,7.6,6.8, 6.2, 5.7,5.3} (* units of L/h *)
Data=Transpose[{Hours,Rates}];
ListPlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}]
ListLinePlot[Data,Filling->Axis,PlotStyle->{Thick,PointSize[Large]}]
n=Length[Rates] ;
DeltaX=1;
RRR=N[DeltaX*Sum[Rates[[i]],{i,2,n}]]
LRR=N[DeltaX*Sum[Rates[[i]],{i,1,n-1}]]
TRAP=(RRR+LRR)/2