If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

What is a function?

Functions assign a single output for each of their inputs. In this video, we see examples of various kinds of functions. Created by Sal Khan.

Want to join the conversation?

  • spunky sam blue style avatar for user faz919
    So, one day, I asked my dad if a function could be graphed as a circle. He said yes. But I said no because I thought there would be more than one output of the input. For example, see this program I made:
    https://www.khanacademy.org/cs/a-function/1860626452
    My dad said yes because he said you could find the absolute value of both sides, but I didn't think of it that way. Can someone tell me: who is correct?
    (155 votes)
    Default Khan Academy avatar avatar for user
    • hopper cool style avatar for user Chuck Towle
      Ωπ fαz919 πΩ ,

      By definition of a function, a circle cannot be a solution to a function.
      A function, by definition, can only have one output value for any input value. So this is one of the few times your Dad may be incorrect. A circle can be defined by an equation, but the equation is not a function.

      But a circle can be graphed by two functions on the same graph.
      y=√(r²-x²) and y=-√(r²-x²)

      If you look at this program, you will see that it used two functions to create the graph: http://www.khanacademy.org/cs/xr-yr-1/1807411349
      (172 votes)
  • winston baby style avatar for user Hannah
    at why is y a square root of three? why not 3 squared?
    (2 votes)
    Default Khan Academy avatar avatar for user
    • piceratops ultimate style avatar for user Brendan
      You have to remember that in algebra, what is done to one side of the equation has to also be done to the other side of the equation. When y^2 = 3, in order to find out what y is equal to, you have to get rid of the square. If you square 3, you also have to square the other side of the equation to make it equal. 3^2 would be equal to y^4, which doesn't really help us. Instead, get rid of the square by getting the square root of y squared (which is equal to y) and then finding the square root of the 3.
      (369 votes)
  • leaf green style avatar for user WillMosher
    What's the difference between functions in algebra and functions in programming languages? Is here one?
    (110 votes)
    Default Khan Academy avatar avatar for user
    • male robot hal style avatar for user Cameron
      In programming, the concept of functions came from the idea of functions in mathematics.

      How they are similar:

      In math:
      -You take some input values
      -You give them to your function
      -You get some output

      In a program
      -You have some inputs
      -You give them to the function
      -You get some output

      How they are different:
      In math:
      -If we give the function the same input, we always get the same result
      -Typically, the most important part of the function is the output

      In programming:
      -If we give the function the same inputs, we may get different results
      (This could be because of randomness or the function having "side effects" that record an internal state. There are some programming languages called "functional programming languages" e.g. Haskell, where functions don't have side effects and as a result act like functions in math. While these programming languages exist, they are much less popular than other programming languages)
      -Often, we don't care about what the output from a function is, because the "side effects" are the most important part e.g. We could have a function that loaded a game, that returned 1 if it was sucessful or 0 if it failed. Loading the game is what we care about, the 0 and 1 aren't that important.

      Hope this makes sense
      (2 votes)
  • female robot grace style avatar for user ilovemeat123
    I don't get how Sal got h(2)=3 and h(8)=11. someone help please?
    (2 votes)
    Default Khan Academy avatar avatar for user
  • leaf blue style avatar for user raqinda
    why are there two variables?
    (13 votes)
    Default Khan Academy avatar avatar for user
    • piceratops ultimate style avatar for user David Solorzano
      If you mean, "why does f(x) contain two variables?", please note the f is not a variable. The f is just a way for you to know that when you see f(x) to treat it as a function and not mistakenly treat it as multiplying one variable by the other (it DOES NOT mean f multiplied by x). It does not have to be an f, it can be any symbol and using different symbols such as h(a) helps differentiate one function from another.
      (2 votes)
  • leaf blue style avatar for user TB
    Can a function have multiple inputs? If so, how would you graph said function?
    (7 votes)
    Default Khan Academy avatar avatar for user
    • stelly blue style avatar for user Kim Seidel
      Yes, a function can have multiple inputs. We can graph in the coordinate plane when we have 1 input to 1 output. If we have a function with 2 inputs to create 1 output, we can graph in a 3 dimensional graph of (x, y, z). Once you go to even higher inputs, we typically would not graph them as we don't what a 4-dimensional space looks like.
      (13 votes)
  • starky ultimate style avatar for user Toska Pi
    Hi! I was wondering if there is a relationship between the equation describing how to plot a circle () and the Pythagorean theorem.
    (5 votes)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user itimespi
      Yep, there definitely is.

      Let's consider a circle with center (0, 0) (to make the explanation a little simpler) and radius 3. Let's find some points on the outer edge of the circle.

      A noticeable one is (3, 0) (3 units away from the center). Let's try to make a right triangle, where the center of the circle is one vertex, and its opposite vertex is the outer edge. Since this is a right triangle, we should be able to apply the Pythagorean theorem. The base of the triangle would be the x-axis, and the adjacent side would be some y-value. The hypotenuse would be the radius of our circle. Thus, a = x, b = y, and c = r. Using this in the Pythagorean theorem, we find:
      x² + y² = r²

      Does this work for the point we selected (aka (3, 0))?
      3² + 0² = 3² → 9 + 0 = 9 → 9 = 9 ✓

      You will find that this works for every single point on the circle. For example, another point on our circle is (3/√2, 3/√2). Does this work in our equation?
      (3/√2)² + (3/√2)² = 3² → (9/2) + (9/2) = 9 → 18/2 = 9 → 9 = 9 ✓

      When you use this equation with every possible x-value and y-value and graph the points you are able to make, you will construct a circle.
      (15 votes)
  • old spice man green style avatar for user Jonathan Ziesmer
    What does the f stand for?
    (3 votes)
    Default Khan Academy avatar avatar for user
    • old spice man green style avatar for user Eli Rochelle
      Basically, the concept of functions gives us a way to name the whole
      process of evaluating a particular expression, so we can talk about
      it as a whole. We can compare different functions, discuss their
      properties, or actually operate on functions to make new functions.
      It also broadens the concept, because not all functions can be
      written as a simple expression. These two processes, naming things
      and extending them, are central to what mathematics is all about.

      For example, the first function you showed can be called 'squaring',
      and the second can be called 'adding 3'; but most functions would
      have to have much more complicated names. By calling one F and the
      other G, we have a simple way to discuss them. Some functions, like
      the square root and the absolute value, can't be expressed in terms
      of more basic functions, but only by inventing a whole new symbol. In
      fact, we like to write the square root as 'sqrt(x)', using function
      notation, because we don't have the symbol available in e-mail.

      We can also treat these names like variables, where we don't know what
      specific functions we are calling f and g, yet we can say general
      things about the relation of f and g, proving that something is true
      for ANY functions, or at least for any functions of a certain type,
      all at once. That is powerful!
      (2 votes)
  • leaf green style avatar for user X Y
    How can we graph the fancy function h(a)?
    (6 votes)
    Default Khan Academy avatar avatar for user
    • hopper cool style avatar for user 🍕⚡ ViςhαL Πaudel⚡🍕
      Good question, but, we need more info! For essence 'h (a) = x*a + b', where 'x' is the slope of the function and 'b' is the Y-axis intersection, or what you call is as a "Y intersect". ( Remember 'b' can either be positive or negative) A function is nothing but a number "operator" it takes some numbers & variables, fiddles with it and gives only one output. Thanks! May you have a great Day/Evening ;] .

      Extra: Well, if you are given an expression for h(a) which is not necessarily linear(that is not of the form of ax+b) then you can graph it computing various output points on various inputs and get a sense of the function's graph(you can use some concepts of how the function progresses or looks like using calculus and understand the end behaviour).
      (8 votes)
  • hopper jumping style avatar for user Komal
    So, a function is like a machine. You input something into that machine, and you get the output. If we have f(2)=4, then we know that if we input 2 into that machine (f), the machine will output 4. Is this a good, basic way of explaining functions? :)
    (6 votes)
    Default Khan Academy avatar avatar for user

Video transcript

A function-- and I'm going to speak about it in very abstract terms right now-- is something that will take an input, and it'll munch on that input, it'll look at that input, it will do something to that input. And based on what that input is, it will produce a given output. What is an example of a function? I could have something like f of x-- and x tends to be the variable most used for an input into the function. And the name of a function, f tends to be the most-used variable. But we'll see that you can use others-- is equal to, let's say, x squared, if x is even. And let's say it is equal to x plus 5, if x is odd. What would happen if we input 2 into this function? The way that we would denote inputting 2 is that we would want to evaluate f of 2. This is saying, let's input 2 into our function f. And everywhere we see this x here, this variable-- you can kind of use as a placeholder-- let's replace it with our input. So let's see. If 2 is even, do 2 squared. If 2 is odd, do 2 plus 5. Well, 2 is even, so we're going to do 2 squared. In this case, f of 2 is going to be 2 squared, or 4. Now what would f of 3 be? Well, once again, everywhere we see this variable, we'll replace it with our input. So f of 3, 3 squared if 3 is even, 3 plus 5 if 3 is odd. Well, 3 is odd, so it's going to be 3 plus 5. It is going to be equal to 8. You might say, OK, that's neat, Sal. This was kind of an interesting way to define a function, a way to kind of munch on these numbers. But I could have done this with traditional equations in some way, especially if you allowed me to use the squirrelly bracket thing. What can a function do that maybe my traditional toolkits might have not been as expressive about? Well, you could even do a function like this. Let me not use f and x anymore, just to show you that the notation is more general than that. I could say h of a is equal to the next largest number that starts with the same letter as variable a. And we're going to assume that we're dealing in English. Given that, what is h of 2 going to be? Well, 2 starts with a T. What's the next largest number that starts with a T? Well, it's going to be equal to 3. Now what would h of-- I don't know, let's think about this, h of 8 be equal to? Well, 8 starts with an E. The next largest number that starts with an E-- it's not 9, 10-- it would be 11. And so now you see it's a very, very, very general tool. This h function that we just defined, we'll look at it. We'll look at the letter that the number starts with in English. So it's doing this really, really, really, really wacky thing. Now not all functions have to be this wacky. In fact, you have already been dealing with functions. You have seen things like y is equal to x plus 1. This can be viewed as a function. We could write this as y is a function of x, which is equal to x plus 1. If you give as an input-- let me write it this way-- for example, when x is 0 we could say f of 0 is equal to, well, you take 0. You add 1. It's equal to 1. f of 2 is equal to 2. You've already done this before. You've done things where you said, look, let me make a table of x and put our y's there. When x is 0, y is 1. I'm sorry. I made a little mistake. Where f of 2 is equal to 3. And you've done this before with tables where you say, look, x and y. When x is 0, y is 1. When x is 2, y is 3. You might say, well, what was the whole point of using the function notation here to say f of x is equal to x plus 1? The whole point is to think in these more general terms. For something like this, you didn't really have to introduce function notations. But it doesn't hurt to introduce function notations because it makes it very clear that the function takes an input, takes my x-- in this definition it munches on it. It says, OK, x plus 1. And then it produces 1 more than it. So here, whatever the input is, the output is 1 more than that original function. Now I know what you're asking. All right. Well, what is not a function then? Well, remember, we said a function is something that takes an input and produces only one possible output for that given input. For example-- and let me look at a visual way of thinking about a function this time, or a relationship, I should say-- let's say that's our y-axis, and this right over here is our x-axis. Let me draw a circle here that has radius 2. So it's a circle of radius 2. This is negative 2. This is positive 2. This is negative 2. So my circle, it's centered at the origin. It has radius 2. That's my best attempt at drawing the circle. Let me fill it in. So this is a circle. The equation of this circle is going to be x squared plus y squared is equal to the radius squared, is equal to 2 squared, or it's equal to 4. The question is, is this relationship between x and y-- here I've expressed it as an equation. Here I've visually drawn all of the x's and y's that satisfy this equation-- is this relationship between x and y a function? And we can see visually that it's not going to be a function. You pick a given x. Let's say x is equal to 1. There's two possible y's that are associated with it, this y up here and this y down here. We could even solve for that by looking at the equation. When x is equal to 1, we get 1 squared plus y squared is equal to 4. 1 plus y squared is equal to 4. Or subtracting 1 from both sides, y squared is equal to 3. Or y is equal to the positive or the negative square root of 3. This right over here is the positive square root of 3, and this right over here is the negative square root of 3. So this situation, this relationship where I inputted a 1 into my little box here, and associated with the 1, I associate both a positive square root of 3 and a negative square root of 3, this is not a function. I cannot associate with my input two different outputs. I can only have one output for a given input.