RATES OF CHANGE
Secant and Tangent Lines

<<Graphics`Colors`

Rates of Change

The VELOCITY of an object moving in a straight line is something
we should all be able to calculate, especially when we relate this
to a car traveling on the interstate.

Let d(t) be the distance in miles that a car travels due east in time t (in hours after noon).  If the car starts at 1 p.m. then the distance is 0 at 1 p.m. so that d(1)=0.  If the car has traveled 100 miles by 3 p.m., then d(3)=100.  By 4:00pm the distance is 165 miles.

trip=Plot[0,{x,-.15,5},
			AspectRatio->1/GoldenRatio,
			PlotRange->{-1,200},
			Ticks->{{1,2,3,4},{0,100,165}},
			AxesLabel->{"Time","Distance"},
			DisplayFunction->Identity];
		 
points=Graphics[{Blue,PointSize[.025],Point[{4,165}],
				 Blue,PointSize[.025],Point[{1,0}],
				 Blue,PointSize[.025],Point[{3,100}]}];

taw=Graphics[{Text["d(1)=0 miles",{1,10}],
Text["d(3)=100 miles",{3,90}],
Text["d(4)=165 miles",{4,155}]}];



Show[trip,points,taw,DisplayFunction->
$DisplayFunction];

trip=Plot[0,{x,-.15,5},
			AspectRatio->1,
			PlotRange->{-1,200},
			Ticks->{{1,2,3,4},{0,100,165}},
			AxesLabel->{"Time","Distance"},
			DisplayFunction->Identity];
		 
points=Graphics[{Blue,PointSize[.025],Point[{4,165}],
				 Blue,PointSize[.025],Point[{1,0}],
				 Blue,PointSize[.025],Point[{3,100}]}];

taw=Graphics[{Text["d(1)=0 miles",{1,10}],
Text["d(3)=100 miles",{3,90}],
Text["d(4)=165 miles",{4,155}]}];

route=Graphics[{RGBColor[1,0,0],Line[{{1,0},{3,100}}]}];

Show[trip,points,taw,route, DisplayFunction->
$DisplayFunction];

How would we calculate the car's velocity-or average rate of 
change from 1:00p.m. to 3:00p.m. ?

We need to calculate d(b)-d(a) / b-a .  For this problem we have [(d(3)-d(1)] / (3-1) =
(100-0) / 2 =
100/2 = 50 .
The average velocity or rate of change between these two points is 50 mph.

trip=Plot[0,{x,-.15,5},
			AspectRatio->1,
			PlotRange->{-1,200},
			Ticks->{{1,2,3,4},{0,100,165}},
			AxesLabel->{"Time","Distance"},
			DisplayFunction->Identity];
		 
points=Graphics[{Blue,PointSize[.025],Point[{4,165}],
				 Blue,PointSize[.025],Point[{1,0}],
				 Blue,PointSize[.025],Point[{3,100}]}];

taw=Graphics[{Text["d(1)=0 miles",{1,10}],
Text["d(3)=100 miles",{3,90}],
Text["d(4)=165 miles",{4,155}]}];

route=Graphics[{RGBColor[1,0,0],Line[{{3,100},{4,165}}]}];

Show[trip,points,taw,route, DisplayFunction->
$DisplayFunction];

Similarly, the average rate of change can be calculated between 3:00 and 4:00pm.  We have [d(4)-d(3) ] / (4-3) =
                           (165-100) / 1 = 65mph.

This definition generalizes to the average rate of change for an arbitrary function.

THE AVERAGE RATE OF CHANGE of the functiony=f(x) over the intervalfrom x=a to x=b, with a<b, is [f(b)-f(a)] / (b-a).

Consider the function f(x)=3x-1
a.) What is the average rate of change of f(x) over the interval from x=-1 to x=4? b.)  What about the interval from x=1 to x=2?

Use Mathematica to make the calculation.  Click on the input cell and hit enter.

Clear[f,x]
f[x_]:= 3x-1
(f[4]-f[-1])/(4- -1)
(f[2]-f[1])/(2-1)

Clear[f,x,tgra,pts,tawa,rt]
f[x_]=3x-1
tgra=Plot[f[x],{x,-5,5},
			AspectRatio->1/GoldenRatio,
			Ticks->{{-5,-4,-3,-2,-1,0,1,2,3,4,5},
			{-16,-12,-8,-4,0,4,8,12,16}},
			PlotRange->{-18,18},
			AxesLabel->{"x","y"},
			DisplayFunction->Identity];
		 
pts=Graphics[{Blue,PointSize[.025],Point[{-1,-4}],
				 Blue,PointSize[.025],Point[{4,11}],
    			 Red,PointSize[.025],Point[{1,2}],
                 Red,PointSize[.025],Point[{2,5}]}]; 


rt=Graphics[{Green,Line[{{-1,-4},{4,11}}],SkyBlue,
Line[{{1,2},{2,5}}]}];

Show[tgra,pts,rt, 
     DisplayFunction->$DisplayFunction];

We see both calculations yield an average rate of change of 3, which happens to be the slope of the line.   f(x)=3x+1

Let us consider the function f(x)=x‹  (which is a nonlinear function).
Compute the average rate of change of f(x) over the interval a.) from
x=1 to x=3 and b.) from x=1 to x=1.5

Use Mathematica to make the calculation.  Click on the input cell and hit enter.

Clear[f,x]
f[x_]:=x^3
(f[3]-f[1])/(3-1)
(f[1.5]-f[1])/(1.5-1)

Clear[f,x,tgra,pts,tawa,rt]
f[x_]:=x^3
tgra=Plot[f[x],{x,-4,4},
			AspectRatio->1/GoldenRatio,
			
			PlotRange->{-25,35},
			AxesLabel->{"x","y"},
			DisplayFunction->Identity];
		 
pts=Graphics[{Blue,PointSize[.025],Point[{1,f[1]}],
				 Blue,PointSize[.025],Point[{3,f[3]}],
                 Red,PointSize[.025],Point[{1.5,f[1.5]}]}];


rt=Graphics[{Green,Thickness[.01],Line[{{1,f[1]},{3,f[3]}}],SkyBlue,
Thickness[.01],
Line[{{1,f[1]},{1.5,f[1.5]}}]}];

Show[tgra,pts,rt, 
     DisplayFunction->$DisplayFunction];

We see that the average rate of change is not constant over a 
nonlinear function.   Below is the graphical interpretation.

Instantaneous Rate of Change

What happens if we calculate the average rates of change of the function f(x)=x‹ over the intervals from x=1 to x=1+h for various values of h as h is getting smaller and smaller, that is h is 
approaching zero?  (By doing these calculations, we are zeroing in on the behavior of the curve for a fixed value of x.)

First let us start with x=1 and h=.05 as h is decreasing by .1 on each interval.

Use Mathematica to make the calculation.  Click on the input cell and hit enter.

Clear[f,x,h]
f[x_]:=x^3
x=1;
TableForm[Table[{h,{{"from",x,"to",x+h}},(f[x+h]-f[x])/h},
{h,.5,.01,-.1}],
TableSpacing->{0,10},
TableHeadings->{{},{"h","Interval",
"Average Rate of Change"}}]

Now let's see the results if we let x=1 and h=.1 and let h decrease  by .002 on each interval.

Clear[f,x,h]
f[x_]:=x^3
x=1;
TableForm[Table[{h,{{"from",x,"to",x+h}},(f[x+h]-f[x])/h},
{h,.01,.001,-.002}],
TableSpacing->{0,10},
TableHeadings->{{},{"h","Interval",
"Average Rate of Change"}}]

Use Mathematica to make the calculation.  Click on the input cell and hit enter.

We see that the Average rate of change seems to be approaching 3 as the interval is getting closer and closer to 1 from the right for the function f(x)=x‹.
What happens if we approach 1 from the left?

Clear[f,x,h]
f[x_]:=x^3
x=1;
TableForm[Table[{h,{{"from",x+h,"to",x}},(f[x+h]-f[x])/h},
{h,-.01,-.001,.002}],
TableSpacing->{0,10},
TableHeadings->{{},{"h","Interval",
"Average Rate of Change"}}]

We see that the average rate of change is approaching 3 from the left as well.

This number that the average rates of change is approaching is said to be the INSTANTANEOUS RATE OF CHANGE for the function y=f(x) at a specific value of x.

What does this mean geometrically?

Thus far we have used algebra to define the instantaneous rate of change in terms of the average rate of change.  Let's look at the geometric interpretation.
In general a line that passes through two point on a curve is called a
secant line.

Clear[f,a,h,m,M,g]
f[x_]:=x^2
a:=2
m:=-8
M:=13
l:=-18
L:=18
h:=1
g[x_]:=f[a] + (f[a+h]-f[a])/h(x - a)
func:=Plot[f[x],{x,m,M},PlotStyle->{Thickness[.015]},
PlotRange->{l,L},DisplayFunction->Identity];
secant:=Plot[g[x],{x,m,M},PlotStyle->{{Thickness[.01],
RGBColor[1,0,0]}},PlotRange->{l,L},
DisplayFunction->Identity];
pts:=Graphics[{PointSize[.02],RGBColor[0,1,0],
Point[{a,f[a]}],Point[{a+h,f[a+h]}]}];
sectex=Graphics[{Text["a",{2,-4}],
Text["b",{3,-4}],
Text["f(a)",{2,8}],
Text["f(b)",{3,12}],
Text["f(b)-f(a)",{6,8}],
Text["_________",{6,7.3}],
Text["b-a",{6,5.5}],
Text["=",{8,7.1}],
Text["Change in y",{10.2,8}],
Text["__________",{10.2,7.3}],
Text["Change in x",{10.2,5.5}]}];

slo= Graphics[{Red,Text["SLOPE",{8,2}]}];
Show[func,secant,pts,sectex,slo,Ticks->{{-8,-6,-4,-2,0,2,4,6,8},
{-16,-12,-8,-4,0,4,8,12,16}},

DisplayFunction->$DisplayFunction];

Using the definition of slope we can see that the average rate of change is equal to the slope of the secant line.

What happens if we look at the secant lines through ( x, f[x]  ) and (x+h, f[x+h] ) as h gets smaller and smaller?

Here we see what happens at x=1 as h approaches zero from the right.

Clear[f,a,h,m,M,g]
f[x_]:=x^3
a:=1
m:=-10
M:=10
l:=-10
L:=10
h:=.5
g[x_]:=f[a] + (f[a+h]-f[a])/h(x - a)
func:=Plot[f[x],{x,m,M},PlotStyle->{Thickness[.015]},
PlotRange->{l,L},DisplayFunction->Identity];
secant:=Plot[g[x],{x,m,M},PlotStyle->{{Thickness[.01],
RGBColor[1,0,0]}},PlotRange->{l,L},
DisplayFunction->Identity];
pts:=Graphics[{PointSize[.02],RGBColor[0,1,0],
Point[{a,f[a]}],Point[{a+h,f[a+h]}] }];
slo:=Graphics[{Blue,
               Text[StringForm["SLOPE = ``",(f[a+h]-f[a])/h],
               {-6,5}],
              Red,
               Text[StringForm["h = ``",h],
               {-6,6.5}] }];
Do[Show[func,secant,pts,slo,
DisplayFunction->$DisplayFunction],{h,1,.01,-.05}]

Click on the fishhook arrow above.  Then press command y.
Press the number 2 to slow the animation.

And here we see what happens at x=1 as h approaches zero from the left.

Clear[f,a,h,m,M,g]
f[x_]:=x^3
a:=1
m:=-10
M:=10
l:=-10
L:=10
h:=.5
g[x_]:=f[a] + (f[a+h]-f[a])/h(x - a)
func:=Plot[f[x],{x,m,M},PlotStyle->{Thickness[.015]},
PlotRange->{l,L},DisplayFunction->Identity];
secant:=Plot[g[x],{x,m,M},PlotStyle->{{Thickness[.01],
RGBColor[1,0,0]}},PlotRange->{l,L},
DisplayFunction->Identity];
pts:=Graphics[{PointSize[.02],RGBColor[0,1,0],
Point[{a,f[a]}],Point[{a+h,f[a+h]}]}];
slo:=Graphics[{Blue,
               Text[StringForm["SLOPE = ``",(f[a+h]-f[a])/h],
               {-6,5}],
              Red,
               Text[StringForm["h = ``",h],
               {-6,6.5}] }];
Do[Show[func,secant,pts,slo,
DisplayFunction->$DisplayFunction],{h,-1,-.01,.05}]

Click on the fishhook arrow above.  Then press command y.
Press the number 2 to slow the animation.

We see that the secant lines are approaching the tangent line to the curve at x=a as h is approaching zero.  We can conclude that the instantaneous rate of change is the slope of the tangent line to the curve at a specific value of x.

The tangent line to a curve is the line that best approximates the behavior of the curve at that specific point.

Clear[a,f,g,x]
a:=-5
f[x_]:= (x-3)(x+4)(x+2)(x-1) 
g[x_]:=f'[a](x-a)+f[a]
slo:=Graphics[{Blue,Text["Tangent line",{6.2,50}],
               Red,Text
               [StringForm["y = ``",Simplify[g[x]]]
               ,{6.2,40}]  }];
pic:=Plot[{f[x],g[x]},{x,-6,8},PlotRange->{-50,75},
PlotStyle->{{Thickness[.01]},{RGBColor[1,0,0],Thickness[.0013]}},
AxesLabel->{"x","f[x]"},DisplayFunction->Identity];
Do[Show[pic,slo,DisplayFunction->$DisplayFunction],{a,-4,4,.5}];

Click on the fishhook arrow above.  Then press command y.
Press the number 3 to slow the animation.