## 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
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

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(\text{input}) = \text{output based on input}$

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

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

So, when we input 2, all our $x$'s are replaced with 2, and our output comes out to be 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!