Section 9.3 Defining Functions and Using Function Notation
Instead of defining an expression, it is sometimes more useful to define a function. A function specifies the variables that are included in the expression. This allows us to substitute values into our functions easily using function notation, such as \(f(5)\text{.}\)
Aside
> f(x) := sin(x) - exp(x);
\begin{equation*}
\displaystyle f\, := \,x\mapsto \sin \left( x \right) -{{ e}^{x}}
\end{equation*}
Make sure that the variable in the function name matches the variable in the function, since we often use functions of \(t\) or other variables besides \(x\text{.}\)
> g(t) := -4.9*t^2 + 5*t + 20;
\begin{equation*}
\displaystyle g\, := \,t\mapsto - 4.9\,{t}^{2}+5\,t+20
\end{equation*}
A functionโs name does not have to be a single letter. In fact, it is often a good idea to have a functionโs name correspond to what the function represents.
> area(r) := Pi*r^2;
\begin{equation*}
\displaystyle area\, := \,r\mapsto \pi\,{r}^{2}
\end{equation*}
Aside
Once we have defined a function, we can use function notation much like we would in class. For example, now that \(f(x)\) is defined, rather than using the
subs() command to substitute \(x=0\) into the function, we can now simply type \(f(0)\text{.}\)
> f(0);
\begin{equation*}
\displaystyle -1
\end{equation*}
It is easy to substitute an expression into a function using function notation.
> h(x) := 2*x^2 - 3*x;
\begin{equation*}
\displaystyle h\, := \,x\mapsto 2\,{x}^{2}-3\,x
\end{equation*}
> h(x+1);
\begin{equation*}
\displaystyle 2\, \left( x+1 \right) ^{2}-3\,x-3
\end{equation*}
