\chapter{Linear Functions as Models}
\specialsection{Introduction}
In Table~\ref{HybridMarketShare}, we show the percentage of the 
U.S. new car sales made up of hybrid-electric vehicles (such as
the Toyota Prius).\footnote{From Alternative Fuels and Advanced
Vehicle Data Center, U.S. Department of Energy,
{\tt https://www.afdc.energy.gov/data/10301}, accessed June 26, 2017.}   
Hybrids incorporate internal combustion engines and electric engines
powered by storage batteries.  This design
increases fuel efficiency (typically to levels over
40 mpg) and reduces tailpipe emissions.  These vehicles became widely available
in the early 2000's.
\begin{table}[ht]
\renewcommand\arraystretch{1.5}
\caption{Hybrid Vehicle Market Share in the U.S.}
\label{HybridMarketShare}
\noindent\[
\begin{array}{|c|c|c|c|c|c|c|c|}
\hline
{\rm Year} & 2002 & 2003 & 2004 & 2005 & 2006 & 2007 & 2008\\ 
\hline
\% {\rm\ of\ sales}& .24 & .32 & .56 & 1.40 & 1.77 & 2.55 & 2.37\\ 
\hline
{\rm Year} & 2009 & 2010 & 2011 & 2012 & 2013 & 2014 & 2015 \\
\hline
\% {\rm\ of\ sales} & 2.79 & 2.37 & 2.11 & 3.01 & 3.19 & 2.75 & 2.21\\
\hline
\end{array}
\]
\end{table}
Mathematically, we can consider the hybrid vehicle market share as a 
\emph{function} of the years in this range.  This means that for each year shown, the
market share of hybrid vehicles during that year is a well-defined number
depending on the year.   The value 3.19 for the year 2013, for instance, means
that $3.19\%$ of all new vehicle sales in the U.S. were hybrids.

This information can be represented graphically in several ways.  In Figure~\ref{fig:HybridPointPlot},
we show a point plot with the year on the horizontal axis and the market share on the vertical axis.
\begin{figure}
\begin{center}
\includegraphics[width=2.5in,width=2.5in]{HybridPointPlot.png}
\caption{Point Plot of Hybrid Car Market Share Data}
\label{fig:HybridPointPlot}
\end{center}
\end{figure}
Another way information such as this might be presented is as a ``bar chart,'' as in Figure~\ref{fig:HybridBarChart}.
There we include one bar for each year whose height gives the market share in that year.
Both of these plot styles are designed to let us visualize the change in the hybrid
market share over time.  And they both show a rather irregular up-and-down pattern
with peaks in 2009 and 2013, followed by declines.  Evidently, the appeal of hybrid vehicles
is different in years when gasoline prices are trending upward; one of the attractive
features of hybrids is their greater fuel efficiency.  But this also comes at a higher cost
in the sticker price of hybrid vehicles. As a result, people considering purchasing a hybrid often take their expected fuel consumption
into account in making the decision and hybrids tend to be less attractive when fuel prices are low.

Nevertheless, we can see 
what is apparently an upward trend in the hybrid market share over time.  
In this chapter we will focus on modeling situations like this using what are called
\emph{linear} models, where the graph of the corresponding mathematical function
would be a \emph{straight line}.  We will also see a way, called \emph{linear regression},
to estimate the straight line that fits a data set like our hybrid market share data as 
closely as possible.  

\begin{figure}
\begin{center}
\includegraphics[width=2.5in,width=2.5in]{HybridBarChart.png}
\caption{Bar Chart of Hybrid Car Market Share Data}
\label{fig:HybridBarChart}
\end{center}
\end{figure}

\specialsection{Functions}
We will begin by discussing the general mathematical concept of a \emph{function}.  This idea may
be familiar if you have taken a precalculus or calculus course, but we will review the basics and
use that language here as well.  A function
can be thought of as a rule, or a process, or perhaps even a ``black box,'' that assigns to each element
in some set (called the \emph{domain}) a \emph{unique} element of some other set (called the \emph{range}).  
We often think of the domain $D$ as the set of \emph{input values} for the function; the corresponding \emph{output values}
make up the range.  The most important part of this definition is that there is \emph{exactly one
corresponding output for each possible input} -- there is no ambiguity or mulitplicity involved
in the process of going from the input to the output.  

For us, the domain
and range will always be sets of numbers.  Mathematicians often give functions single-letter
names such as $f$ and write $f : D \to R$ to mean that $D$ is the domain of the function and $R$ is
the range.  If $x$ is an element of the domain $D$, then the notation $f(x)$ represents the element
of $R$ that the function produces as output when the input value is $x$. 

\begin{example}
\label{FormulaFunction}
Probably the most common way to specify a function is to give a \emph{formula} for 
producing $f(x)$ from $x$.  For instance the formula
$$f(x) = 17.9 x + 23.7$$
defines a function with domain the set of all real numbers because we can compute $f(x)$ for any real
number by taking $x$, multiplying it by $17.9$, then adding $23.7$ to the result.   For instance
$$f(1.1) = 17.9 \times 1.1 + 23.7 = 43.39.$$
Similarly
$$f(-2) = 17.9 \times (-2) + 23.7 = -12.1.$$
This function is especially simple because we can substitute any real value for $x$ in the formula.
This may not be true for other more complicated function such as the one defined by 
$$g(x) = \frac{1}{x^2 - 16}.$$
Here notice that $g(4)$ and $g(-4)$ are not defined because substituting $x = 4$ or $x = -4$ makes the denominator
in the formula equal to zero; division by zero is not allowed.  In cases like this, the 
usual ``rule of thumb'' is to take the domain to be the set of all real $x$ that can be 
substituted into the formula to yield a well-defined value (unless some other domain is explicitly specified).

For instance, the base-$a$ logarithms that we discussed in Chapter 1 are values of function called
$\log_a$ with domain equal to the set of all strictly positive real numbers.  (The logarithm
of a negative number is not defined in the real numbers.
$\triangle$
\end{example}

Other ways of specifying functions will also be important for us in this course.  

\begin{example}
\label{TableFunction}
The hybrid vehicle market share values in Table~\ref{HybridMarketShare} in the Introduction to this chapter
can be thought of as the definition of function with domain 
$$D = \{2002,2003,\ldots,2015\}$$
and range given by the set of market share values.  The other tables of values we
have considered in previous chapters could be thought of in the same way.  Especially
when a table of values represents the data collected in a scientific experiment or
measurement process, we may want to think of those values as a sort of \emph{incomplete
description} of a function that might be defined for other input values as well.   For example,
the tabulated data in Tables~\ref{ArithLogTable} and \ref{GeomLogTable} from our discussion
of the Weber-Fechner law in Chapter 1 show subsets of the ranges of the $\log_{10}$ function,
but that function is defined for all strictly positive $x$, not just for the input values
given in those tables. $\triangle$
\end{example}

A function could also be defined by giving a graph in the $xy$-plane where each
vertical line $x = c$ meets the graph \emph{at most once}, as in Figure~\ref{fig:Graph}.  If $(c,d)$ is the 
point on the graph with $x = c$, then we would define $f(c) = d$.   For instance, from this plot
we can see $f(0) = 0$ and $f(2) \doteq 2.7$. We say such a graph
``passes the vertical line test.''  Even if we do not have an explicit formula for such
a function, the graph is a complete specification.

\begin{figure}
\begin{center}
\includegraphics[width=2.5in,width=2.5in]{FunctionGraph.png}
\caption{Function Defined by a Graph}
\label{fig:Graph}
\end{center}
\end{figure}

\specialsection{Linear Functions}
In this chapter, we focus on one particular class of functions, the ones known as \emph{linear functions}
and their applications.
There are several ways to say which functions are linear and to understand what makes a function 
linear.  

First, linear functions are exactly the functions whose formulas can be rearranged to the form
\begin{equation}
\label{eq:LinearFunction}
\framebox{$f(x) = m x + b$}
\end{equation}
where $m, b$ are constants.  As you probably recognize, the graph 
$$y = f(x) = m x + b$$
is just a \emph{straight line} and that gives a second characterization of the linear functions 
in terms of their graphs.  The constants $m,b$ have a nice interpretation
in terms of that line.  The constant $m$ is called the \emph{slope} of the line
and it has the following interpretation.  Suppose we start from $x = a$ and the 
corresponding point $(a,f(a)) = (a,m a + b)$ on the graph of the linear function.
If we change the $x$-coordinate to $a + \Delta x$, then the $y$-coordinate
changes to 
$$f(a + \Delta x) = m(a + \Delta x) + b = m a + m\Delta x + b.$$
Hence the corresponding change in the $y$-coordinate is just
$$\Delta y = f(a + \Delta x) - f(a) = m a + m \Delta x + b - (m a + b) = m\Delta x.$$
Assuming $\Delta x \ne 0$, we can divide through to yield
\begin{equation}
\label{eq:Slope}
\frac{\Delta y}{\Delta x} = m.
\end{equation}
Notice that this equation is true for all $a$ and all $\Delta x$.  In other words, according to the 
language introduced in Chapter 2, for all $a$ and all $\Delta x$, the ratios $\frac{\Delta y}{\Delta x}$
are always the same, equal to the slope $m$.  Another way to say this is that $\Delta y$ and
$\Delta x$ are always \emph{proportional}, with ratio equal to $m$.  
This gives an important additional way to understand the property of linearity, which is illustrated
by the diagram in Figure~\ref{fig:LinearSlope}:

\emph{If we take any two points on the graph of a linear function and draw in a small right triangle
with legs parallel to the coordinate axes and hypotenuse along the graph, as in Figure~\ref{fig:LinearSlope},
then ratio of the legs (which is the tangent of the angle between the horizontal leg and the line)
is always the same, and equal to the constant $m$ in the equation of the line as in 
Equation~\ref{eq:LinearFunction}.}

\begin{figure}
\begin{center}
\includegraphics[width=2.5in,width=2.5in]{SlopeMeaning.png}
\caption{Slope of a Line}
\label{fig:LinearSlope}
\end{center}
\end{figure}

There is also an easy interpretation for the constant $b$ in Equation~\ref{eq:LinearFunction}.  The
value $b = f(0) = a\cdot 0 + b$.  So the point $(0,b)$ on the $y$-axis is also on the line defined
by $y = m x + b$.  This point is called the \emph{$y$-axis intercept}.  Hence $b$ is sometimes
also called the \emph{intercept} and Equation~\ref{eq:LinearFunction} is called the 
\emph{slope-intercept form} of the equation of a line.   

\begin{example}
\label{LineExample}
Hence, for instance, the 
line defined by $f(x) = -3 x - 1$ has slope $m = -3$ and $y$-axis intercept $(0,-1)$.
The negative value of the slope means that the line is ``sloping down'' left to right -- 
in other words, the $y$-coordinates of points on the line are decreasing as the 
$x$-coordinates increase.   $\triangle$
\end{example}

An alternative way to specify a linear function is to give the slope $m$ and
one point $(x_0,y_0)$ on the line (i.e. the graph of the function).  If $(x,y)$
is any other point on the line, then using those two points we have
$$\Delta x = x - x_0 \quad {\rm and} \quad \Delta y = y - y_0$$
so from Equation~\ref{eq:Slope}, we obtain
$$\frac{y - y_0}{x - x_0} = m,$$
and hence
\begin{equation}
\label{eq:PointSlope}
\framebox{$y - y_0 = m(x - x_0)$.}
\end{equation}
This is called the \emph{point-slope form} of the equation of the line.  Note that this 
form can be rearranged to give
$$y = m x + (y_0 - mx_0)$$
by distributing the product of $m$ and $x - x_0$ and adding $y_0$ to both sides.
So we have a linear function $f(x) = m x + (y_0 - mx_0)$ as in Equation~\ref{eq:LinearFunction}, where 
$$b = y_0 - m x_0.$$
There is no need to memorize this formula for the intercept; you can always rearrange an equation
given in point-slope form to slope-intercept form as above if you need to find the intercept.  

\begin{example}
\label{PointSlopeEx}
The line with slope $m = 4.2$ containing the point $(1.1,2.8)$ has equation 
$$y - 2.8 = 4.2(x - 1.1) \quad {\rm or}\quad y = 4.2 x - 1.82.$$
\end{example}

It is a basic fact from geometry that there is exactly one line passing through any two
distinct points in the plane.  GIven the two points, $(x_1,y_1)$ and 
$(x_2,y_2)$, if we need to determine
the line, the fastest way is to compute the slope using Equation~\ref{eq:Slope} first, 
and then use Equation~\ref{eq:PointSlope}.  The known point $(x_0,y_0)$
can be either of the two given points; the resulting equation will be the 
same after simplification.

\begin{example}
\label{TwoPointsEx}
Say we have the two points $(x_1,y_1) = (2.2,8.7)$ and $(x_2,y_2) = (4.3,5.0)$.  We ask, what
is the equation of the line through those points?  The slope must be
$$m = \frac{y_2 - y_1}{x_2 - x_1} = \frac{5.0 - 8.7}{4.3 - 2.2} \doteq -1.76.$$
So, using $(2.2,8.7)$ as the known point in Equation~\ref{eq:PointSlope}, the line is (approximately)
$$y - 8.7 = -1.76(x - 2.2) \quad {\rm or} \quad y = -1.76 x + 12.57.$$
Note that computing 
$$(-1.76)(4.3) + 12.57 = 5.002, $$
not exactly $5.0$.  The reason for this is that our slope $\frac{-3.7}{2.1} = -\frac{37}{21}$ is 
a rational number with an infinite repeating decimal expansion.  Therefore the 
rounded value $m \doteq -1.76$ is only approximate. $\triangle$
\end{example}

To conclude this section, we will consider how to tell whether a table of values
comes from a linear function and determine the equation if it does.  This basically
uses all the ideas we have introduced so the idea should be clear if we just
consider the following example.

\begin{example}
\label{LinearTable}
The population of the state of California, measured at 10-year intervals in
the period between 1870 and 1920 is given Table~\ref{CalPop}.\footnote{According to U.S. Census data.}
\begin{table}[ht]
\renewcommand\arraystretch{1.5}
\caption{Population of California 1870 to 1920}
\label{CalPop}
\noindent\[
\begin{array}{|c|c|c|c|c|c|c|}
\hline
{\rm Year} & 1870 & 1880 & 1890 & 1900 & 1910 & 1920\\ 
\hline
 {\rm Population}& 560,247 & 864,694 & 1,213,398 &  1,485,053 & 2,377,549 & 3,426,861\\ 
\hline
\end{array}
\]
\end{table}
We ask whether these are values of some linear function of time in years.  According to 
Equation~\ref{eq:Slope}, that would be true
exactly when the slope between any two of the points was the same.  However, using the 
populations for 1870 and 1880 gives
$$\frac{864,694 - 560,247}{1880-1870} = 30,444.7\ {\rm people/year},$$
while the same computation for the populations in 1880 and 1890 gives
$$\frac{1,213,398 - 864,694}{1890 - 1880} = 34,870.4\ {\rm people/year}.$$
This alone is enough to show that the tabulated values \emph{do not} come from any single
linear function.  

Nevertheless if we make a point plot of these population values as in Figure~\ref{fig:CalPops} then we see some 
interesting things.
\begin{figure}
\begin{center}
\includegraphics[width=2.5in,width=2.5in]{CalPopPlot.png}
\caption{California Population Data}
\label{fig:CalPops}
\end{center}
\end{figure}
First notice that the points here are not actually all that far from lying on a straight line.
We could ask -- Is there a line that ``fits'' the data as well as possible.  Looking more
deeply, we can also see that there was apparently also some sort of ``change point''
in 1900.  The first four points from the census values for 1870, 1880, 1890 and 1900
are actually even closer to lying on one line than the data points as a whole.  The
same is true for the final three points from the census values for 1900, 1910, and 1920.
We might try to ``fit'' two lines separately and compare their slopes to understand
the apparent difference between the first part of the time period and the second part.
We will return to this example later in this chapter. $\triangle$
\end{example}

\specialsection{Mathematical Models}
Much of the mathematical topics we will study this year will be applied to construct
\emph{mathematical models} of various real-world and environmental situations.
The idea of mathematical modeling is shown in the diagram given in 
Figure~\ref{fig:MathModels}.\footnote{Source: {\tt http://mathforteaching.com}.}
\begin{figure}
\begin{center}
\includegraphics[width=3.0in,width=3.0in]{modeling.jpg}
\caption{The Mathematical Modeling Process}
\label{fig:MathModels}
\end{center}
\end{figure}
This sort of mathematical work is (almost) always motivated by the desire to 
understand and/or make predictions about the behavior of some real-world system.\footnote{Some 
mathematicians also study mathematics ``purely'' for its own sake, without
any applications in mind.  One of the surprising things we can see from the history
of the subject is that many mathematical techniques  originally developed  without
any applications in mind have turned out to be useful for applications later on.  A 
famous essay by the physicist Eugene Wigner called \emph{The unreasonable effectiveness
of mathematics in the natural sciences} discusses some of this.}  

The modeling process should ideally start with a deep understanding of the real-world problem, and for this reason
mathematicians doing this sort of work often collaborate with biologists, climate
scientists, and other experts in the applications areas they want to study.  Moving into the 
mathematical world, the underlying real-world problem is often reformulated and abstracted
as a mathematical question.  This often involves making simplifying assumptions or 
ignoring aspects of the real world system that are thought to be irrelevant
(or at least less important) for the problem at hand.  

A mathematical model can be an equation, or a graph, or some other mathematical structure
that captures some of the features of the real-world system under study.  



\specialsection{Linear Regression}

\specialsection{Chapter Project}

\specialsection{Chapter Exercises}
\begin{xcb}{}
\begin{enumerate}
\item Consider the function defined by $f(x) = \sqrt{x - 6}$.  What is the domain of $f$ according to
the ``rule of thumb'' discussed in the text.  

\item Same question as in (1) for $g(x) = \frac{x}{x^2 - 5x + 6}$.

\item Does the equation $x^2 + y^2 = 9$ define $y$ as a function of $x$?   (Hint: What curve in the 
plane is defined by that equation?)  If yes, plot that function.  If not, 
explain why not and say how you could find subsets of the curve defined by this equation
that are graphs of functions of $x$ and give their domains.

\item We discussed an example of a family of circles with areas in an \emph{arithmetic} progression in 
Figure~\ref{fig:ArithCircs}.  Formally an arithmetic progression is any sequence of numbers of the
form 
$$a, a + d, a + 2\cdot d, a + 3\cdot d, \ldots, a + n\cdot d$$
where $a,d$ are fixed numbers.  Show how such an arithmetic progression can be obtained
as the values $f(0), f(1), \ldots, f(n)$ for some linear function.  (What is the formula of that linear function?)

\item Given that the line plotted in Figure~\ref{fig:LinearSlope} passes through the points $(1,5)$ and $(2,7)$,
what is the equation of the corresponding linear function $f = m x + b$? 

\end{enumerate}
\end{xcb}
\endinput
