One input, one output
A function is a rule that takes an input and gives back exactly one output. Lesson 0.2.1 wrote this as : the output of the rule at the input .
A table of values is the simplest way to see one. Here is :
| 0 | 1 | 2 | 3 | ||
|---|---|---|---|---|---|
| 3 | 0 | 0 | 3 |
Two inputs may share an output: . What a function may not do is give two outputs for one input. "The number whose square is " is not a function, because for it could be 2 or .
Rule: Function
A function assigns to every allowed input exactly one output. Read the arrow as "goes to".
The output carries its own units, set by the rule. A car at a steady 60 km per hour has gone km after hours. The input is a time in hours and the output a distance in km, so km.
A function can be given by a formula, a table, a graph or a piece of code. All four answer the same question: which output goes with each input?
Try it
A Python function built from +, -, * and ** works on one number or on a whole NumPy array. One call on an array gives the whole table.
The two printed lines match the table above.
The domain: which inputs are allowed
The domain is the set of inputs the function accepts. Unless told otherwise, it is every real number for which the formula makes sense.
Two things break a formula in this module: dividing by zero, and taking the square root of a negative number. Logarithms add a third in module 1.4.
Take . A table shows where it starts working:
| 2 | 3 | 4 | 7 | 12 | |
|---|---|---|---|---|---|
| none | 0 | 1 | 2 | 3 |
At the inside is , which has no square root. Algebra finds the edge exactly: the inside must be at least 0, so , which gives (lesson 0.3.3).
The domain is the interval . The square bracket keeps 3 itself, because is fine.
Now take . The bottom is zero at , so the domain is every real number except 2. In set-builder notation (lesson 0.2.1) that is .
Close to 2 the outputs grow very large, positive on one side and negative on the other: , and .
Three more cases complete the picture.
- Both rules at once. In the root needs and the bottom needs . Together, : the domain is , with 3 left out.
- Nothing to break. has no fraction and no root, so its domain is all of .
- Limits from the situation. A square of side cm has area cm². The formula accepts , but a side cannot be negative, so the domain is .
Rule: Finding the domain
Find every bottom of a fraction and every square root, and remove the inputs where one fails. A root inside a bottom must be strictly positive. Then remove anything the situation rules out.
Try it
Python refuses inputs outside the domain. Each try block catches the error so the cell keeps going.
NumPy is more forgiving. It returns nan ("not a number") for a bad square root and inf (infinity) for a division by zero. The errstate line hides the warnings it would print.
The last line is at 3, 4 and 7: the edge 3 gives inf.
The range: which outputs come out
The range is the set of outputs the function produces as the input runs over the whole domain. On a graph, the domain is the graph's shadow on the -axis and the range is its shadow on the -axis.
Domain and range as shadows of the graph. starts at , so its domain begins at 3 and its range at 0. accepts every , and its lowest point sets the bottom of its range.
A graph suggests the range; algebra confirms it. A number is in the range when the equation has a solution in the domain. Rearrange it for , as in lesson 0.3.2.
- . Squaring both sides gives : the output 5, for example, comes from . A square root is never negative, so this works for every and no other. The range is .
- . Multiply by and divide by : . That works for every except 0, so the range is every real number except 0. The graph never touches the -axis.
- . Multiplying out gives , so . A square is never below 0, so the output is never below , and it is at . The range is ; lesson 1.2.2 turns this trick into a method.
A constant function such as has the smallest possible range: the single number 5.
Rule: Finding the range
Solve for . The outputs for which a solution exists, inside the domain, make up the range.
Lesson 0.2.1 wrote , read " takes inputs from to outputs in ". The set is the domain.
The set only promises where outputs land; the range is the part of actually reached. For with , outputs land in , but the range is only .
Try it
The first lines check the solving: feed in and gives back ; feed in and gives back .
Sampling many inputs estimates a range. On , the lowest value of is , at . The highest, 15, is only the highest on this interval: the outputs keep growing beyond it.
Graphs
The graph of is every point drawn on a grid. Two places on it have names.
- Where the graph meets the -axis, . Those inputs are the zeros (or roots) of : for , 0 and 2. A function can have no zeros: has range , so it never reaches 0.
- Where the graph meets the -axis is the point , and is the -intercept. It exists only when 0 is in the domain, so has none.
A graph also shows at a glance whether a curve is a function at all. Two points straight above each other would mean two outputs for one input.
The vertical line test. The parabola meets every vertical line once. The curve pairs the input 4 with both 2 and , so it fails.
Rule: Vertical line test
A curve is the graph of a function exactly when no vertical line crosses it twice. "At most" allows none: a vertical line outside the domain misses the graph.
Try it
A function written with NumPy operations works on a whole array at once, so one call gives every point to plot.
The dashed curve is a circle. A vertical line through its middle meets it twice, so it is not the graph of a function of . Change the formula in f and run the cell again to see another graph.
These ideas carry the rest of the module. Lesson 1.1.2 moves and reshapes graphs, lesson 1.1.3 runs functions backwards, and case study 1.1.5 draws option payoffs as graphs.
Common mistakes
- Mixing up domain and range. The domain is about inputs; the range is about outputs.
- Getting the edge wrong. accepts 3, but does not: a root in a bottom must be strictly positive.
- Forgetting the situation. A length or a time cannot be negative, even if the formula accepts it.
- Trusting a sample as the whole range. Evaluating at many points shows the outputs on that interval only. Solve to be sure.
- Reading off a -intercept that is not there. exists only when 0 is in the domain.
- Using
mathon arrays.math.sqrttakes one number. For a NumPy array usenp.sqrt. - Accepting two outputs for one input. If a vertical line meets a curve twice, the curve is not a function of .
Functions, domain and range
0 of 13 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- A function gives exactly one output for each input; its output has the units the rule produces. On a graph, every vertical line meets it at most once.
- Domain: the inputs allowed. Remove inputs that divide by zero or take the square root of a negative number, and any the situation rules out.
- Range: the outputs produced. is in the range when has a solution in the domain. On a graph, the range is the shadow on the -axis.
- In , is the domain; the range is the part of actually reached.
- Zeros are the inputs where ; the -intercept is , when 0 is in the domain.
- Write functions with NumPy operations (
np.sqrt, notmath.sqrt) and they work on whole arrays.