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;      (* point of tangency starting point value *)
amin = -4.3;      (* point of tangency minimum value *)
amax= 5;          (* point of tangency maximum value *)

hstart = 0;      (* Secant line intersection starting point *)
hmin = -4;      (* Secant line intersection minimum value *)
hmax = 4;       (* Secant line intersection maximum value *)
Manipulate[
If[h==0,h=.001];Grid[{{Plot[{f[x],f[a]+(D[f[t],t]/.t->a)*(x-a), If[tl,f[a]+((f[a+h]-f[a])/h)*(x-a)]} , {x,xmin,xmax}, PlotStyle->{{Thickness[.005],Black},{Thickness[.004],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],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+h,f[a+h]}]}}]},{Row[{Style[Text["tangent slope = "<>ToString[D[f[t],t]/.t->a]], Blue, 20],If[tl,Style[Text["secant slope =  "<>ToString[(f[a+h]-f[a])/h]], Red, 20]]},"    "]}}], 
{{a, astart,"(Subscript[x, 0])"},amin,amax},
 {{h,hstart,"h"}, hmin,hmax,.01},
{{tl,False,"secant line"},{True,False}},
TrackedSymbols->{a,h,tl}, SaveDefinitions->True]

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Secant and Tangent Lines" from The Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/SecantAndTangentLines/

Contributed by: Joshua Fritz, Angela Sharp, and Chad Pierson

A full-function Wolfram Mathematica 6 system is required to edit or run this notebook.
(Mathematica Player runs only Demonstrations published on this site.)
GET WOLFRAM MATHEMATICA 6 »

© The Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »