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

Worked example: graphing piecewise functions

A piecewise function is a function that is defined in separate "pieces" or intervals. For each region or interval, the function may have a different equation or rule that describes it. We can graph a piecewise function by graphing each individual piece.

Want to join the conversation?

  • blobby green style avatar for user Christopher Uren
    At the blue and purple lines join at a point. How do you know whether to make that point an open circle or a closed circle, if they were different inequalities? Does it always just become coloured in?
    (10 votes)
    Default Khan Academy avatar avatar for user
    • hopper cool style avatar for user Chuck Towle
      Christopher,
      You asked an excellent question. In the video, Sal did not stress why he filled in the circle, probably because he assumed this had been covered in another video.

      I'll try to explain it.

      When Sal did the first interval, at , he left the circle not filled in at (-2,5) because the second sign was > and not ≤. But then Sal did the next interval at the same point at (-2,5) was calculated, but this time the ≤ was used in the first part of the interval. Because this included being "equal to", the circle was then filled in.

      Had the second interval been x+7, -2 *<* x < -1, neither interval would have had a closed circle at (-2,5), so the point would have had an open circle.

      As each interval is worked, the circle is either filled in or left open If the same point is first left open, but in the next interval, it should be filled in, it is filled in. However, if the problem had been different, and the point was filled in on the first interval, but the same point would have normally been not filled in on the next interval, it still remains filled in.

      I hope that helps make it click for you.
      (40 votes)
  • leaf green style avatar for user Kevin Hoffman
    Does this mean that you can make the graphs of functions I've seen that bump up and down using this? Is there anything else? Thx
    (22 votes)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user Melcalc
      If you're talking about sawtooth functions, square waves, or triangle waves, yes. A sawtooth function can be represented by the piecewise linear function: x-floor(x), and similarily the other waveforms can be represented by more convoluted combinations of floor functions, which are piecewise.
      (7 votes)
  • blobby green style avatar for user venadane.priwingsih
    what should I do if the equation says f(x) = (bracket) 3 if x< 2. what should I do with the 3? where can I plug in the 2?
    (6 votes)
    Default Khan Academy avatar avatar for user
    • starky ultimate style avatar for user Top Ramen
      Sorry this is super late, but here's my understanding of it.

      F(x) = ()3, x < 2

      This piece of function would apply to any x value from negative infiniti up to (but not including) two. The 2 is just there to tell you what x variables that function piece applies to. That 3 would be multiplied by whatever is in the parenthesis.
      (5 votes)
  • duskpin tree style avatar for user Abhi
    are the lines not always straight?
    (3 votes)
    Default Khan Academy avatar avatar for user
  • duskpin tree style avatar for user Laura
    Do you write the x and y points in the order of which line is the highest on the graphs?
    (3 votes)
    Default Khan Academy avatar avatar for user
  • leafers seedling style avatar for user karen
    mmk, but what if there's no "x" in the first part of the equation? (for example if it was just 7 instead of "x+7")
    (2 votes)
    Default Khan Academy avatar avatar for user
  • sneak peak green style avatar for user S. Volkov
    Isn't it interesting how if you look at the transcript it says
    So, I'm gonna put a little open circle there,
    and then I'm gonna draw the line.
    And then I'm gonna draw the line.
    I am going to draw my best attempt, my best attempt,
    at the line.
    It seems like poetry but when you actually go to it sounds like he's deciphering ancient runes.
    (4 votes)
    Default Khan Academy avatar avatar for user
  • leafers tree style avatar for user Tams Fletcher
    At Sal fills in the previously pink open circle with the orange closed circle. In a previous video Sal said you could not have a value defined twice or it is not a function, and thus the < instead of =< for the otherwise overlapping values. In this case, though, it would have been different ways of writing the same thing. I think that the pink x values could have been x =< -1 as well as the orange defining the value for -1 <=x because both gave the same y value (6).
    Is this the case? Can each part of a piecewise function 'overlap' if the output values are the same?
    (3 votes)
    Default Khan Academy avatar avatar for user
  • blobby blue style avatar for user Someone
    I have a problem really confusing me. When do you put open and closed circles on the graph?
    (2 votes)
    Default Khan Academy avatar avatar for user
    • duskpin ultimate style avatar for user Selina ✨
      Open and closed circles are used to show whether a number is included or excluded from a certain range of numbers. For example, if the range was "x > 5" the line would have an open circle at 5 and continue to the right. If the range was "x ≥ 5", the line would have a closed circle at 5 and continue to the right. If it's "greater than or equal to" or "less than or equal to", the line should have a closed circle. If it's "greater than" or "less than" the line should have an open circle.
      I hope that helped!
      (3 votes)
  • blobby green style avatar for user jacob reeves
    at how do you know if the blue and purple lines are closed or open circles.
    (2 votes)
    Default Khan Academy avatar avatar for user
    • stelly blue style avatar for user Kim Seidel
      The inequality symbols tell you which to use.
      Notice, the 1st part of the blue line tells you -10<=x. This means "x" can equal 10 or be larger than 10. Since "x" can equal -10, use a closed circle. On the opposite end, it tells you x<-2. Now "x" must be less than -2. It can't equal -2. This is when you use the open circle.

      Hope this helps.
      (2 votes)

Video transcript

- [Voiceover] So, I have this somewhat hairy function definition here, and I want to see if we can graph it. And this is a piecewise function. It's defined as a different, essentially different lines. You see this right over here, even with all the decimals and the negative signs, this is essentially a line. It's defined by this line over this interval for x, this line over this interval of x, and this line over this interval of x. Well, let's see if we can graph it. I encourage you, especially if you have some graph paper, to see if you can graph this on your own first before I work through it. So, let's think about this first interval. When negative 10 is less than or equal to x, which is less than negative two, then our function is defined by negative 0.125x plus 4.75. So this is going to be a line, a downward sloping line, and the easiest way I can think about graphing it is let's just plot the endpoints here, and then draw the line. So, when x is equal to 10, sorry, when x is equal to negative 10, so we would have negative zero, actually let me write it this way. Let me do it over here where I do the, so we're going to have negative 0.125 times negative 10 plus 4.75. That is going to be equal to, let's see, the negative times a negative is a positive, and then 10 times this is going to be 1.25 plus 4.75. That is going to be equal to six. So, we're going to have the point negative 10 comma six. And that point, and it includes, so x is defined there, it's less than or equal to, and then we go all the way to negative two. So, when x is equal to negative two, we have negative 0.125 times negative two plus 4.75 is equal to, see negative times negative is positive, two times this is going to be point, is going to be positive 0.25 plus 4.75. It's going to be equal to positive five. Now, we might be tempted, we might be tempted, to just circle in this dot over here, but remember, this interval does not include negative two. It's up to and including, it's up to negative two, not including. So, I'm gonna put a little open circle there, and then I'm gonna draw the line. And then I'm gonna draw the line. I am going to draw my best attempt, my best attempt, at the line. Now, let's do the next interval. The next interval, this one's a lot more straightforward. We started x equals negative two, when x equals negative two negative two plus seven is, negative two plus seven is five. So, negative two, so negative two comma five, so it actually includes that point right over there. So we're actually able to fill it in, and then when x is negative one, negative one plus seven is going to be positive six. Positive six, but we're not including x equals negative one up to and including, so it's going to be right over here. When x is negative one, we are approaching, or as x approaches negative one, we're approaching negative one plus seven is six. So, that's that interval right over there. And now let's look at this last interval. This last interval, when x is negative one, you're going to have, well, this is just going to be positive 12 over 11 'cause we're multiplying it by negative one, plus 54 over 11 which is equal to 66 over 11 which is equal to positive six. So, we're able to fill in that right over there, and then when x is equal to 10, you have negative 120 over 11. I just multiplied this times 10, 12 times 10 is 120, and we have the negative, plus 54 over 11. So this is the same thing. This is going to be, what is this? This is negative 66 over 11, is that right? Let's see, if you, yeah, that is negative 66 over 11, which is equal to negative six. So when x is equal to 10, our function is equal to negative six. And so this one actually doesn't have any jumps in it. It could've, but we see, so there we have it. We have graphed this function that has been defined in a piecewise way.