0.4: Functions
- Page ID
- 89701
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)Now that we have reviewed basic ideas about sets we can start doing more interesting things with them — functions.
When we are introduced to functions in mathematics, it is almost always as formulas. We take a number \(x\) and do some things to it to get a new number \(y\text{.}\) For example,
\begin{align*} y = f(x) &= 3x-7 \end{align*}
Here, we take a number \(x\text{,}\) multiply it by 3 and then subtract seven to get the result.
This view of functions — a function is a formula — was how mathematicians defined them up until the 19th century. As basic ideas of sets became better defined, people revised ideas surrounding functions. The more modern definition of a function between two sets is that it is a rule which assigns to each element of the first set a unique element of the second set.
Consider the set of days of the week, and the set containing the alphabet
\begin{align*} A &= \left \{ \text{Sunday, Monday}, \text{Tuesday, Wednesday}, \text{Thursday, Friday}, \text{Saturday}, \text{Sunday}\right \}\\ B &= \left \{ \text{a,b,c,d,e}, \dots,\text{x,y,z}\right \} \end{align*}
We can define a function \(f\) that takes a day (that is, an element of \(A\)) and turns it into the first letter of that day (that is, an element of \(B\)). This is a valid function, though there is no formula. We can draw a picture of the function as
Clearly such pictures will work for small sets, but will get very messy for big ones. When we shift back to talking about functions on real numbers, then we will switch to using graphs of functions on the Cartesian plane.
This example is pretty simple, but this serves to illustrate some important points. If our function gives us a rule for taking elements in \(A\) and turning them into elements from \(B\) then
- the function must be defined for all elements of \(A\) — that is, no matter which element of \(A\) we choose, the function must be able to give us an answer. Every function must have this property.
- on the other hand, we don't have to “hit” every element from \(B\text{.}\) In the above example, we miss almost all the letters in \(B\text{.}\) A function that does reach every element of \(B\) is said to be “surjective” or “onto”.
- a given element of \(B\) may be reached by more than one element of \(A\text{.}\) In the above example, the days “Tuesday” and “Thursday” both map to the letter \(T\) and similarly the letters \(S\) is mapped to by both “Sunday” and “Saturday”. A function which does not do this, that is, every element in \(A\) maps to a different element in \(B\) is called “injective” or “one-to-one” — again we will come back to this later when we discuss inverse function in Section 0.6.
Summarising this more formally, we have
Let \(A, B\) be non-empty sets. A function \(f\) from \(A\) to \(B\text{,}\) is a rule or formula that takes elements of \(A\) as inputs and returns elements of \(B\) as outputs. We write this as
\begin{gather*} f: A \to B \end{gather*}
and if \(f\) takes \(a \in A\) as an input and returns \(b\in B\) then we write this as \(f(a) = b\text{.}\) Every function must satisfy the following two conditions
- The function must be defined on every possible input from the set \(A\text{.}\) That is, no matter which element \(a \in A\) we choose, the function must return an element \(b \in B\) so that \(f(a)=b\text{.}\)
- The function is only allowed to return one result for each input 1. So if we find that \(f(a)=b_1\) and \(f(a)=b_2\) then the only way that \(f\) can be a function is if \(b_1\) is exactly the same as \(b_2\text{.}\)
We must include the input and output sets \(A\) and \(B\) in the definition of the function. This is one of the reasons that we should not think of functions as just formulas. The input and output sets have proper mathematical names, which we give below:
Let \(f:A \to B\) be a function. Then
- the set \(A\) of inputs to our function is the “domain” of \(f\text{,}\)
- the set \(B\) which contains all the results is called the codomain,
- We read “\(f(a) = b\)” as “\(f\) of \(a\) is \(b\)”, but sometimes we might say “\(f\) maps \(a\) to \(b\)” or “\(b\) is the image of \(a\)”.
- The codomain must contain all the possible results of the function, but it might also contain a few other elements. The subset of \(B\) that is exactly the outputs of \(A\) is called the “range” of \(f\text{.}\) We define it more formally by
\begin{align*} \text{range of } f &= \left \{ b \in B \;|\; \text{there is some } a \in A \text{ so that } f(a) = b \right \}\\ &= \left \{ f(a) \in B \;|\; a \in A \right \} \end{align*}
The only elements allowed in that set are those elements of \(B\) that are the images of elements in \(A\text{.}\)
Let us go back to the “days of the week” function example that we worked on above, we can define the domain, codomain and range:
- The domain, \(A\text{,}\) is the set of days of the week.
- The codomain, \(B\text{,}\) is the 26 letters of the alphabet.
- The range is the set \(\left \{ F,M,T,S,W\right \}\) — no other elements of \(B\) are images of inputs from \(A\text{.}\)
A more numerical example — let \(g: \mathbb{R} \to \mathbb{R}\) be defined by the formula \(g(x) = x^2\text{.}\) Then
- the domain and codomain are both the set of all real numbers, but
- the range is the set \([0, \infty)\text{.}\)
Now — let \(h:[0,\infty) \to [0,\infty)\) be defined by the formula \(h(x) = \sqrt{x}\text{.}\) Then
- the domain and codomain are both the set \([0,\infty)\text{,}\) that is all non-negative real numbers, and
- in this case the range is equal to the codomain, namely \([0, \infty)\text{.}\)
Yet another numerical example.
\begin{align*} V:[-1,1] \to \mathbb{R} && \text{defined by } V(t) &= \begin{cases} 0 & \text{if } -1 \leq t \lt 0\\ 120 & \text{if } 0 \leq t \leq 1 \end{cases} \end{align*}
This is an example of a “piece-wise” function — that is, one that is not defined by a single formula, but instead defined piece-by-piece. This function has domain \([-1,1]\) and its range is \(\left \{ 0,120\right \}\text{.}\) We could interpret this function as measuring the voltage across a switch that is flipped on at time \(t=0\text{.}\)
Almost all the functions we look at from here on will be formulas. However it is important to note, that we have to include the domain and codomain when we describe the function. If the domain and codomain are not stated explicitly then we should assume that both are \(\mathbb{R}\text{.}\)