Secant and Tangent Lines

f[x_]=-(x^3) + (x^2) + (12*x) - 3;
      (* define a function of x here *)

xmin = -6;                              (* function max and min x values set here *)
xmax = 6;

astart = -3.5;      (* point of tangency starting point value *)
amin = -4.3;      (* point of tangency minimum value *)
amax= 5;          (* point of tangency maximum value *)

hstart = 2;      (* Secant line intersection starting point *)
hmin = -1.3;      (* Secant line intersection minimum value *)
hmax = 8.5;       (* Secant line intersection maximum value *)

Manipulate[
If[h==0,h=.001];
Grid[{
{
Show[{
Plot[{f[x],
If[tl,f[a]+(D[f[t],t]/.t->a)*(x-a),0],
f[a]+((f[a+(0.95^n)Cos[n]h]-f[a])/((0.95^n)Cos[n]h))*(x-a)} ,
 {x,xmin,xmax}, 
PlotStyle->{{Thickness[.005],Black},{Thin,Blue}, {Thickness[.004],Red}},PlotRange->{15*xmin,(8*xmax) + 2}, 
ImageSize->{475,325},
PlotLabel ->Style[Row[{Style["f(x)",Italic]," = ",ToString[- x^3+ x^2+ 12 x - 3,TraditionalForm]}],20],
Ticks->{{{a,"(Subscript[x, 0])",{0,0.05}},{a+h,"(Subscript[x, 0])+h",{0,0.05}},{((2a+h)/2),"h",{0,.2}}},None},TicksStyle->Directive[Blue,18],

AxesLabel-> {Style["x",16,Italic],Style["y",16,Italic]},
Prolog->{{PointSize[.02],If[tl,Blue,Red], Point[{a,f[a]}]},{PointSize[.02],Red, Point[{a+(0.95^n)Cos[n]h,f[a+(0.95^n)Cos[n]h]}]}}],
Graphics[{Blue,Thick,Line[{{a,0.4},{a+h,0.4}}]}]
}]
},{
Row[{If[tl,Style[Text["tangent slope = "<>ToString[D[f[t],t]/.t->a]], Blue, 20]],Style[Text["secant slope =  "<>ToString[(f[a+(0.95^n)Cos[n]h]-f[a])/((0.95^n)Cos[n]h)]], Red, 20]},"    "]
}
}], 

(*Manipulate Controllers*)
Style["Secant and Tangent Lines",Bold,12],(*Title*)
{{a, astart,"(Subscript[x, 0])"},amin,amax},
 {{h,hstart,"h"}, hmin,hmax},
{{n,0,"animate"},0,100,.025},
{{tl,False,"tangent line"},{True,False}},AutorunSequencing -> {{3,60}},
TrackedSymbols->{a,h,tl,n}, ImageSize->Small,ControlPlacement->Left,SaveDefinitions->True]

Velocity of a Falling Object

s[t_]:=-16*t^2+20

Manipulate[
If[time==(Subscript[t, 0]),time=(Subscript[t, 0])+.0001];
Grid[
(*first row*){{Text@TableForm[Table[{NumberForm[t,{4,1}],NumberForm[s[t],{6,4}]},{t,0,1.1,.1}],TableHeadings->{{" "},{Row[{" time ",Style["t ",Italic]}],Row[{" height ",Style["s ",Italic]}]}},TableAlignments->Right],Show[Plot[s[t],{t,0,1.2},PlotRange->{-1,21},AxesLabel->{Style["t",Italic],Style["s",Italic]},PlotStyle->Thickness[.006],ImageSize->Medium,PlotLabel ->Style[Row[{Style["s",Italic],"(",Style["t",Italic],")"," = ",ToString[- 16t^2+20,TraditionalForm]}],14]],
ListPlot[Table[{0,s[t]},{t,0,1.1,.1}],PlotStyle->{RGBColor[.9,.42,.17],PointSize[Large]}],ListPlot[Table[{t,s[t]},{t,0,1.1,.1}],PlotStyle->{RGBColor[.25,.43,.82],PointSize[Large]}],
ListPlot[{{0,s[time]},{time,s[time]}},PlotStyle->{RGBColor[.48,.11,.56],PointSize[Large]}],ImageSize->{400,200}]},
(*second row*)
{Framed[Column[{Style[Text[Row[{"From time ",Style["t",Italic]," to ",Subscript[Style["t",Italic],0],":"}]],Black,16],Style[Text[Row[{"Δ",Style["s",Italic]," = ",NumberForm[-Abs[s[(Subscript[t, 0])]-s[time]],{6,4}]}]], RGBColor[.9,.42,.17], 14],
Style[Text[Row[{"Δ",Style["t",Italic]," = ",NumberForm[Abs[(Subscript[t, 0])-time],{6,4}]}]],RGBColor[.25,.43,.82],14],
Style[Text[" "], RGBColor[.48,.11,.56],16],
Style[Text["average velocity"], RGBColor[.48,.11,.56],16],
Style[Text[Row[{"Δ",Style["s",Italic],"/Δ",Style["t",Italic]," = " ,NumberForm[(s[(Subscript[t, 0])]-s[time])/((Subscript[t, 0])-time),{5,3}]}]], RGBColor[.48,.11,.56],16]}]],Show[Plot[{s[t],s[(Subscript[t, 0])]+(s[time]-s[(Subscript[t, 0])])/(time-(Subscript[t, 0]))*(t-(Subscript[t, 0]))},{t,0,1.2},PlotRange->{-1,21},AxesLabel->{Style["t",Italic],Style["s",Italic]},PlotStyle->Thickness[.006],ImageSize->Medium],
Graphics[{RGBColor[.9,.42,.17],Thick,Line[{{time,s[time]},{time,s[(Subscript[t, 0])]}}]}],
Graphics[{RGBColor[.25,.43,.82],Thick,Line[{{time,s[(Subscript[t, 0])]},{(Subscript[t, 0]),s[(Subscript[t, 0])]}}]}], ListPlot[{{0,s[time]},{(Subscript[t, 0]),s[(Subscript[t, 0])]},{time,s[time]}},PlotStyle->{RGBColor[.48,.11,.56],PointSize[Large]}],ImageSize->{400,200}]}}],

(*Manipulate Controllers*)
Style["Average Rate of Change and Velocity",Bold,12],(*Title*)
{{time,.5,"time t"},0,1.2,.01,Appearance->"Labeled"},
{{(Subscript[t, 0]),1},{.2,.6,1}},
ImageSize->Small,ControlPlacement->Left,SaveDefinitions->True]