2. The Slope and Derivative

Slope of a Straight Line Function

The slope characterizes the steepness of a line;  the larger the slope the steeper the line.  An example is perhaps the best way to clarify the concept of slope.    Consider the straight line function f[t] defined

f[t_] := 3*t + 5

where t is the independent variable.  A graph of f[t] generated by Mathematica  appears

Plot[f[t], {t, -1 ,1 },GridLines->Automatic]

The slope of f[t] is defined

((Δf)/(Δt))=((f[(Subscript[t, 2])]-f[(Subscript[t, 1])])/((Subscript[t, 2])-(Subscript[t, 1])))

and the calculation of the slope requires that you pick two points on the line (which are labeled points 1 and 2 in the figure on the next page).  For example, for the function at hand, choose the two points indicated below:

Note that Δt = (t 2 - t 1) = 1.0 is the horizontal distance indicated on the graph and Δf = (f2 - f1) = (8-5)=3 is the vertical distance indicated.  The numerical value of the slope of this straight line is

((Δf)/(Δt))=(((8-5))/1)=3

Since t2 = t1 + Δt   another way of writing equation (1) is

((Δf)/(Δt))=((f[(Subscript[t, 1])+Δt]-f[(Subscript[t, 1])])/(Δt))

This is called the slope of f[t] at the point t1.  It is a simple matter to have Mathematica  calculate the slope using equation (3)

Δt=1.0;
Slope[t_]:=((f[t+Δt]-f[t])/(Δt))

Notice the subscript 1 on t1 is dropped for simplicity.  Also, notice Δt=1.0 is given the numerical value before Δt is used in the definition of the Slope function.  Mathematica  can now answer a variety of numerical questions about Slope.  For example, what is the Slope at the point t=0 ?

Make sure to input the definitions of f[t] and slope by selecting the cell bracket with the mouse arrow (and clicking) and then hitting the computer enter key.  Then the Slope function yields

Slope[0]

This is an answer we already know.  The slope at any other point can be computed as well, for example

Slope[0.5]

The slope of a straight line has the same numerical value regardless of which point t you choose on the line.  You should compute the slope of this line at other points t yourself. 

     The slope of a straight line does not depend upon the size of Δt and this is another fact you can easily verify.  For example, with Δt=0.1 you have

Δt=0.1;
Slope[t_]:=((f[t+Δt]-f[t])/(Δt))

and the slope at the point t=0 is

Slope[0]

the same value as before when delta was 10 times larger.  
      Observe the colon and equal sign  :=  form was used in the definition of the Slope function

Slope[t_]:=((f[t+Δt]-f[t])/(Δt))

(instead of just an equal sign) since there is a need to change the size of Δt. If only an equal sign were used in the definition of Slope[t], then changing delta would not change the Mathematica  function Slope[t].  This is very important for dealing with non-straight line functions as will be seen in a moment.

The Slope of a Graph Which Is Not a Straight Line:

An example of a graph which is not a straight line is a parabola function h[t]

h[t]=2 (t^2)

Notice the space between the 2 and (t^2) which tells Mathematica to multiply the two. Employing Mathematica  you obtain

h[t_]:=2 (t^2);
Plot[h[t],{t,-2,2},GridLines->Automatic]

What is the slope of this parabola function h[t] at the point t = 1.0 ?  To answer this question, you pick a second point on the parabola (point 2 in the figure below) a distance Δt=1.0 to the right of the first point.  Next draw a straight line passing through points 1 and 2.  The straight line through point 1 and point 2 is shown below:

and the slope of this straight line is obtained from Mathematica  using

Δt=1.0;
Slope[t_]:=((h[t+Δt]-h[t])/(Δt))

Slope[1.0]

Slope[1.0]

Visually you can see this is the correct by checking the slope of the straight line in the above graph.

Note, what is computed is the slope of the straight line and not the parabola.   But you can imagine what would happen if you consider another point 2 on the parabola at t=1.5 and repeat the above procedure.  Point 2 is now closer to point 1 since now Δt=0.5 (half the size of Δt before) and the graph of this situation appears below

The slope of the new straight line has the numerical value 5 as computed with

Δt=0.5;
Slope[t_]:=((h[t+Δt]-h[t])/(Δt))
Slope[1.0]

The straight line through points 1 and 2 in this case coincides more with the parabola.  The smaller Δt, the more the straight line coincides with the parabola.  Notice the smaller slope = 5 in this case where Δt=0.5 than before where Δt=1.0 and  slope=6.

How Large Should Δt Be in Practice?

What happens to the numerical value of the slope at the point t = 1.0 as Δt is made smaller and smaller?  You should repeat the calculations leading to the table below:

({{Δt, 1.0, 0.5, 0.25, 0.125, 0.06, 0.03, 0.015}, {Slope, 6, 5, 4.5, 4.25, 4.12, 4.06, 4.03}})

Notice as you go the right in the table, each successive delta is half the size of the previous delta.  Visual inspection of this data indicates the value of the slope approaches  4.0  as  Δt  gets smaller and smaller.  A graph of this data is more convincing

data=({{1.0, 6}, {0.5, 5}, {0.25, 4.5}, {0.13, 4.25}, {0.06, 4.13}, {0.03, 4.06}, {0.015, 4.03}});

ListPlot[data,PlotStyle->PointSize[0.02]]

The above is an example of graphing numerical data using the Mathematica function ListPlot.  This function will be discussed in detail in the next module.

Question:  How small should Δt be in practice?  
Answer: :  You should take Δt as small as necessary to get the slope to the  accuracy you require.  DETAILS:  From the data above, you can be reasonably sure the slope is 4.0X where X is uncertain.   The reason you are sure of the "4" is that after dividing Δt in half five times (and more), the "4" in the slope did not change. You can continue making Δt  smaller and smaller until you are reasonably certain the slope is "4.0" to two digits of accuracy and so on to get three digits of accuracy.  It is more difficult to formulate this procedure into a definite rule for the size of Δt but the above example illustrates what is involved.

The Derivative of a Function:

In theory you can take Δ t as small as you wish and in fact all the way to zero.  The theoretical value of the slope when Δ t->0 is called the derivative of the function f[t]

(df/dt) = (Underscript[Limit, Δt->0])((Δf)/(Δt))

Practically there is a limit to the precision of measurements, meaning the limit Δ t->0  is not possible in laboratory experiments.  Also, it is often necessary to know the value of the derivative only to some accuracy.

The Slope Is Not Constant for Most Functions:

The above calculations of the slope were all at the point t = 1.0  for the parabola  function equation (4)  What is the slope at a different point, for example t = 3.0 ?  Start with Δt=1.0

Δt=1.0;
Slope[t_]:=((h[t+Δt]-h[t])/(Δt))
Slope[3.0]

If you make Δt smaller, then the following values for the slope at t=3.0 are obtained

({{Δt, 1.0, 0.05, 0.25, 0.125, 0.06, 0.03, 0.015}, {Slope, 14, 13, 12.5, 12.25, 12.12, 12.06, 12.03}})

The data indicates the slope at t = 3.0 is 12.X where the X is uncertain from the data above. This value of the slope is different than at t = 1.0 where slope = 4.0X   Clearly the numerical value of the slope depends on the point t.  You get a different slope for each different point t on the parabola.

The Derivative of the Sine Function:

The numerical derivative of more complicated functions like Sin[t] can also be easily calculated.  A plot of Sin[t] over the range 0 < t < 2π  appears

Plot[Sin[t], {t, 0 , 2*Pi}]

The numerical derivative of the sine function is easily obtained for Δt=0.1

Δt=0.1;
g[t_]:=Sin[t];
Slope[t_]:=((g[t+Δt]-g[t])/(Δt))

A plot of the numerical derivative of Sin[t] over the range 0 < t < 2π appears using 
 Δt = 0.1

Plot[Slope[t], {t, 0, 2 π}]

This looks like the graph of the cosine function, a result you might have expected provided you have taken a semester or two of calculus!  Here this result was much more easily obtained numerically.

Exercises You Can Do with Mathematica

1. Calculate the numerical derivative of f[t_]:=5 (t^3) with Δt = 0.1  at the point 
t = 1.5 .  Repeat your calculation making delta half the previous value and complete the entries in the data table below:

({{Δt, 0.1, 0.5, 0.025, 0.0125, 0.01125}, {Slope, 36.05, 34.89, \[Placeholder], \[Placeholder], \[Placeholder]}})

Δt=0.1;
g[t_]:=5 (t^3);
Slope[t_]:=((g[t+Δt]-g[t])/(Δt))

Slope[1.5]

Estimate the value of slope when Δ t->0.  How does this compare to the theoretical result

Clear[t];

(∂_t) (5 (t^3))

when t=1.5 ?  How small does Δt need to be to get the slope accurate to two figures?
Notice

15*(1.5^2)

A Note on the Use of Data Tables in This Text:

Data tables like the one above occur frequently in this text.  While not strictly necessary, these tables are helpful in focusing the reader on what calculations are expected in the exercise.  It is suggested that you fill in the data tables in pencil as you complete the exercise.  Often the reader is ask to use the data in construction of a graph.

2.  Plot the slope of f[t_]:=7 (t^( 5)) using Δt= 0.1  over the range 0 < t < 7. Also plot the derivative (df/dt) = 35*(t^4) on the same graph using the Mathematica function Show.  How good is the agreement between the slope and the derivative in this case?

3.  Calculate the slope of f[t_]:=Cos[t] using Δt = 0.05 over the range 0 < t < 2 π .  HINT:  Do not forget to put a space between the 2 and π to indicate multiplication. Compare the slope of f[t] with the derivative (df/dt) = - Sin[t] by graphing together using Show. How good is the agreement between the slope and the derivative in this case?

4. Calculate the slope of the function f[t_]:=3*t+4*(t^6) over the range 0  < t < 5 using Δt = 0.1.  (We used the star to indicate multiplication but a space works just as well.)  Plot the derivative (df/dt)=3+24*(t^5) on the same graph as the Slope using Show.  How good is the agreement between the slope and the derivative in this case?  What value of t gives the greatest difference between the slope and derivative?

Results from Introductory Calculus

Elementary calculus provides the following results:  The derivative of a function which is a power is obtained using Mathematica

(∂_t) (t^n)

The usual mathematical notation for this operation would be

((dt^n)/dt)= n (t^(n-1))

so this is not too different.  
To use the Mathematica derivative function, open the Basic Math Assistant (from Palettes).  Expand "Basic Commands" and click the d∫∑ button.  Click on the derivative button "(∂_var)expr".  
It asks you to put the function you're deriving in the "expr" box and the variable of the function in the "var" box.

The special case where n = 3 yields

(∂_t) (t^3)

You also learn in introductory calculus that

(∂_t) Sin[t]

and

(∂_t) Cos[t]

Here is an example of a derivative acting on a polynomial function

(∂_t) (3+24*(t^5))

© Prentice Hall and Rodney L. Varley (1996, 2001, 2009)