# Introduction to Functions

You’ve made it through algebra: now it is time to start talking about functions. While functions are often used to make upper-level mathematics easier to understand, they can be confusing at first. So – what is a function? How do functions relate to the algebraic equations we have used before? And how do they help us with mathematics and computer science?

## What is a function?

In short, a function:

1. Expresses a relationship between two or more variables.
2. Represents an equation where, for every input, there is only one output.

## What does that mean?

Let’s start with rule #1 - a function is a way of expressing a relationship between two or more variables. For example, if I want to describe a relationship between the variable x and the variable y, I might write y = 2x. You have likely seen equations that look like y = 2x before, and, as you probably know, this equation tells me that for every value of x I choose, the value of y will be double that value. In other words, I know that:

If x = 3, y = 6

If x = 7, y = 14

And so on.

However, while y = 2x is certainly an example of a function, functions are more commonly written in a form that looks like this:

f(x) = 2x

Before we discuss what this new form means and why it is useful, let’s review some key terms.

## Dependent and Independent Variables

Independent variable: the variable that is changed by the experimenter. For example, imagine I am studying the effect of milk consumption on a child’s height. To set up this experiment, I might pick a period of time – say, a year – and, over that period, have one child drink one gallon of milk, another child drink ten gallons, and a third child drink a hundred gallons. At the end of the year, I might measure how many inches taller each child grew. Because I (the experimenter) am choosing how much milk is consumed by each person, the amount of milk (1, 10, or 100 gallons) is the independent variable. Commonly, the independent variable is expressed as x.

Dependent variable: the variable that is measured in the experiment. In an algebraic function, the dependent variable changes when the independent variable changes (in other words, it is “dependent” on the independent variable). In the milk example, the children’s height is measured in the experiment and is the dependent variable. Commonly, the dependent variable is expressed as y.

## Function Notation

Another way to describe the dependent variable is to say that it is a function of x. Because of this, the dependent variable is often expressed as f(x) – which literally represents “function of x”-- rather than as y. This means that y = 2x and f(x) = 2x are different ways of writing the same function.

This form holds true for all types of variables. For example, if I were to choose the letter a instead of x for my independent variable, I would write the dependent variable as f(a), to indicate that it is a function of a.

Additionally, you might see other letters besides f used to represent functions. G(x) and h(x) are both common – though any letter may be used in place of f -- and mean the same thing as f(x). Sometimes, if you are working with several functions at once, you might see both f(x) and g(x) used in the same question to represent two different functions of the same independent variable (here, x).

### Here’s an example of a question you might see:

“Graph both functions on the same axes:

F(x) = 2x

G(x) = 4x”

Before we graph functions, let’s talk a little bit more about that second rule – that a function represents an equation where, for every input, there is only one output. To understand that concept, we’ll have to talk about domain and range.

## Range and Domain

Two important properties of functions are called domain and range. Codomain may also show up when you are working with functions, though you shouldn’t have to worry about codomain until you foray into higher-level math.

Domain: the set of numbers that the independent variable can be (also known as the function’s set of inputs). Take the milk example - say I only have three research subjects: the child who drinks one gallon of milk, the child who drinks ten gallons of milk, and the child who drinks one hundred gallons of milk. Because amount of milk is our independent variable (let’s call it x), the set of inputs for the function will be {1,10,100}, to represent 1, 10, and 100 gallons of milk. There aren’t any subjects drinking 2 gallons of milk, so 2 is not included in the set of inputs. You’ll often see sets of numbers, like the domain, expressed in curly brackets. We often write domain in the form:

Domain(f) = {1,10,100}

Unlike the domain in the example, the domains of functions you’ll see most often in algebra will be made up of more than three distinct numbers. Let’s go back to our function f(x) = 2x. The graph of this function, which we will talk about in more detail later, is below: The graph of f(x) = 2x gives us a straight, diagonal line. From the chart, we see that we could find a point on the line for any value of x, positive or negative. X can be any number. The domain of x, then, can be officially expressed as the set of all real numbers. If you haven’t learned about real vs. imaginary numbers yet, don’t worry about this added word, “real” – for now, it refers to all numbers. This domain can be expressed in the following form:

Domain(f) = {x R}

The symbol R indicates all real numbers. This includes negative numbers, positive numbers, whole numbers, and decimals. There are so many numbers in R that we can’t write them out as a list (like the set {1,10,11}), so we have to use a symbol (R) instead.

The symbol indicates a set, which means that you are referring to a group of numbers (like R), rather than a few distinct numbers (like 1, 10, and 100).

Range: all of the numbers that the dependent variable is (also known as the set of outputs, or all of the values of f(x) we get out when we put in all of the inputs in the domain). For example, in our milk example, let’s say that the child who drank one gallon grew one inch, the child who drank ten gallons grew two inches, and the child who drank a hundred gallons grew three inches. The set of outputs, or range -- expressed in curly brackets because it is a set --- would be {1,2,3}. Since no child grew 4 inches, 4 is not included in the range. Range is often expressed in this format:

Range(f) = {1,2,3}

Similar to domains, the ranges you’ll see in most algebraic functions will be made up of more than three distinct numbers. Let’s go back to our example of f(x) = 2x. If we look back at the graph of this function, we see that we could find a point on the line for every value of y. Y (e.g. the output of the function) can be any number. Therefore, the range of f(x) is also the set of all real numbers, and can be expressed, like the domain:

Range(f) = {x R}

### How do domain and range help us define functions?

As we mentioned earlier, a function is an equation, where, for every input, there is one output. In other words, for every value in the domain, there is one corresponding number in the range. Let’s take our milk example – for every input in the domain ({1,10,100}), there is one output in the range ({1,2,3}). If I, for example, plugged x = 1 into an equation and got two values of y, that equation would not be a function.

## Graphing and Evaluating Functions:

So, how do we visualize functions? Let’s explore what it looks like to plot a function on a graph.

As we noted above, f(x) = 2x and y = 2x represent the same equation. You are likely familiar with graphing equations in the form y = 2x, and, luckily, you can graph functions in the form f(x) = 2x using the same process. We’ll plot our x value on the x-axis, and our f(x) value on the y axis.

Let’s walk through it as we graph our two functions: f(x) = 2x and g(x) = 4x on the same axes.

Both equations describe lines. You’ll recall that we can graph lines by finding two of the line’s points and drawing a straight line that goes through both points. Let’s start by finding two points (values of x and y) that fit into the equation for each function. We’ll do that by choosing a value of x and calculating the value of f(x) or g(x) when we plug our value of x into the function (otherwise known as evaluating the function).

If x = 0:

f(x) = 2x = 0

g(x) = 2x = 0

We know, then, that both lines have a y-value of 0 when they have an x-value of 0. In other words, we know both lines go through the point (0,0).

If x = 1

f(x) = 2x = 2

g(x) = 2x = 4

When x = 1, f(x) will have a value of 2 on the y-axis. f(x), then, passes through the point (1,2).

When x = 1, g(x) will have a value of 4 on the y-axis. g(x), then, passes through the point (1,4).

We are then left with two points for each line:

f(x) = 2x: (0,0), (1,2)

g(x) = 4x: (0,0), (1,4)

If we plot the two points for each function and draw a line through each set, we get the following two lines. To reiterate, plotting f(x) = 2x is just like plotting y = 2x. In two-dimensional equations, the output of the function (f(x)) simply represents the value on the y-axis.

## Applications of Functions in Mathematics and Computer Science

So why is it useful to think about equations like this? Functions play a role in many types of mathematics. They even form the basis of computer science. Here are some ways you’ll continue to see functions as you advance in your math education:

Calculus: Functions are an important part of calculus, which is the study of “continuous change.” That means that calculus is concerned not with points on a graph where x = 1, 2, or 3, but with, for example, all of the points in between x = 0 and x = 1 – the hundredths, thousandths, millionths, and so on. Calculus is concerned with the intervals that are too small to characterize point by point, and that’s where functions can be helpful. They can describe the way a line behaves without needing to reference individual points.

Several variables: Functions are also useful for characterizing relationships between several variables at once. The functions we talked about in this post had one input and one output, and looked like this: However, functions can have more than one input, and, when graphed, can represent structures in 3, 4, 5, or more dimensions. Those functions are called multivariable functions and may look more like this: Computer science: Function logic also guides computer science. Think about commands on a computer. Maybe you want the computer to play a song when you click on the song’s name in Spotify. That’s a function; you have an input (the click) that produces an output (the song playing), just like f(x) = 2x. In f(x) = 2x, as we discussed, our input (x) also produces an output (f(x)).