Limits, recursion, induction, tangent and secant lines

Imre Tuba

1.  Limits

1.1.  Regular limits

Mathematica can compute limits of functions using Limit[expr, x->(Subscript[x, 0])], where expris some formula in terms of x.  Here are a few examples.

Limit[1/x^2,  x -> 3]

Limit[1/x^2, x -> a]

Limit[x*Sin[1/x], x -> 0]

Limit[1/x, x -> Infinity]

Limit[(4 x^2 - 3 x + 2)/(2 x^2 - 6 x - 7), 
      x -> Infinity]

Limit[(4 x^2 - 3 x + 2)/(2 x^4 - 6 x^3 - 7), 
      x -> -Infinity]

Limit[Exp[-1/x^2],  x  ->  0]

1.2.  One-sided limits

It is also possible to compute one-sided limits by Limit[expr, x->(Subscript[x, 0]), Direction -> 1] for left limits and Limit[expr, x->(Subscript[x, 0]), Direction -> -1] for right limits.

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

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

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

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

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

Limit[E^(1/x), x -> 0,  Direction -> 1]

Limit[E^(1/x), x -> 0,  Direction -> -1]

1.3.  Limits that do not exist

\(Sometimes\ the\ limit\ does\ not\ exist\ at\ all . \ \ In\ such\ a\ case\),Mathematica will try to give you an interval that the values of the expression are in as x approaches (Subscript[x, 0]).

Limit[Sin[1/x], x -> 0]

Limit[x*Sin[x], x -> Infinity]

Limit[Tan[1/x], x -> 0]

Unfortunately, you can't always trust Mathematica.  For example, it gives wrong results for the following limits.

Limit[1/x,  x -> 0]

Limit[E^(1/x), x -> 0]

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

2.  Recursion

The following is based on exercise 20 on p .  85 in Stewart . 
Let (Subscript[f, 0])(x)=1/(2 - x) and (Subscript[f, n + 1])(x)=(Subscript[f, 0])((Subscript[f, n]) (x)) for n = 0, 1, 2, ... .  Find an expression for (Subscript[f, n])(x) and use mathematical induction to prove it .   Graph (Subscript[f, 0]),(Subscript[f, 1]), (Subscript[f, 2]), (Subscript[f, 3]) on the same screen and describe the effects of repeated composition.

We could certainly define (Subscript[f, 0]), (Subscript[f, 1]), (Subscript[f, 2]), (Subscript[f, 3]) as follows.

f0[x_] = 1/(2 - x)

f1[x_] = f0[f0[x]]

f2[x_] = f0[f1[x]]

f3[x_] = f0[f2[x]]

But this is not very efficient.  Notice that (Subscript[f, 1])=(Subscript[f, 0])∘(Subscript[f, 0]), (Subscript[f, 2])=(Subscript[f, 0])∘(Subscript[f, 0])∘(Subscript[f, 0]), (Subscript[f, 3])= (Subscript[f, 0])∘(Subscript[f, 0])∘(Subscript[f, 0])∘(Subscript[f, 0]).  That is we just keep composing (Subscript[f, 0]) with itself.  Mathematica has a built in function to do this.  Nest[f, expr, n] applies the function f to expr n times.  So we can automate the above process by

f[n_, x_] = Nest[f0,  x,  n + 1]

We get a warning that n+1 cannot be verified to be a non-negative integer at this time.  As long as we only use f with a nonnegative integer as its second argument, we are not going to have a problem though.  There are ways to eliminate the warning.  One of them is to delay the execution of the Nest function until f is invoked.  This way no tests are attempted on the inputs at the time f is defined, only when it's executed, at which time n is presumably a nonnegative integer, and therefore n+1 passes the test.  This is achieved by using := instead of = when defining f.

f[n_, x_] := Nest[f0, x, n + 1]

Then (Subscript[f, 0])(x)=f[0, x], (Subscript[f, 1]) (x)=f[1, x], etc .   We can even list the first few of these using the Table function.  Table[expr, {i, (Subscript[i, min]), (Subscript[i, max])}] generates a list by substituting i into expr as i runs from (Subscript[i, min]) to  (Subscript[i, max])

Table[f[n, x], {n, 1, 5}]

Alternately, we could have used

NestList[f0, x, 5]

which generates a list of f0 applied to x 0, 1, 2, ..., 5 times.
    The above lists show that we defined the function f[n,x] correctly, but does not help us find the pattern.  This is because the expressions are not simplified.  Let's try

Simplify[%]

Now we see the emerging pattern and guess (Subscript[f, n]) (x)=(n+1-nx)/(n+2-(n+1)x).  We will prove that this is correct by showing that our formula satisfies the conditions given in the exercise.  First, let's define

g[n_, x_] = (n + 1 - n*x)/(n + 2 - (n + 1)*x)

Notice that

g[0, x]

is indeed the same as (Subscript[f, 0])(x).  To see that g[n,x] is also satisfies the recursive formula, we compute

g[n + 1, x] - g[0, g[n, x]]

If g[n,x] satisfies the recursive formula given in the exercise, this should be 0.  This is hard to see because the expression is not simplified.

Simplify[%]

show that it is is indeed 0.  So our expression is correct.  We can now plot the functions:

Plot[{f[0, x],  f[1, x],  f[2, x],  f[3, x]},  {x, -3, 3}, 
      PlotStyle -> {Red,  Blue,  Green,  Purple}]

Notice how the vertical asymptotes creep closer and closer to 1.  This is not surprising, as (Subscript[f, 0]) has a vertical asymptote at x = (n + 2)/(n + 1), which indeed approaches 1 as n  ->  ∞.

3. Induction

Look at problem 2 on the exam.  It asks to prove (1/(1·2))+(1/(2·3))+  ...   + 
          (1/((n - 1) n))  =  ((n - 1)/n) for n  ≥  2 using induction.  The base case n = 2 is obvious.  Let's see what Mathematica says about this sum.  We can use the built in function Sum to find its value

Sum[1/(i*(i - 1)),  {i, 2, n}]

This is indeed what we are supposed to prove.  Notice that (1/(1·2))+\(TraditionalForm\`\(\(\(\(\(1\/\(2·3\)\)\(+\)\)\  ... \)\  + 1\/\(n(n + 1)\)\)\(\ \)\(=\)\)\)(1/(1·2))+(1/(2·3))+  ...   + 
          (1/((n - 1) n)) +  (1/(n(n + 1)))  =  ((n - 1)/n) + (1/(n(n + 1))) .  Let Mathematica simplify this expression

Simplify[(n - 1)/n + 1/(n*(n + 1))]

This is (n/(n + 1)), as we were supposed to get by substituting n + 1 for n.  So the statement of the problem is indeed true.

4. Tangent and secant lines

Let's find equations of the tangent and secant lines to a function, say

f[x_] = Sin[x]

First, we construct a function g[x1,x2] to compute the slope of the secant line to f between x1 and x2.

g[x1_, x2_] = (f[x1] - f[x2])/(x1 - x2)

Next, we construct a function h[x] to compute the slope of the tangent line to f at x.  Since Mathematica knows how to find limits, we can let it do this for us.

h[x_] = Limit[g[y, x], y -> x]

Now we construct a function k[x1,x2,x] which will be the equation of the secant line to f between x1 and x2.  Notice that x is just the independent variable in the usual equation of the line y = mx + b.  Think about where this formula comes from.

k[x1_, x2_, x_] = g[x1, x2]*(x - x1) + f[x1]

Similarly, we construct a function m[x0,x] which will be the equation of the tangent line tof at x0.  Again, x is just the independent variable in the usual equation of the line y = mx + b.  Notice that m is very similar to k.

m[x0_, x_] = h[x0]*(x - x0) + f[x0]

We can now plot the original function, the tangent line at 1, and two nearby secant lines in the same graph.  Experiment with different ranges for x.  Which line does the graph of the function resemble as you zoom in around x=1?

Plot[{f[x], m[1, x], k[ .5, 1, x], k[ .8, 1, x]}, {x, 0, 2}, 
      PlotStyle -> {{Brown, Thickness[ .01]}, Red, Blue, 
          Purple}]

Now try zooming in on the kink in |x| at x = 0.  Does it start resembling a line as you look closer?

Plot[Abs[x], {x, -1, 1}]