Examples from Section 1.4

Univariate Calculus
Andy Long

#1, p. 49

xs={5,10,15,20,25,30} (* this is a list of x values: just like on a TI calculator, you can compute with lists, to save some time. *)
ys={694,444,250,111,28,0} (* here's a list of y values *)
p1=ListPlot[Transpose[{xs,ys}],PlotMarkers->{Automatic,Large}] (* now we plot the points, using ListPlot *)

slopes=(ys-ys[[3]])/(xs-xs[[3]]) (* here we compute with lists, subtracting the third point -- the one with x=15 -- in the slope equation *)
N[slopes] (* these are the numerical values, obtained using the N function, rather than fractions *)

We can get a good guess to the true slope of the tangent line by using the two points closest to 15 (surrounding the point of interest):

slope=N[(ys[[4]]-ys[[2]])/(xs[[4]]-xs[[2]])] (* here I compute the numerical value of the slope, using the N function *)

Show[p1,Plot[slope*(x-xs[[3]])+ys[[3]],{x,xs[[1]],xs[[6]]}]] (* now I show the original data, plus the "tangent line" (well, an approximation....) *)

#4, p. 49

Clear[f,a,b]
f[x_]:=Cos[Pi x]
a=.5;
b=0;
xs={0,.4,.49,.499,1,.6,.51,.501};
ys=f[xs];
slopes=(ys-0)/(xs-0.5) (* again I compute with a list *)
p1=ListPlot[Transpose[{xs,ys}],PlotMarkers->{Automatic,Medium}];
p2=Plot[f[x],{x,0,1}];
Show[p1,p2]

slope=(ys[[4]]-ys[[8]])/(xs[[4]]-xs[[8]]) (* the fourth and eighth points are actually the two points closest to x=0.5 *)

The curve and the tangent line:

p3=Plot[slope*(x-.5),{x,0,1}];
Show[p1,p2,p3]

#5, p. 49

height[t_]:=40t-16t^2
Plot[height[t],{t,0,2.5}]

ts=2+{0.5,.1,.05,.01}
hs=height[ts]
slopes=(hs-height[2])/(ts-2)
p1=Plot[height[t],{t,1.9,2.6}];
p2=ListPlot[Transpose[{ts,hs}],PlotMarkers->{Automatic,Medium}];
Show[p1,p2]

p3=Plot[slopes*(t-ts)+hs,{t,0,2.5}];
Show[p1,p2,p3]

#8, p. 49

s[t_]:=2*Sin[Pi t]+3Cos[Pi t]
Plot[s[t],{t,0,2},PlotLabel->s[t]](* one period *)

AV[t1_,t2_]:=(s[t2]-s[t1])/(t2-t1)
AV[1,2]
AV[1,1.1]
AV[1,1.01]
AV[1,1.001]

slope=AV[1,.99999] (* to estimate the instantaneous velocity at 1, I use a point even closer to 1 to construct the secant line slope approximation: *)
p1=Plot[s[t],{t,0,2},PlotLabel->s[t]] ;
p2=Plot[slope*(t-1)+s[1],{t,0,2}];
Show[p1,p2]