Lab One - The Function Zoo

Functions: defining, plotting, and transforming them

Andy Long, MAT229, Spring 2025

My thanks to Aimee Krug, who did most of the hard work -- I just tidied things up, and added a few more examples.

Functions: what are they?

A function 𝑓 consists of a set of inputs, a set of outputs, and a rule for assigning each input to exactly one output. The set of inputs is called the domain of the function. The set of outputs is called the range of the function.

Things that are functions.

Example 1:
	The temperature at a given location and on a given date is a function of the time of day.  For example we might have Temp[7:00] = 63  and Temp[13:30] = 89.
If the precise location of the thermometer and the date is fixed, and we know the time of day, then the temperature is determined.

Example 2:
	The Dow Jones average at closing is a function of a given date.  So we have DOW[ 1/14/25] = 42,518.28.

Example 3: 
	Plotting standard functions
	It’s easy to plot most of your familiar functions (e.g. polynomials, sines and cosines). You just need to know what Mathematica calls them. For example, to plot a sine, you need to know that Mathematica calls it by Sin[x] (notice that Mathematica’s built-in functions start with capital letters, and square brackets are used rather than parentheses). Then you use the “Plot” command (capitals again!), and a domain and range to plot it (notice that the domain is given in braces -- “{ and }” -- rather than parentheses).
	To execute that command, you click inside the cell containing the command and hit “Shift-Enter”:

Plot[Sin[x],{x,-Pi,Pi}]

Creating your own functions
	The log key (log base 10) on a calculator is actually a logarithm of base 10: here we create a function to act as the "log" key , using Mathematica’s Log function -- which offers the choice of any base, including 10:

log[x_]:=Log[10,x]

Notice that functions use square brackets, “[“ and “]”, rather than parentheses. It’s an easy thing to forget! Notice the underscore in “x_” -- it tells Mathematica that you’re constructing a function, rather than trying to evaluate one. And finally notice the “:=” (rather than just an “=” sign). All of these things are essential. Once we have it, however, we can operate just like we did for the builtin function “Sin[x]”.

log[5]
Plot[log[x],{x,1,10}]

Example 4:

	Frequently we collect data, and then model it
	
	1. From within Wolfram Alpha, search  "temperature Highland Heights, KY"
		Look over 1 week and 5 years.   How would we 'model' the temperature as a first step to understanding and predicting weather?
	2. From within Wolfram Alpha search on "unemployment rate US by year"
		Is it a function? How on earth would you model it?:)

Example 5:
	Income tax is figured as 
	10% on the first $8,025, 
	15% on your income between $ 8,025 and  $32,550, 
	25% from $32,550 to  $65,725, 
	28% from $65,725 to $171,550, and so forth.
	
The tax rate, TR(x),  is a function  - one that is fairly complicated.
TR(65,984)=0.28  
and 
TR(4,687.50)=0.15.

For example, a person making $100,000 would be taxed

($ 8,025 minus 0) x .10 : $802.50
(32,550 minus 8,025) x .15 : $3,678.75
(65,725 minus 32,550) x .25 : $8,293.75
(100,000 minus 65,725) x .28 : $9,597.00

8025 * .10 + 
(32550 - 8025) * .15  + 
(65725 - 32550) * .25  + 
(100000 - 65725)* .28

Total : $ 22,372
The amount of tax you pay is a fairly complicated function of the money you make.

Things that are not functions.

Example 1   
	How does y depend on x for the circle of radius 5 centered at the origin:  (x^2)+(y^2)=25?

This is not a function, because knowing x does not tell us y:  For example,  if  x=3, what is y?

Plot[{Sqrt[25-x^2],-Sqrt[25-x^2]},{x,-5,5},AspectRatio->1]

Example 2:  
	Consider the "function" ran which is defined below.  Is it  a function?

ran[x_]:=Random[Real,x];
ran[3]
ran[3]

The Zoo of Functions

Linear functions.

Plotting 2 x + 3

Plot[ 2x + 3,{x,-5,5},PlotStyle->{Red,Dashed}] (* Notice that I'ved added a style command! *)

Plotting m x + b

The “Manipulate” command is remarkably wonderful, allowing us to play around with functions, experiment, etc. In this case, you’ll play with the linear function’s parameters of slope m and intercept b. The slopes will vary between -5 and 5 by steps of 0.1, whereas the intercept can vary between -4 and 4, by steps of 1:

Manipulate[ 
Plot[ m x + b,{x,-5,5},PlotRange->{-10,10},PlotLabel->m x+b],
{m,-5,5,0.1},
{b,-4,4,1}
]

Power functions, with positive integer powers.

Manipulate[Plot[ (x^n),{x,-5,5},PlotRange->{-100,100},PlotLabel->(x^n)],{n,1,10,1}]

Even powers of x :

Manipulate[Plot[ (x^n),{x,-5,5},PlotRange->{-100,100},PlotLabel->(x^n)],{n,2,12,2}]

Odd powers of x :

Manipulate[Plot[ (x^n),{x,-5,5},PlotRange->{-100,100},PlotLabel->(x^n)],{n,3,11,2}]

Root functions.

Even root powers of x :

Manipulate[Plot[ (x^(1/n)),{x,0,10},PlotRange->{0,3},PlotLabel->(x^(1/n))],{n,2,10,2}]

Odd root powers of x :

y=(x^(1/n)), n odd

Notice that for this one we have to be a little clever, creating the function piecewise:

Manipulate[Plot[If[x>0,(x^(1/n)),-(((Abs[x]))^(1/n))],{x,-10,10},PlotRange->{-2,2},PlotLabel->(x^(1/n))],{n,3,11,2}]

Some rational functions.

Even powers of x :

Manipulate[Plot[1/(x^n),{x,-3,3},PlotRange->{-10,10},PlotLabel->1/(x^n)],{n,1,7,2}]

Odd powers of x :

Manipulate[Plot[1/(x^n),{x,-3,3},PlotRange->{-10,10},PlotLabel->1/(x^n)],{n,2,8,2}]

Exponential functions

The simple exponential functions can be written as h(x)=(b^x) where b is a positive number other than 1.

Manipulate[
Plot[b^x,{x,0,2},PlotRange->{0,10},PlotLabel->"Simple Exponential"],
{b,0.1,6}
]

Facts

Used to model growth and decay behavior.

For calculus always write simple or general functions in base e.

Simple exponential functions: (b^x)=(e^(r x)) where r=ln(b).

General exponential functions: ((p(x))^(q(x)))=(e^(k(x))) where k(x)=q(x)ln(p(x)).

Domains:

For simple exponential functions the domain is (-∞,∞).

For general exponential functions  the domain is that of the exponent function k(x)=q(x)ln(p(x)).

The range for simple exponential functions is (0,∞).

End behavior: One end, either x->-∞ or x->∞, goes to zero. The other end, x->∞ or x->-∞, goes to ∞.

To differentiate exponential functions, use the exponential rule (((e^x)))'=(e^x) along with the chain rule.

Integration: ∫ln(x)d x (will get to in coming weeks).

Logarithm functions

Logarithms are the inverse functions to simple exponential functions.
	y=(b^x)⟷x=(Subscript[log, b])(y)

Manipulate[
Plot[Log[b,x],{x,0,2},PlotRange->{-10,10},PlotLabel->"Simple Logs"],
{b,0.1,10}
]

Just as for exponential functions, we prefer to work with base e, so we convert other logs to base e logs, via
	(Subscript[log, b])(y)=(1/(ln(b)))ln(y)

Facts

The domain of (Subscript[log, b])(x) is the range of its inverse (b^x),
	Domain of (Subscript[log, b])(x): (0,∞)

The range of (Subscript[log, b])(x) is the domain of its inverse (b^x),
	Range of (Subscript[log, b])(x): (-∞,∞)

End behavior for natural logarithm ln(x) with domain (0,∞),

(lim_(x->(SuperPlus[0])))ln(x)=-∞

(lim_(x->∞))ln(x)=∞

Differentiation: ((ln(x)))'=(1/x)

Integration: ∫ln(x)d x we will get to in coming weeks.

A final modeling example: 
	Choose parameters a, b, and c so that the plot of f(x)= a (((x-b))^2)+c falls well over the data. What values of a, b, and c did you find?

xs=10*RandomReal[1,15]-3*RandomReal[1];
ys=Pi/3(xs-1.5)^2+E;
dataPlot=ListPlot[Transpose[{xs,ys}]];

Manipulate[
Show[
Plot[ a (x-b)^2 +c,{x,-10,10},PlotRange->{-50,50},PlotLabel->a(x-b)^2+c],dataPlot],
{a,0.1,2,.1},
{b,-2,2,.1},
{c,-50,100,.1}
]