Mathematical Principles for Scientific Computing and Visualization  
http://www.farinhansford.com/books/scv
by Gerald Farin and Dianne Hansford



Demonstrate the derivative as the slope of the tangent to the function

Step 1: View the plot of f alone. (The range of x-values was selected to help with the visualization in the next step.)

Step 2: Add the linear functions t1, t2, t3 to the plot.

In the successive tangent lines below, we use a smaller h, thus coming closer the true tangent. Try decreasing h in t3.

Step 3: Plot the true tangent at x=2.

Define fderiv -- the derivative (slope) of f 
Define ftangent as the tangent line at x=2. It is defined by the function at x=2 and the derivative at x=2

f[x_] := x^4

t1[x_] := f[2] + ((f[3]-f[2])/(3-2))(x - 2)
t2[x_] := f[2] + ((f[2.5]-f[2])/(2.5-2))(x - 2)
t3[x_] := f[2] + ((f[2.01]-f[2])/(2.01-2))(x - 2)

fderiv[x_] := 4x^3
(* tangent line at x=2 *)
ftangent[x_] := f[2] + fderiv[2](x - 2)

Plot[{f[x],t1[x], t2[x], t3[x], ftangent[x]}, {x,1,3.5}]