2 Limits and the Derivative

2.1 Limits      (on page 49)

Example 2.1.1    (on page 49)

Clear[f];  f[x_] = Sin[x]/x;

Grid[{{ TableForm@Table[{x, f[x]}, {x,-.4,.4,.1}],
TableForm@Table[{x, f[x]}, {x,-.04,.04,.01}],
TableForm@Table[{x, f[x]}, {x,-.004,.004,.001}] }}, Spacings->2]//Quiet

Plot[ f[x], {x, -2*Pi,2*Pi}]

Limit[ f[x], x->0]

Example 2.1.2       (on page 50)

Clear[f]; f[x_] = ((x^3-1)^4)^(1/3)/(x-1)

Grid[ {{ TableForm@Table[{x,f[x]}, {x,.97,1.03,.01}],
TableForm@Table[{x,f[x]}, {x,.997,1.003,.001}],
TableForm@Table[{x,f[x]}, {x,.9997,1.0003,.0001}]  }},Spacings->2 ] //Quiet

Plot[ f[x], {x,.5,1.4}]

Limit[ f[x], x->1]

Example 2.1.3     (on page 52)

Clear[f]; f[x_] = ((2x+Abs[x])/(Abs[x]))Cos[x]

Limit[ f[x], x->0,Direction->1]

Limit[ f[x], x->0,Direction->-1]

Plot[ f[x], {x, -5, 5}]

Limit[ f[x], x->0]

Since the two-sided limit does not exist,  our author is motivated to make the following definition.

theLimit[expr_, xtoa_] := Module[{ rlim=Limit[expr, xtoa,Direction->-1]},
		If[rlim==Limit[expr,xtoa,Direction->1], rlim, "doesn't exist"]]

theLimit[ f[x], x->0]

Infinite Limits and Vertical Asymptotes    (on page 53)

Example 2.1.4   (on page 53)

Clear[f,g]; f[x_] = (1/(x-1));  g[x_] = (1/(((x-1))^2));

{ Limit[ f[x], x->1, Direction->1], Limit[ f[x], x->1, Direction->-1] }

Plot[ f[x], {x,-2,4}]

{ Limit[ g[x], x->1, Direction->1], Limit[ g[x], x->1, Direction->-1] }

Plot[ g[x], {x,-2,4}]

Limits at  ±∝  and Horizontal Asylmptotes (page 54)

Example 2.5.1      (on page 54)

Clear[f,g]; f[x_] := ArcTan[x]

Plot[ f[x], {x, -20, 20}]

{ Limit[ f[x], x->Infinity], Limit[ f[x], x-> -Infinity] }

Example 2.1.6      (on page 54)

Clear[f]; f[x_] = E^(-x/10)*Cos[x^2]

N[ {E, e, E}]

Plot[ f[x], {x, -12,24}]

{ Limit[ f[x], x->-Infinity], Limit[ f[x], x->Infinity] }

Limit[ f[x], x->-Infinity]

Example 2.1.7        (on page 55)

Clear[f]; f[x_] = ((2x^2+5x-1)/(x^2+1))

{ Limit[ f[x], x->-∞], Limit[ f[x], x->∞ ] }

{ Limit[f[x], x->-Infinity], Limit[f[x],x->Infinity] }

Plot[ {f[x], 2}, {x,-20,20}, PlotRange->All]

Limits of Expressions with Symbolic Parameters. (page 55)

Limit[ (((Sqrt[4+h])-(Sqrt[4]))/h), h->0]

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

Limit[ (∑_(k=1)^n)Cos[((k π)/(3 n))] (π/(3 n)), n->∞]

Note that the following limit is the area under the graph of the cosine function over the interval [0, x] when  0 < x ≤ (π/2).

f[x_] = Limit[ (∑_(k=1)^n)Cos[((k x)/n)] (x/n), n->∞]

Sin[Pi/3]

Exercises     (on page 56)

Do Exercises  1, 3, and 4

Exercise 2 on page 56.

In general, we can expect the evaluation of    Lim[ f[x],  x->a ]   to be correct when  f(x)  is expressible as the quotient of two power series about  x = a such that each has a positive radius of convergence about  x = a.  The subject of power series about  x = a  that possess positive radii of convergence belongs in Calculus III and other later courses in mathlematics.   For this reason, one may regard Problem 2 on page 56 with interest when Mathematica  evaluates the two one-sided limits correctly but gives an incorrect answer for the two-sided limit

Limit[  Sqrt[2x^3-x^2-4x+3]/(x-1), x->1 ]     (* BAD - See Below *)

Limit[  Sqrt[2x^3-x^2-4x+3]/(x-1), x->1, Direction->-1]

Limit[  Sqrt[2x^3-x^2-4x+3]/(x-1), x->1, Direction->1]

A brief explanation for Problem 2 on page 56.

Factor[ 2x^3 -x^2-4x+3  ]

For real  x, the function  3 + 2x  is nonnegative only for x ≥ -(3/2).   
Therefore, for real x satisfying  x ≥ - (3/2) and x ≠ 1,  we have  (Sqrt[(((x-1))^2)]) = | x - 1| and 
     ((Sqrt[2(x^3)-(x^2)-4x+3])/(x-1)) =  ((| x - 1|(Sqrt[2x+3]))/(x-1)) = g(x),  
where  g(x) = (Sqrt[2x+3  ]),  for x > 1;  and   g(x) =  - (Sqrt[2x+3]),   for  -(3/2)≤ x < 1.
Thus, the function defined by   f(x) = ((Sqrt[2(x^3)-(x^2)-4x+3])/(x-1)) has a right-hand limit of  (Sqrt[5]) as x→(SuperPlus[1])  
(Direction->-1) and a left-hand limit of  -(Sqrt[5]) as x→(SuperMinus[1])   (Direction->1).  In particular, the two-sided limit does not exist.

Observtion about Exercise 13 (and 14 and 15) on page 56.

The function  f  is defined by

Clear[f]; f[x_] := Which[x<-1, -x-2, -1<=x<=0, -1, 0<x<1, Sin[2*Pi*x], 1<= x, x]

Here, the delayed set  (i.e.,   :=   ) is absolutely necessary.  The value of the function depends on which condition is satisfied and the latter depends on the particular  x  at the time the function is evaluated.  One can define functions with conditions and then extend the definitions.  The precedng function can be defined in this manner  (as we illustrate next).

Clear[g]

g[x_] :=  -x-2  /; x<-1

g[x_] := -1          /; -1<= x <= 0

g[x_] := Sin[2*Pi*x]   /; 0 < x < 1

g[x_] := x             /; 1 <= x

Table[ {x, N[ f[x] ], N[ g[x] ]},  {x, -1.5,1.5, .1 }]//TableForm

However, the limit techniques of Mathematica are not needed for Problems 13, 14, 15 on page 56.

Clear[f]

f[x_] := Which[ x<-1, -x-2, -1≤x≤0, -1, 0<x<1,Sin[2*Pi*x], 1≤x, x]

Plot[f[x],{x,-3,2}]

Limit[ f[x], x->-1, Direction->1]

Another problem for page 56.

Evaluate   (lim_(x->0))((3(e^(2x))-3-6x-6(x^2)-4(x^3))/(x^4)).

Limit[(3E^(2x)-3-6x-6x^2-4x^3)/x^4,x->0]

The Derivative  (page 57)

2.1 Limits

Example 2.2.1a

Clear[f]; f[x_] = x(2-x)

secLine[a_, h_][x_] := f[a] + (f[a+h]-f[a])*(x-a)/h

q[x_] = secLine[.5,.5][x]

Plot[{f[x],q[x]}, {x,0,1.5}]

The Slope of the Tangent Line  (page 58)

Example 2.2.1a  (page 57,  for the preceding function)

Plot[{f[x], secLine[.5,.5][x], secLine[.5,.3][x], secLine[.5,.15][x],secLine[.5,.01][x]}, {x,0,1.5}]

Plot[{f[x], secLine[.5,.01][x]}, {x,0,1.5}]

Example 2.2.2   (page 59)

Clear[f];  f[x_] = Sqrt[x]*(4-x)

mfwd[a_,h_] := (f[a+h] - f[a])/h

mcntrl[a_,h_] := (f[a+h]-f[a-h])/(2*h)

secfwd[x_] = f[1]+mfwd[1,.5]*(x-1)

seccntrl[x_] = f[1]+mcntrl[1,.5]*(x-1)

Generally, it is advisable to use a separate cell for each item of the MATHEMATICA input.  This was not done by our author in the preceding situation.

sec3[x_] = f[.5] + mcntrl[1,.5]*(x-.5)

Plot[{f[x],secfwd[x], seccntrl[x],sec3[x]}, {x,0,2},PlotStyle->{Black, Red,  Blue, Purple}]

Eample 2.2.3  (page 60)

Clear[f];  f[x_] = x^3 - x;

ndf[x_] = (f[x+.01] - f[x-.01])/.02

ndf[1]

Plot[{f[x], ndf[1]*(x-1)}, {x,-1,2}]

Plot[{f[x], ndf[x]}, {x,-1.5,1.5}]

An Animation of the Derivative Graph  (page 61)

nd[fn_,x_] := 500 ((fn /. x->x+0.001) - (fn /. x->x-0.001));
slopeExplorer[fn_,{x_,xmin_,xmax_}, {y_,ymin_,ymax_}] := 
Module[ {f}, f[t_] = fn /.x->t; ndf[t_] = nd[fn, x] /. x->t;
Manipulate[ Show[ Plot[{f[x], f[a] + ndf[a]*(x-a)},
{x,xmin,xmax}, PlotStyle->{{Black}, {Red}}], Plot[ndf[x],
{x,xmin-0.01,a},PlotStyle->{Thickness[0.006], Purple}],
Graphics[{Gray, Line[{{a,f[a]},{a, ndf[a]}}]}],
Graphics[{PointSize[0.02], Blue, Point[{a,ndf[a]}]}],
Graphics[{PointSize[0.02], Blue, Point[{a, ndf[a]}]}],
PlotRange-> {ymin, ymax}], {a,xmin,xmax}]]

slopeExplorer[x^3-x,{x,-1.5,1.5},{y,-2,3}]

By pointing the cursor at the small rectangle (with the two greenish edges) that represent values of a, hold the left mouse button down and move the mouse left to right to move the corresponding rectngle from left to right (thereby showing the slope of the tangent line at x = a for increasing values of a).

slopeExplorer[x^2,{x,-1.5,1.5},{y,-2,3}]

Symbolic Computation of Exact Derivatives

Clear[g]

g[x_] := x*Sin[3x]

Limit[ (g[x+h]-g[x])/h, h->0]

g'[x]

D[g[x],x]

The following was obtained by first clicking on the 6th entry in the BasicMathInput pallette to obtain   (∂_□) □.

(∂_x) g[x]

One could type     Exc pd Esc   to obtain   ∂   and then use the subscript symbol    (Subscript[□, □])   to obtain   (∂_□)  and then insert the   x.

(∂_x) (x^3*Sqrt[x^2+1])

D[x^3*Sqrt[x^2+1], x]

(∂_t) (x*t^3- Exp[k*t])

D[x*t^3- Exp[k*t],t]

(∂_x) {c*u[x], u[x] + v[x], u[x]*v[x], u[x]/v[x], u[x] v[x]}  // TableForm

(∂_x) ( (x*Cos[x] + Sqrt[x^2+1])/( Sin[x^2]*Cos[x]) )

Simplify[ (∂_x) ( (x*Cos[x] + Sqrt[x^2+1])/( Sin[x^2]*Cos[x]) ) ]

(∂_x) ( (x*Cos[x] + Sqrt[x^2+1])/( Sin[x^2]*Cos[x]) )  // Simplify

f[x_] := (x*Cos[x] + Sqrt[x^2+1])/( Sin[x^2]*Cos[x])

f'[x] //Simplify

Clear[f]

Page 64, Exercise 10.

f[x_] := x^2;
Plot[ Evaluate[ Table[ f[a] + f'[a]*(x-a), {a,-2,2,.1}]], {x,-2,2}, PlotRange-> {-4,4}]

2.3   Higher-order Derivatives   (page 65)

?Derivative

Clear[f];  f[x_] = (x^13+x^7+1)*E^x;

Derivative[91][f][x]

The preceding expression is the ninety-first derivative of   ((x^13) + (x^(7 ))+ 1) (e^x) with respect to x.  Its numerical value at x = 1.5 is approximately

Derivative[91][f][1.5]

The computation could also be made as follows.

g[x_] = D[  f[x], {x,91}]

g[1.5]

Or, as follows (using the sixth item in the BasicMathInput palette) with x repeated ninety-one times (separated by commas)..

h[x_] =(∂_(x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x)) f[x]

h[1.5]

Or, as follows.

Clear[f,g,h]

expr = D[ (x^13+x^7+1)*E^x, {x, 91}]

expr  /. x->1.5

For low-order derivatives, the prime notation is convenient. 
As an illustration, consider the following problem of finding the critical points and the points of inflection of the function  f(x) = (x^3)-15(x^2)+71x -104.

f[x_] = x^3-15x^2+71x-104

f'[x]

criticalPoints = NSolve[ f'[x] ==0,x ]

f''[x]

inflectionPoint = NSolve[f''[x]==0, x]

{x, f[x], f'[x], f''[x]} /. criticalPoints

{x,f[x],f'[x],f''[x]} /. inflectionPoint

Plot[f[x], {x,0,8}]

Clear[f,g,h]

Page 65.

g[x_] := x^2*Cos[a*x]

g''[x]

D[g[x],{x,2}]

(∂_(x,x)) g[x]

g'''[x]

D[g[x],{x,4}]

(∂_(x,x,x,x,x)) g[x]

Table[ D[g[x], {x,k}], {k,0,8}] // TableForm

The Second Derivative and Concavity

Clear[f,g,h];  f[x_] = x^4 - 2x^2;
Plot[{f[x], f'[x]}, {x,-2,2}]

Plot[{f[x],f''[x]}, {x,-2,2}]

Exploring the Graph of the Second Derivative

concavityExplorer[ fn_, {x_,xmin_,xmax_}, {y_,ymin_, ymax_}] := 
Module[{f}, f[t_] = fn /.x->t; Manipulate[ Show[ 
Plot[{ f[x], f[a]+f'[a]*(x-a)}, 
{x, xmin, xmax}, PlotStyle->{Black, Red, Green} ], 
Plot[f''[x], {x,xmin-.01,a}, PlotStyle->{Thickness[.006], Blue}],
Graphics[{Gray, Line[{{a, f[a]}, {a,f''[a]}}]}],
Graphics[{PointSize[.02], Red, Point[{a,f[a]}]}],
Graphics[{PointSize[.02], Blue, Point[{a,f''[a]}]}],
PlotRange->{ymin,ymax}], {a, xmin,xmax} ] ]

concavityExplorer[ x^2*Sin[x/2]/10,{x,-2Pi,2Pi}, {y, -2, 2} ]

By pointing the cursor at the small rectangle (with the two greenish edges) that represent values of a, hold the left mouse button down and move the mouse left to right to move the corresponding rectngle from left to right (thereby showing the concavity of the graph at  (a, f(a))  for increasing values of a).

slopeExplorer[ x^2*Sin[x/2]/10, {x,-5,5}, {y, -3,3}]

slopeExplorer[ x/(x^2+1), {x,-5,5}, {y, -3,3}]

concavityExplorer[  x/(x^2+1), {x,-5,5}, {y, -3,3} ]