
\chapter{Functions}


We say that a variable $y$ is a \index{ function} function of another variable $x$, if given
any value of $x$ we have a well defined procedure to compute the value of $y$.
The simplest example of a function is given by the equation $y=2x+3$, which associates the value $2x+3$ to $y$ when any value of $x$ is chosen. Thus, if 
$x=1$, then $y=2(1)+1=3$. We will find it convenient to use names to denote
such rules. Thus we may prefer to say $y=f(x)$, where the function $f(x)=2x+3$.
This notation has the advantage that we can describe the assignment of values 
to $x$ in a concise fashion. Thus the sentence that ``if $x=1$, then $y=2(1)+1=3$ '' can be simply stated as $y=f(1)= 3$.

\smallskip

If we consider a new function $g(x)=1/x$, then we see that $g(0)$ does not make sense and hence we should allow restrictions on the values allowed for the
variable $x$. The set of such allowed values is called the domain of the function. Sometimes, we may want to restrict the values of the variable for
practical reasons which may have little to do with evaluation problems.

For example, if $x$ denotes the length of the side of a square and the function
$y=A(x)$ denotes the area of such a square, then it makes sense to state tha
domain of the function $A(x)$ to be the set of nonnegative real numbers, even
though the formula $A(x)=x^2$ makes perfect sense for negative $x$ also.

This $A(x)$ is an example of a function which is defined by a geometric procedure first, but then we make an algebraic formula. Sometimes we may need several algebraic formulas and sometimes the function may not have any known formula. For instance the daily average temperature at a place is a function of the date, but usually all we expect to know completely is a few values of this 
function! Sometimes, such functions are interpolated by ordinary mathematical
functions for estimation and prediction, but in reality, we are only stipulating the existence of such functions! 

Another example of a function without a formula is the one where the domain is 
a set of people and the function associates the chosen first name to each 
person. Here neither the domain nor the values of the function are real numbers
and we don't expect any formulas. Fortunately, our functions would usually
be about real numbers.

\smallskip

Given a domain $D$ and a function $f(x)$ we say that the set of all possible
values obtained by evaluating the function $f(x)$ is said to be the image or the range of the function $f$. For instance, the range of the area function
$A(x)$ described above is the set of all nonnegative real numbers.

\smallskip

Mathematical functions can be usually described by a graph which consists
of plotting all possible points $(x,f(x)$ as $x$ varies in the domain.
Such graphs will usually look like curves. We now think about which curves
can be graphs of functions. Given a graph and a value $x=t$, to get the
value of $f(t)$, we simply have to draw the vertical line $x=t$ and see where
it hits the graph. 

The condition that the graph comes from a function states that every 
such vertical line (as $x$ varies in the domain) must hit the graph is 
{\bf exactly one} point. This is the so-called ``\index{ vertical line test} vertical line test ''.

\smallskip 
  
Given a value of $x$, a function has to
give you only one value of $y$.  Thus, vertical lines are not graphs
of functions.  For example, the line $x=1$ fails the test in two ways. 
If we take $x=1$, then both $(1,2)$ and $(1,3)$ are on the graph, so 
the vertical line hits in more than one point. (Actually it hits infinitely 
often.) Also, if we take any other value, say $x=2$, then the vertical line does not hit the graph at all! So, we have a failure of the condition, if
our domain contains at least one more point besides $x=1$.

\smallskip

%%%% To update!
%------------------------------
\bigskip

%               DIA Three graphs side by side on p. 6.
\begin{centering}
\begin{psfigure}{\textwidth}{1.25in}{figBA.ps}
\puttext{-160,-53}{Graph of $y=f(x)=x^2$}
\puttext{0,-53}{Graph of $y=f(x)=\sqrt{x}$}
\puttext{160,-53}{Graph of $y=f(x)=1/x$}
\end{psfigure}\\
\end{centering}

%------------------------------

\bigskip
%----------------------------------------------------------------------

We have seen that the \index{ domain of a function} domain of a function is a matter of choice, as 
long we stick to points for which the function can be uniquely evaluated.
Given a mathematical formula, it makes sense to think about a ``\index{ natural domain} natural domain '', that is the largest set of real numbers which can be in the domain
without violating the definition.
 
For example, the square-root function $y=f(x)=\sqrt{x}$ is the rule which
says, given an $x$-value, take the nonnegative number whose square is $x$.
This rule only makes sense if $x$ is positive or zero.  We say that the
{\it natural} domain of this function is $x\ge 0$. 

We often use a more precise notation which is:
$$\mbox{The~domain~of~the~function~}\sqrt{x} \mbox{~is}\{ x|x \ge 0\} $$ 
Alternately, we can use interval
notation, and write that the domain is $[0,\infty)$.  (In interval notation,
square brackets mean that the endpoint is included, and a parenthesis means
that the endpoint is not included.)  The fact that the domain of
$y=\sqrt{x}$ is $[0,\infty)$ means that in the graph of this function (see
above) we have points $(x,y)$ only above $x$-values on the right side of
the $x$-axis.

We may often drop the word ``natural'' and say that it is ``the domain'' of
the given function.

\smallskip

Another basic example of a function whose domain is not the entire
$x$-axis is: $y=f(x)=1/x$, the reciprocal function.  We know that we
cannot substitute
$x=0$ in this formula.  The function makes sense, however, for any nonzero
$x$, so we get that the (natural) domain is: $x\ne 0$.  The graph of this function
does not have any point $(x,y)$ with $x=0$.  As $x$ gets close to 0 from
either side, the graph goes off toward infinity.   We call the vertical
line $x=0$ an {\bf \index{ asymptote} asymptote } of the given graph.

\smallskip

To summarize, usually there are two reasons why certain $x$-values are 
excluded from the domain of a function (i) we cannot divide by zero, 
and (ii) we cannot take the square root of a negative number. A possible
third reason is that the variable $x$ is associated with quantities for
which only certain values are allowed. We have already illustrated this in 
the are function above.

\smallskip


In a story problem, often letters different from $x$ and $y$ are used.
In using a computer it is not uncommon to denote variables by entire words.
For example, the volume $V$ of a sphere is a function of the radius
$r$, given by the formula $V=f(r)=\frac{4}{ 3}\pi r^3$.
Also, letters different from $f$ may be used.  For example, if $y$ is
the velocity of something at time $t$, we write $y=v(t)$ with
the letter $v$ (instead of $f$) standing for the velocity function (and
$t$ playing the role of $x$).
 

In using a computer
system, it might make more sense to write $V=Vol(radius)=\frac{4}{ 3}\pi r^3$.
The computer can  do the calculations in either symbolism with equal ease, but it is easy to recall your own reasoning after many days, of you use the long notations.

\smallskip

The letter playing the role of $x$ is called the
{\bf \index{ independent variable} independent variable }, and the letter playing the role of $y$ is
called the {\bf \index{ dependent variable} dependent variable } (because its value ``depends on'' the
value of the independent variable).  In story problems, when one has to
translate from English into mathematics, a crucial step is to determine
what letters stand for variables.  If only words and no letters are given,
then you have to decide which letters to use.  Some letters are traditional.
For example, almost always, $t$ stands for time.

\medskip
%%%% To update!
% example 1:

\begin{example}
An \index{ open-top box} open-top box is made from an $a\times b$ rectangular piece
of cardboard by cutting out a square of side $x$ from each of the four corners,
and then folding the sides up.  Find a formula for the volume $V$ of the box as
a function of $x$, and find the domain of this function.

\smallskip

Here the box we get will have height $x$, and rectangular base of
dimensions $a-2x$ by $b-2x$.  Thus, 
$$ V=f(x)=x(a-2x)(b-2x).$$

Here $a$ and $b$ are constants, and $V$ is the variable that depends
on $x$, i.e., $V$ is playing the role of $y$. Note that for the problem to make
sense, the constants $a,b$ have to be positive! 

\smallskip

This formula makes mathematical sense for any $x$, but in the story
problem the domain is much less.  In the first place, $x$ must be
positive.  In the second place, it must be less than half the length
of either of the sides of the cardboard.  Thus, the domain is
$$\{ x| 0<x< \frac{a}{2} \mbox{~and~} 0<x<\frac{b}{2}\}$$

In interval notation, we write: the domain is the interval
$(0,\frac{1}{2}\min(a,b))$.

\end{example}

\medskip

We now give more examples of the domain of a purely mathematical function.

\medskip

% example 2:
\begin{example} {(Circle of radius $r$ centered at the origin)} 

The equation for this circle is usually given in the form $x^2+y^2=r^2$.
To write the equation in the form $y=f(x)$ we solve for $y$, obtaining
$y=\pm\sqrt{r^2-x^2}$.  But {\it this is not a function}, because when we
have an $x$ it does not give us a {\it single} value of $y$ but rather {\it
two values} (provided that $x$ is between $r$ and $-r$).  To get a
function, we must choose one of the two signs in front of the square root.
If we choose the positive sign, for example, we get the upper semicircle
$y=f(x)=\sqrt{r^2- x^2}$.  The domain of this function is the interval
$[-r,r]$, i.e., $x$ must be between $-r$ and $r$ (including the endpoints).
If $x$ is outside of that interval, then $r^2-x^2$ is negative, and we
cannot take the square root.  In terms of the graph, this just means that
there are no points on the curve whose $x$-coordinate is greater than $r$
or less than $-r$.

Note that it is equally possible to take the negative square root and then the 
graph is that of the lower semicircle. This is a different function with
domain $[-r,r]$.
%------------------------------
%DIA Graph of upper unit semicircle on p. 7.

\begin{centering}
\begin{psfigure}{\textwidth}{2.0in}{figBB.ps}
\puttext{60,25}{$y = \sqrt{1-x^2}$}
\end{psfigure}\\
\end{centering}

%------------------------------
\end{example}

\medskip

% example 3:
\begin{example}
Find the domain of 
$$ y=f(x)=\frac{1}{\sqrt{4x-x^2}}.$$
\smallskip

To answer this question, we must rule out the $x$-values that make
$4x-x^2$ negative (because we cannot take the square root of a negative)
and also the $x$-values that make $4x-x^2$ zero (because if $4x-x^2=0$, then
when we take the square root we get 0, and we cannot divide by 0).
In other words, the domain consists of all $x$ for which $4x-x^2$ is
strictly positive.  We give three different methods to find out when  $
4x-x^2>0$.

\smallskip

{\it First method.} Factor $4x-x^2$ as $x(4-x)$.  The product of two numbers
is positive when either both are positive or both are negative, i.e., if
either $x>0$ and $4-x>0$, or else $x<0$ and $4-x<0$.  The latter alternative
is impossible, since if $x$ is negative, then $4-x$ is greater than 4, and
so cannot be negative.  As for the first alternative, the condition $4-x>0$
can be rewritten (adding $x$ to both sides) as $4>x$, so we need:
$x>0$ and $4>x$ (this is sometimes combined in the form $4>x>0$, or,
equivalently, $0<x<4$).  In interval notation, this says that the domain
is the interval $(0,4)$.

\smallskip

{\it Second method.}  Write $4x-x^2$ as $-(x^2-4x)$, and then complete
the square, obtaining $-\Bigl((x-2)^2-4\Bigr)=4-(x-2)^2$.  For this
to be positive we need $(x-2)^2<4$, which means that $x-2$ must be less
than 2 and greater than $-2$:  $-2<x-2<2$.  Adding 2 to everything gives
$0<x<4$.  

{\it Third method.} Again factor $4x-x^2$ as $x(4-x)$.  Thus the
product is zero when $x=0$ or $x=4$. Mark these two points on 
a usual number line. This yields three pieces of the number line 
which, in interval notation, are:

$$I_1=(-\infty, 0) ~,~ I_2=(0,4)~,~ I_3=(4,\infty)$$

Our function $4x-x^2$ must keep a constant sign on each of these 
intervals. We can test the signs easily by testing any convenient point
in each interval. For example, in $I_1$, try $x=-1$ and consider
$x(4-x)=(-1)(4-(-1))=-5<0$. In $I_2$, try $x=1$ to get $1(4-1)=3>0$
and in $I_3$, try $x=5$ to get $5(4-5)=-5<0$. So the needed
interval is $I_2$. Since we need to avoid the zeros of our function, 
the answer is $I_2=(0,4)$. In general, you will have to investigate
the endpoints separately.

\end{example}

\bigskip

A function does not always have to be given by a single formula.
For example, suppose that $y=v(t)$ is the velocity function for a car
which starts out from rest (zero velocity) at time $t=0$; then
increases its speed steadily to 20 m/sec, taking 10 seconds to do this;
then travels at constant speed 20 m/sec for 15 seconds; and finally
applies the brakes to decrease speed steadily to 0, taking 5 seconds to
do this.  The formula for $y=v(t)$ is different in each of the three
time intervals.  The graph of this function is shown below, along with
the three formulas:
%---------------------------------
%DIA Diagram on p. 8 situated to the right of the formula below.
\bigskip
\medskip

\begin{centering}

\begin{rightindent}{0.6\textwidth}
$y=v(t)=\begin{cases}2t, &\text{if $0\le t \le 10$;}\\ 
                     20,&\text{if $10\le t\le 25$;}\\
                  120-4t,&\text{if $25\le t\le 30$}.\end{cases}
$
\vspace{0.2in}

\
\end{rightindent}
\hfill
\begin{psfigure}{0.3\textwidth}{1.5in}{figBD.ps}
%\puttext{190,-25}{$t$}
\puttext{0,45}{$y = v(t)$}
\end{psfigure}\\
\end{centering}

\medskip

%-------------------------------

Not all functions are given by formulas.  A function
can be given by an experimentally determined table of values.
For example, the population $y$ of the U.S. is a function
of the time $t$: we can write $y=f(t)$.  This is a perfectly good
function --- you could graph it if you had data for various $t$ --- but
you couldn't find an algebraic formula for it.

Another inportant point is that this is a fuzzy function! Its mathematical
form, once written down, gives a good function, but whether it is ``really equal'' 
to the actual function being discussed is always in doubt and subject
to disputes and opinions. Even though the function may exist and be well defined, 
it is impossible for anyone to claim to know it completely 
or to be able to prove the claim! 

This raises an interesting philosophical question. Does a function exist if its
description seems to make sense, but nobody can ever determine all its function
values - or even a formula for it! The uncertainty principle of Physics makes this
problem even more intriguing, since it states that it is impossible to precisely 
determine both the time and the position of a moving particle. In Mathematics, we
don't have to worry about such uncertainties!


\medskip

\section{\index{ Shifts and Expansions} Shifts and Expansions }

Many functions in applications are built up from simple functions by
inserting constants in various places.  It is important to understand
the effect such constants have on the appearance of the graph.

\smallskip

\noindent
{\bf \index{ Horizontal shifts} Horizontal shifts.} {\it If you replace $x$ by $x-C$ everywhere it
occurs in the formula for $f(x)$, then the graph shifts over $C$ to the
right.} (If $C$ is negative, then this means that the graph shifts over
$|C|$ to the left.)  For example, the graph of $y=(x-2)^2$ is the parabola
$y=x^2$ shifted over to have its vertex at the point 2 on the
$x$-axis.  The graph of $y=(x+1)^2$ is the same parabola shifted over to
the left so as to have its vertex at $-1$ on the $x$-axis.

If you have to do such sketches by hand, often the trick is to draw the
original parabola $y=x^2$ and then just shift the $y$-axis to the desired new
location. Think why you must shift the $y$-axis for an apparent shift in $x$ values.
Also, you should remember that to shift a curve to the left is the same as shifting
the $y$-axis to the right by the same amount.

\smallskip


\noindent
{\bf \index{ Vertical shifts} Vertical shifts.} {\it If you replace $y$ by $y-D$, then the graph
moves up $D$ units.}  (If $D$ is negative, then this means that the graph
moves down $|D|$ units.)  If the formula is written in the form
$y=f(x)$ and if $y$ is replaced by $y-D$ to get $y-D=f(x)$, we can
equivalently move $D$ to the other side of the equation and write
$y=f(x)+D$.  Thus, this principal can be stated: {\it to get the
graph of $y=f(x)+D$, take the graph of $y=f(x)$ and move it $D$ units up.}
For example, the function $y=x^2-4x=(x-2)^2-4$ can be obtained from
$y=(x-2)^2$ (see the last paragraph) by moving the graph 4 units down.
The result is the $x^2$-parabola shifted 2 units to the right and 4 units
down so as to have its vertex at the point $(2,-4)$.

Just as explained above, this can also be accomplished by shifting the $x$-axis
accordingly. It is of course, much easier to redraw the axes in a different location
than to redraw the whole curves.

\smallskip

{\bf Warning.}  Do not confuse $f(x)+D$ and $f(x+D)$.  For example,
if $f(x)$ is the function $x^2$, then $f(x)+2$ is the function $x^2+2$,
while $f(x+2)$ is the function $(x+2)^2=x^2+4x+4$. To sketch $f(x)+2$,
the graph of $f(x)$ has to be pushed up by $2$ units; but to sketch
the graph of $f(x+2)$, the same graph has to be pushed to the left by
two units. 

\smallskip

\begin{example}{(Circles)}  
An important example of the above two principles is the circle
$x^2+y^2=r^2$.  This is the circle of radius $r$ centered at the origin.
(As we saw, this is not a single function $y=f(x)$, but rather two
functions $y=\pm\sqrt{r^2-x^2}$ put together; in any case, the two shifting
principles apply to equations like this one which are not in the function
form $y=f(x)$.)  If we replace $x$ by $x-C$ and replace $y$ by $y-D$ ---
getting the equation $(x-C)^2+(y-D)^2=r^2$ --- the effect on the circle is
to move it $C$ to the right and $D$ up, thereby obtaining the circle of
radius $r$ centered at the point $(C,D)$.  This tells us how to write the
equation of any circle, not necessarily centered at the origin.
\end{example}
\smallskip

We will later want to use two more principles concerning the effects of
constants on the appearance of the graph of a function.

\smallskip

\noindent
{\bf \index{ Horizontal expansion.}  
 Horizontal expansion.}  
{\it If $A$ is positive and $x$ is replaced by $x/A$ in a formula,
then the effect on the graph is to expand it by a factor of $A$ in the
$x$-direction (away from the $y$-axis).} This wording supposes that $A>1$.
If $A$ is between 0 and 1, then ``expand by a factor of $A$'' means
``contract by a factor of $1/A$.''  For example, replacing $x$ by
$x/0.5~=~2x$ has the effect of contracting toward the $y$-axis by a factor
of 2.  

If $A$ is negative, then we expand by a factor of $|A|$ and then
flip about the $y$-axis.  Thus, replacing $x$ by $-x$ has the effect of
taking the mirror image of the graph with respect to the $y$-axis.  For
example, the function $y=\sqrt{-x}$, which has domain $x\le 0$, is obtained
by taking the graph of $\sqrt{x}$ and flipping it around the $y$-axis into
the second quadrant.

\smallskip

\noindent
{\bf \index{ Vertical expansion} Vertical expansion.} 
{\it If $B$ is positive and $y$ is replaced by $y/B$ in a formula, 
then the effect on the graph
is to expand it by a factor of $B$ in the vertical direction, away from the
$x$-axis.}
Note that if we have a function $y=f(x)$, replacing $y$ by $y/B$
is equivalent to multiplying the function on the right by $B$: $y=Bf(x)$.
The effect on the graph is to expand the picture away from the $x$-axis by
a factor of $B$ if $B>1$, to contract it toward the $x$-axis by a factor of
$1/B$ if $0<B<1$. If $B<0$, then as before the operation is to expand by $|B|$ 
and then flip about the $x$-axis.

\smallskip

As above, we can avoid redrawing the graph in the case of vertical or horizontal
expansions. We simply choose an appropriate new scale on the axes, keeping our
original curve in tact. While this may be convenient, it may not be the best
visual illustration. As we will illustrate below, we can declare a circle to be an 
ellipse or an ellipse to be a circle by a simple change of scales on the axes. Thus,
if we want comparable scales on the two axes, then this trick is not available.
See the illustrations below.
%%%% To update! Add pictures and illustrations of shifts.

\smallskip

\begin{example} {( Ellipses)}
A basic example of the two expansion principles is given by an {\bf \index{ ellipse} ellipse 
of \index{ semimajor axis} semimajor axis $a$ and \index{ semiminor axis} semiminor axis $b$}.  We get such an ellipse by
starting with the unit circle --- the circle of radius 1 centered at the
origin, the equation of which is $x^2+y^2=1$ --- and stretching it by a factor
of $a$ horizontally and by a factor of $b$ vertically.  To get the equation
of the resulting
ellipse, which crosses the $x$-axis at $\pm a$ and crosses the $y$-axis
at $\pm b$, we replace $x$ by $x/a$ and $y$ by $y/b$ in the equation
for the unit circle.  This gives 
\[
\frac{x^2}{ a^2}+\frac{y^2}{ b^2}=1.
\]

\smallskip

Finally, if you want to analyze a function that involves {\em both} shifts
and expansions, it is usually necessary to deal with the expansions first,
and then the shifts.  For instance, if you want to expand a function by a factor
of $A$ in the $x$-direction and then shift $C$ to the right, you do this
by replacing $x$ first by $x/A$ and then by $(x-C)/A$ in the formula.  As an
example, suppose that, after expanding our unit circle by $a$ in the
$x$-direction and by $b$ in the $y$-direction to get the ellipse in the
last paragraph, we then wanted to shift it a distance $h$ to the right and
a distance $k$ upward, so as to be centered at the point $(h,k)$.  The new
ellipse would have equation 
\[
\frac{(x-h)^2}{ a^2}+\frac{(y-k)^2}{ b^2}=1.
\]

A concrete example might be the function $y=(x-2)^2/4+1$. Naturally, you want
to start with the model parabola $y=x^2$. Then you should first do the vertical
expansion $y=x^2/4$, either by just renaming the scale or preferably by sketching
the curve again in the new formula. The resulting curve can then be shifted 
horizontally and vertically as needed. (See illustrations below.) You should 
experiment with changing the order of these operations and see what trouble you get 
into.

\end{example}


