Derivatives, Slopes, Tangent Lines, and Making Movies

Introduction

OBJECTIVE: To visualize the derivative and the linearization of a function at a point.

In this module, we explore the derivative as the slope of a nonlinear function and find the equation of the line tangent to a curve at a point. You will learn how to plot the curve and selected tangents on the same graph. In addition, you will see how to use Mathematica to make a movie animation by generating a sequence of plots, each showing a different tangent to the curve. When the sequence of graphs is animated, the tangent lines appear to roll along the graph of the function.

Technology Guidelines

NOTE:  If you have just finished a module, restart Mathematica or Quit Kernel under the Evaluation pull-down menu before executing a new module.
TO OPEN CELLS, click on the arrow to the left of the cell or put your cursor on the right cell bracket and double click. To open all cells, highlight the bracket on the far right and select Grouping under the Cell pull-down menu and select Open All Subgroups.
TO STOP AN EXECUTION
Select the Evaluation pull-down menu and click on Abort Evaluation.
ORDER OF EXECUTION
Execute cells in the order given. Do not skip any Input cells within a given notebook.
SAVING NOTEBOOKS
You can save anytime to any directory you choose, and it is wise to save often. However, before you do your final save to reduce the size of your file, it is a good idea to delete all your output by selecting the Delete All Output selection under the Cell pull-down menu.
EXPERIENCING MAJOR PROBLEMS
Save if appropriate, then shut down Mathematica and start it up again.

Part I: The Derivative at a Point

Define a nonlinear function of your choice, and call it y=f(x) and graph it. For an example, we choose the function f(x)=(x^2) for -2≤x≤2. (To enter a different function and domain, change the red entries in the following input cell.)

Clear[y,f];
(Subscript[x, 0])=-2;  (Subscript[x, f])=2;
y=f[x_]=(x^2)

Plot[y,{x,(Subscript[x, 0]),(Subscript[x, f])},PlotRange->All,PlotStyle->{RGBColor[0,0,1]},AxesLabel->{"x","y"}]

Now pick a point on the function and use the definition of the derivative to find the slope of the function's graph at the point you pick, calling it (Subscript[m, tangent]). We choose x=1 for our example.

(Subscript[m, tangent])=Limit[((f[1+h]-f[1])/h),h->0]

Part II: The Linearization of a Function

Form a new function for the line that is tangent to the function that you chose in the "You Try It" section at the point you picked in Part I, and call it (Subscript[y, tangent])=L[x_]. This function is called the linearization of y=f(x) at the point (1, f(1))

(Subscript[y, tangent])=L[x_]=f[1]+(Subscript[m, tangent])*(x-1)

Plot the function and the tangent line on the same graph.

Plot[{f[x],L[x]},{x,(Subscript[x, 0]),(Subscript[x, f])},PlotRange->All,PlotStyle->{{RGBColor[0,0,1]},{RGBColor[1,0,0]}},AxesLabel->{"x","(Subscript[y, tangent])"}]

Part III: The Derivative Function

Form the derivative function that will give the slope of the tangent to your chosen function at any point with coordinates (x,f(x)). Call the derivative function yprime[x_ ] , and graph it.

yprime[x_]=Limit[((f[x+h]-f[x])/h),h->0]

Graph yprime[ x ].

Plot[yprime[x],{x,(Subscript[x, 0]),(Subscript[x, f])},PlotStyle->{RGBColor[0,1,0]},AxesLabel->{"x","yprime"}]

Part IV: A Whole Bunch of Tangents

Form a new Mathematica function that gives the equation of the line tangent to y=f(x) at the point (a,f(a)). Call the new function tanline[x_, a_ ].

Clear[tanline];
tanline[x_,a_]:=f[a]+yprime[a]*(x-a)

Test your tanline[x_,a_] for several values of a by plotting the tangent lines and y=f(x) together on the same graph. First, use the tanline[x_, a_ ] function and the Table[ ] command to generate a list of equations for the tangents to the curve at points (a,f(a)), for values of a varying from -2 to 2 in increments of 0.1. Then graph the tangent lines and y=f(x) together on the same graph.

listoftangentlines=Table[tanline[x,a],{a,(Subscript[x, 0]),(Subscript[x, f]),0.2}]

p1=Plot[Evaluate[listoftangentlines],{x,(Subscript[x, 0]),(Subscript[x, f])},PlotStyle->{RGBColor[0,0,1]},AxesLabel->{"x","(Subscript[y, tangent])"}]

p2=Plot[y,{x,(Subscript[x, 0]),(Subscript[x, f])},PlotRange->All,PlotStyle->{RGBColor[1,0,0],Thickness[0.01`]},AxesLabel->{"x","(Subscript[y, tangent])"}]

Show[{p1,p2}]

Part V: Making Movies

The following command generates a sequence of graphs that you can animate. Set the PlotRange so that all the graphs in the sequence are the same size; Otherwise, the picture will jump around in the animation. You can adjust the vertical limits (in red letters) in the PlotRange option to make the animation fit correctly in the viewing window.
You can stop, slow down, speed up, or reverse the animation with the buttons.

Animate[Plot[{f[x],tanline[x,a]},{x,(Subscript[x, 0]),(Subscript[x, f])},PlotRange->{{(Subscript[x, 0]),(Subscript[x, f])},{-2,4}},PlotStyle->{{RGBColor[1,0,0]},{RGBColor[0,0,1]}},AxesLabel->{"x","(Subscript[y, tangent])"}],{a,(Subscript[x, 0]),(Subscript[x, f]),0.2`}]

You Try It

First, work through Parts I - V with the example function f(x)=(x^2), and then repeat the steps in Parts I - V for some functions that you select. Here are some suggestions.

1. (x^3)  for  -2≤x≤2

2.  sin x  for  0≤x≤2π

3.  (e^(-(x^2)))  for  -2≤x≤2

4.  (Sqrt[x])  for  0<x≤4   Note that we do not include x=0. Do you know why?