Demonstration, August 24, 2009
Local straightness and the tangent line

Some programming.

Needs["Graphics`Colors`"] 
Clear[plot,f,a,scale,plot1,TangentLine,plotboth,scale]; plot:=Show[{ plot1,center}, DisplayFunction->$DisplayFunction]; 
center := Graphics[{Red, PointSize[.03],Point[{a, f[a]}]}];
plot1:=Plot[f[x],{x,a-scale,a+scale},PlotStyle->{AbsoluteThickness[2],Blue},  DisplayFunction->Identity]; TangentLine:=Plot[flin[x],{x,a-scale,a+scale},PlotStyle->{AbsoluteThickness[2],Red},DisplayFunction->Identity]; plotboth:=Show[{TangentLine,plot1, center},DisplayFunction->$DisplayFunction]; fsec[a_,h_,x_]:=f[a]+(((x-a) (f[a+h]-f[a]))/h); SecantLine:=Plot[fsec[a,h,x],{x,a-scale,a+scale},PlotStyle->{AbsoluteThickness[2],Green},DisplayFunction->Identity];plotall:=Show[{TangentLine,plot1,SecantLine, center},DisplayFunction->$DisplayFunction];

Define a function f[x].

Clear[f, a];
f[x_] := 2x - x^2 + x^3 ;
a = 1.6
f[a]

The graph of f[x] on different scales, near x = a:

scale = 10;
plot

scale = 1;
plot
scale = .1;
plot
scale = .01;
plot
scale = .001;
plot

Numerical computation of the slope  ((f[a+h] - f[a])/h) when h is small.

htable= Table[.1^n, {n, 0, 8}];
secantslope[h_] :={h,  ((f[a+h]-f[a])/h)};
slopetable =TableForm[ Map[ secantslope, htable]]

The tangent line to the graph at x = a has slope approximately equal to the number we computed
Slope of tangent line  needs to be filled in here by hand!

m = 6.48;

Formula for the tangent line:       y = f[a] + m*(x-a).

tangentLine = Expand[f[a] + m*(x-a)]
flin[x_] := Expand[f[a] +  m * (x - a)]

Plot of function and tangent line together, on different scales, near x = a:

scale = 10;
plotboth
scale = 1;
plotboth
scale = .1;
plotboth
scale = .01;
plotboth

How good is the approximation of the actual function f[x] by the linear approximation flin[x]?

Consider the difference ϵ[h] = f[a + h] - flin[a  + h],  where y = flin[x] =   f[a] + m*(x-a).  is the tangent line that we computed.  Thus ϵ[h] is the difference between the actual function and  the linear approximation at the x value x = a + h,  close to a.    

What we observe is that, as h --> 0,  ϵ[h] goes to zero SO FAST,  that ((ϵ[h])/h) STILL goes to zero.  Remember that
((ϵ[h])/h) is  ϵ[h]  multiplied by the HUGE number  (1/h).

ϵ[h_] := f[a+h] - flin[a+h]
htable= Table[.1^n, {n, 0, 8}];
error[h_] :={h,  ϵ[h], ϵ[h]/h};
errorTable = Map[ error, htable];
errorTable = Prepend[ errorTable, {"h", "ϵ[h]", "ϵ[h]/h"}];
TableForm[errorTable]

Examples and counterexamples

f[x] = Abs[x]

Clear[f, a];
f[x_] :=Abs[x];
a = 0;
f[a];
scale = 10;
plot

scale = 1;
plot
scale = .1;
plot
scale = .01;
plot
scale = .001;
plot

f[x] = x^3

plot1:=Plot[f[x],{x,a-scale,a+scale},PlotStyle->{AbsoluteThickness[2],Blue},  DisplayFunction->Identity, AspectRatio->
Automatic];
Clear[f, a];
f[x_] :=x^3;
a = 0
f[a]
scale = 1;
plot
scale = .5;
plot
scale = .1;
plot

flin[x_] :=0

scale = 1;
plotboth
scale = .5;
plotboth
scale = .1;
plotboth

f[x] = x^2 Sin[1/x]

plot1:=Plot[f[x],{x,a-scale,a+scale},PlotStyle->{AbsoluteThickness[2],Blue},  DisplayFunction->Identity, AspectRatio->Automatic];
Clear[f, a];
a=0;
f[0]=0;
f[x_] :=x^2 Sin[1/x];

scale = .5;
plot
scale = .1;
plot
scale = .01;
plot

flin[x_] :=0

scale = 1;
plotboth
scale = .5;
plotboth
scale = .1;
plotboth

Approximation to the tangent line by secant lines.

scale = 2;
h = 1;
plotall
h = .5;
plotall
h = .1;
plotall
h = .01;
plotall

Exercises

Exercise 1.

Exercise 2.

Clear[f, a,m];
f[x_] := Sin[x^2];
a = 1.43;
For[n=1,n≤8,n++,
	h=((.1)^n);
	Print[((f[a+h]-f[a])/h)]]

m =  ????

flin[x_] := Expand[f[a] +  m * (x - a)]
scale = 2;
h = .5;
plotall;
h = .1;
plotall;
h = .01;
plotall;