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 = -1;      (* 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[{{Plot[{f[x],If[tl,f[a]+(D[f[t],t]/.t->a)*(x-a)], 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[{If[tl,Style[Text["tangent slope = "<>ToString[D[f[t],t]/.t->a]], Blue, 20]],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},
{{tl,False,"tangent line"},{True,False}},
TrackedSymbols->{a,h,tl}, SaveDefinitions->True]

CAPTION

This Demonstration illustrates the connection between the secant line and the tangent line at a point on a curve. You can vary the point of tangency and the difference h of the x values of the two points defining the secant line.

THIS NOTEBOOK IS THE SOURCE CODE FROM

Joshua Fritz, Angela Sharp, and Chad Pierson

"Secant and Tangent Lines"
 http://demonstrations.wolfram.com/SecantAndTangentLines/
 Wolfram Demonstrations Project
 Published: September 18, 2007

A full-function Wolfram Mathematica system is required to edit this notebook.
GET WOLFRAM MATHEMATICA »

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