Function Basics

Think of functions like a vending machine. When you enter in a code, and you get a soda. Same with a function, when you enter in an input number, you get an output number. Try it out!

big red
A1
incakola
A2
yakult
A3
kuat
A4
sprite
A5
big red
B1
incakola
B2
yakult
B3
kuat
B4
sprite
B5
big red
C1
incakola
C2
yakult
C3
kuat
C4
sprite
C5
big red
D1
incakola
D2
yakult
D3
kuat
D4
sprite
D5
Invalid Input
1
1
4
2
9
3
16
4
25
5
1
-1
4
-2
9
-3
16
-4
25
-5
36
6
49
7
64
8
81
9
100
10
36
-6
49
-7
64
-8
81
-9
100
-10
Invalid Input

Notice a couple things:

  1. A function (or vending machine) take in an input and returns an output.
  2. Every input has only ONE output - when you input A1, you only get Big Red, nothing else. And when you input 3, you only get 9, nothing else.
  3. Multiple inputs can have the same output. To get Inca Kola, you can put in A2, B2, or C2. And to get 9, you can input 3 or -3.
  4. Every possible input on our keypad has an output. There are some numbers/codes that aren't on our keypads, like E1 or -15, but that's okay. We define a set of inputs, like our keypad, and we just need to make sure every input is covered.

In non-vending machine language, we write functions as something like

f(input)=output based on inputf(\text{input}) = \text{output based on input}

We represent our input with a variable, like xx, and our output is a calculation that uses our input, or variable. So, something like this:

f(x)=x2+3x+1f(x) = x^2 + 3x + 1

So, when we input 2, all our xx's are replaced with 2, and our output comes out to be 11:

f(x)=x2+3x+1f(2)=22+3(2)+1f(2)=4+6+1f(2)=11\begin{aligned} f(x) &= x^2 + 3x + 1\\ f(2) &= 2^2 + 3(2) + 1\\ f(2)&= 4 + 6 + 1 \\f(2) &= 11\end{aligned}

Just like our vending machines!

Good question! Let's say we have this table of inputs and outputs:

InputOutput
11
24
39
416

And let's say we have two possible functions that could relate our inputs to our outputs:

  1. f(x)=x+2f(x) = x + 2
  2. f(x)=x2f(x) = x^2

The best way to figure out which function works for our table is by plugging in inputs and seeing if the outputs match.

InputOutputInput + 2Input2^2
1131
2444
3959
416616

Since the last column matches our output column exactly, the function that works here is the second function, f(x)=x2f(x) = x^2.

So, when comparing inputs and outputs that you're given with possible functions, just plug the inputs into the function and compare the outputs you get with the ones you were given!