Math 166
 Computer Lab # 2
 Inverse Functions

Goal: To use Mathematica  to help us investigate whether a function has an inverse as well as to find and  graph the inverse.

New Mathematica  commands introduced:  ListPlot (for plotting discrete data)
New Mathematica  syntax introduced:  [[ ]]  (for accessing an element of a list)

Introduction

Recall that a function f has the property that each element in the domain is mapped to one and only one element in the range.  However this definition does not preclude the fact that two different elements of the domain can be mapped to the same element in the range.  For example, f(x)=x2 is a function whose domain is (-É,É) and whose range is [0,É);  however it maps x=2 and x=-2 to 4.  For this particular function we are unable to define a new function which will reverse  the effect of f(x) because we don't know whether to choose àx or -àx.  If we are able to define a function which reverses the effect of a given function f(x) then it is called the inverse of f(x) and we denote it by f-1(x).

f-1(x) is called the inverse of f(x) on [a,b] provided
f(f-1(x) ) =x  and f-1( f(x) )=x.

Determining if a function has an inverse

Graphical approach

We can often determine if a function is invertible by considering its graph.

Example 1.  Plot the functions (i) f(x)=cos x on [0,3º/2] and (ii) g(x)= ln x on (0,5]  and conjecture if each function has an inverse on the given interval.

Note that f(x) has the property that for some y value there are two corresponding x values.   Graphically this can be seen by    drawing a line y=a  and seeing that it crosses the curve f(x) in two places.  Hence we can not define an inverse for f(x) on this interval.   
 
However for the function g(x) for each  y value there is only one x value which corresponds to it; this is seen graphically by drawing any line y=a and noting that it crosses the graph of g(x) in only one place;  hence g(x) has an inverse on this interval.

p1=Plot[{Cos[x],-.5},{x,.0,1.5 Pi} ,PlotStyle->
  { RGBColor[1.000, 0.177, 0.400], 
  RGBColor[1.000, 0.977, 0.062]},
  PlotLabel->"f(x)=cos x",
  DisplayFunction->Identity]
p2=Plot[{Log[x],-1},{x,.01,5} ,PlotStyle->
  { RGBColor[1.000, 0.177, 0.400], 
  RGBColor[1.000, 0.977, 0.062]},
  PlotLabel->"g(x)=ln x",
  DisplayFunction->Identity]
Show[GraphicsArray[ {{p1,p2}} ]]

A function has an inverse if and only if it is one-to-one; i.e., two different x values get mapped to two different y values, that is, if x1Çx2 then f(x1)Çf(x2) for all x1,x2 in the domain.

Exercise 1.  Plot f(x)=x3-3x+2 and conjecture if it is one-to-one on (-É,É).  (After you have attempted this problem you can check your answer by double clicking on the next cell.)

p1=Plot[x^3-3x+2,{x,-1,1},DisplayFunction->Identity]
p2=Plot[x^3-3x+2,{x,-5,5},DisplayFunction->Identity]
p3=Plot[x^3-3x+2,{x,-20,20},DisplayFunction->Identity] 
Show[ GraphicsArray[{p1,p2,p3}],
    DisplayFunction->$DisplayFunction ]

In the following plots we have graphed f(x) for different x ranges.  The function appears to be one-to-one when plotted on [-1,1], but when we plot f(x) for a larger range of x-values then we see that it is no longer one-to-one.  (Note:  For  demonstration purposes we have suppressed the output of the first three Plot commands by using the option DisplayFunction->Identity.  The three plots have then been arranged in an array. )

Monotonicity

Intuitively, we would expect that if a function is strictly monotonic, i.e., it is always increasing or decreasing on an interval then it is one-to-one on that interval.  Recall that from differential calculus we know that if f'(x)>0 for all x in [a,b] then the function is strictly increasing on [a,b]; similarly if f'(x)<0 for all x in [a,b] then f(x) is strictly decreasing on [a,b].

Example 2. Suppose we want to determine if the function f(x)=x/(x^2+1) is monotonic on (-É,É) by investigating its derivative.  Use Mathematica  to calculate its derivative and plot it.  What do you conclude about the monotonicity of f(x).  

We first clear the variables we plan to use;  recall that the command for calculating the derivative is D (one of the few Mathematica  commands that isn't spelled out) or we can simply use the prime command which works better for plotting.  After calculating the derivative we plot f'(x) using the prime command. 

From the graph of the derivative we can see that it takes on both positive and negative values so that the original function is both increasing and decreasing on its domain and thus is not one-to-one; hence it has no inverse.

Clear[f,x]
f[x_]:=x/(x^2+1)
Simplify[ f'[x] ]

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

Exercise 2.  Let g(x)=(2x+1)/(x-1) on (1,É).  Determine g'(x) and decide whether g(x) is strictly increasing, strictly decreasing, or neither on (1,É) and whether it is one-to-one.

Clear[g]
g[x_]:=(2x+1)/(x-1)
Simplify [ g'[x] ]

Plot[g'[x],{x,1.1,4}]

Since g'[x]=-3/(x-1)2 we see that g'[x]<0 for all x.  This is confirmed by the plot.  Hence g[x] is decreasing on (1,É) and thus g[x] is one-to-one.

Finding an expression for the inverse of a function

In the above exercise you should have concluded that g(x) is one-to-one and thus has an inverse.  We now want to find the inverse of g(x) which we denote g-1(x).  To do this, we must solve the equation y=g(x) for x in terms of y and then write g-1(x) (instead of g-1(y) ).  In many instances we can use the Solve command to do this.  Note that one uses == to denote an equal sign in an equation which you are asking Mathematica  to solve.

Clear[g]
g[x_]:=(2x+1)/(x-1)
Solve[g[x]==y,x]

Thus we see that g-1(x)= -(1+x)/(2-x). To check our result we can calculate g(g-1(x)) and g-1(g(x)) to see that in each case we get x.

Clear[ginv]
ginv[x_]:=-(1+x)/(2-x)
Simplify[ g[ginv[x]] ] 
Simplify[ ginv[g[x]] ]

Graphs of Inverse Functions

Example 3.  Let f(x)=x3 on (-É,É).  Since f(x) is increasing on the interval (since f'(x)=3x2) we know that it is one-to-one and thus invertible.     Plot f(x), f-1(x), and y=x on the same graph from say x=0 to x=2.  What do you notice?

In this case f-1(x)=x1/3 and we use the Plot command to draw the graphs.  Note that since we are plotting more than one function we must put the functions in a list; i.e., use { }.  Also we have used the PlotStyle option to get different colors for the graphs.

Plot[{x^3,x^(1/3),x},{x,0,2},PlotStyle->
  {RGBColor[1.000, 0.157, 0.119],
  RGBColor[0.036, 0.045, 1.000],
  RGBColor[0.987, 1.000, 0.096]},
  PlotLabel->"f(x)=x^3    f inverse= x^(1/3)"]

This graph is a little misleading because it is not drawn to scale; that is, the y-axis represents 3 units and the x-axis 2 units but the x-axis is actually drawn longer than the y-axis.  We can adjust this by using the option AspectRatio in the Plot command; set AspectRatio to Automatic.

Plot[{x^3,x^(1/3),x},{x,0,2},PlotStyle->
  {RGBColor[1.000, 0.157, 0.119],
  RGBColor[0.036, 0.045, 1.000],
  RGBColor[0.987, 1.000, 0.096]},
  PlotLabel->"f(x)=x^3   f inverse= x^(1/3)",
  AspectRatio->Automatic]

From this graph we see that the graphs of f(x) and f-1(x) are reflections of one another about the line y=x.

Problems (to be handed in)

1. Let f(x)=3x2+5x-2 for xÑ0.  

a.  Determine if f(x) is strictly monotonic (i.e., strictly increasing or strictly decreasing) on its domain  and use this to  conclude whether or not f(x) is one-to-one on its domain. Plot f(x) and f'(x) on the same graph.

b. If f(x) has an inverse, use the Solve command to find it. Plot f(x), f-1(x), and y=x on the same plot using 0æxæ1.  Use the AspectRatio option as we did in Exercise 3 to demonstrate that f(x) and f-1(x) are reflections of one another about the line y=x.  Label your plot.

2.  The function  f(x)=1/(1+x) is invertible on the domain [0,É). 

a.   Verify that the inverse of y=f(x) is g(x)=(1-x)/x by evaluating f(g(x)) and g(f(x)).  (Hint: you may need to use the Simplify command to get the desired result.)  What is the domain and range of g(x)?

b.  Plot the two functions and the line y=x on the same graph.

We have seen  that inverse functions have reciprocal slopes; that is, if f(x) and g(x) are inverse functions and f'(x) Ç 0 then g'(x)=1/f'(x). 

c.  Verify this fact  numerically for the specific functions given in (a.).  To do this, make a table consisting of an x and y point and the two derivatives (f' and g') evaluated here; add a fifth column which gives the value of 1/f'(x).  Use, for example, x=0 to x=5 in increments of 0.5; use the TableForm command to print out your table with appropriate headings.

3. Sometimes a  function may not be given explicitly  by a formula, but rather described by a set of discrete values.  In this case we can still talk about an inverse of the function, if it exists.

Consider the following table which gives the gravitational force on a rocket of mass 12,000 kg at various points between sea level and 1000 km.
______________________________________________________________
r        0      100     200    300      400     500    600
f(r)  117773  114178  110744  107463  104325  101323  98449 

r      700     800    900   1000
f(r)  95695   93056  90524  88094  
______________________________________________________________

a.  If f(r) represents the force on the given rocket when it is a distance r km from the earth, use the ListPlot command to plot f(r) and determine if you think it is invertible.  Explain your reasoning.  (First, you should use the on-line help to find the arguments of the ListPlot command.  For your convenience we have typed the data from the above table and put it in the arrays rdata and fdata. In addition, we have combined these two arrays into a single array called data which is a list of (r,f(r)) points.  You may simply enter the cell to input the data.   Note that the syntax to pick off the ith entry of a list called fdata is fdata[[i]]; i.e., we use double square brackets.  For example, fdata[[1]]=117773, fdata[[3]]=110744, etc. )

b.  What does the inverse represent physically?

c.  Plot the inverse function, if you think it exists.  Label your plot.

rdata=Table[x,{x,0,1000,100}]
fdata={117773,114178,110744,107463,104325,101323,
  98449,95695,93056,90524,88094} 
data=Table[{rdata[[i]],fdata[[i]]},{i,1,11}]

4.  Clearly the sin function is not one-to-one and hence is not invertible.  However, if we restrict the domain so that it is one-to-one then we can talk about its inverse.  

a.  Plot the function sin x on [-2º,2º]. How would you restrict its domain so that the function is one-to one and the domain is the largest interval possible which includes the origin.  (Recall that Pi is the built-in function for pi in Mathematica.)

The inverse of the sin x is often called arcsin and this is the name of the built-in function for the inverse sin function on a domain about the origin where sin x is one-to-one. (Of course, it is capitalized, i.e., ArcSin .)

b.  Plot sin x and arcsin x along with y=x on a single plot to show that each is the reflection of the other about the line y=x. 

The number of hours, h, of daylight in a particular city in 1995 can be approximated by the formula
     h(t)= 12 + 2.4 sin( 0.0172(t-80) )
where t is the number of days since the beginning of the year.

c.  Is this function invertible on [1,365]?  If not, restrict its domain  so that it is one-to-one; restrict the domain so that it is as large as possible and includes January 1.   What does the inverse represent physically?

d.  Find the day on which h(t) (restricted so that it is invertible) predicts the number of hours of daylight to be 12.