Graphing a Piecewise Function Using Desmos
A piecewise function is a function whose definition changes depending on the value of the domain.
When functions are defined by more than one equation, they are called piecewise-defined functions.
View the following video:
Is the (left) piecewise equation a function?
It looks to be a function because it has two equations and the restrictions on x for each, but there is a problem. What is it?
Let's recall the definition of a function... Every element in the domain must be mapped onto one and only one element in the range.
When graphing a piecewise function, we must make sure the domain is NOT repeated.
Using Desmos to Graph Piecewise Functions
Example 1 - Graphing a Piecewise Function Using Desmos (with color)
Because it will be helpful to make a visual distinction between each function, we will write each equation of the piecewise function as a separate function. The piecewise function is located on the left.
Method 1 (the one we will be using)
This would be typed in Desmos as follows:
1. y = {x < -2: x + 5}
2. y = {x ≥ -2: x2 + 2x + 3}
It will always be written as y = {condition: function}
Explanation and process:
1. y = {x < -2: x + 5}
~ Test the first condition: x < -2
~ If this condition is true, then execute the expression (x + 5)
2. y = {x ≥ -2: x2 + 2x + 3}
~ If the first condition is false, the second condition will be tested: x ≥ -2
~ If the second condition is true, then execute the expression (x2 + 2x + 3)
Your graph should look similar to this one (Right ---->
Because x + 5 does not include 2 (because the inequality is <), an open circle is drawn. (green graph).
And x2 + 2x + 3 does include 2 (because the inequality is ≥ ), a close circle is drawn. (red graph)
Here's how to include an open circle:
1. After you graph the function, determine where the hole would exist - That would occur when the inequality is < or >
2. Click on the end of the graph to determine the coordinates of the hole or circle.
3. Record the coordinates in the input area and check the box - Label. (Image (right) red circle has the coordinates: (-2, -1))
4. You should see a circle to the left of the coordinates.
5. Click on the circle's icon (Image (right) purple circle) and press on it until you see the following Points options: Notice that there are 3 options - closed circle, opened circle, and x
6. Click on the open circle.
7. An open circle should be visible on the graph.
Example 2 - Graphing a Piecewise Function - (No color)
We will look at the initial function to determine if this is a function. (Right ---->
Method 2 - We won't use this method, but it is valid.
Below is the syntax for graphing piecewise functions in Desmos.
y = {condition: value, condition: value, }
y = {x ≤ 1: x + 2, x ≥ 1: x - 2} Desmos statement.
Note: the two functions are separated with a comma.
Explanation and process:
~ Test the first condition: x ≤ 1
~ If this condition is true, then execute the expression (x + 2)
~ If the first condition is false, the second condition will be tested: x ≥ 1
~ If the second condition is true, then execute the expression (x - 2)
The graph of the piecewise equation is at the right ---->
This graph has two linear graphs.
~ The first graph y = x + 2 has the initial point at x = 1 with coords (1,3).
~ The second graph y = x - 2 also has the initial point at x = 1 with coords (1, -1).
Test to determine if this is a function by using the vertical line test (red line).
This piecewise equation is NOT a function.
Its domain, x = 1, has two values in the range, 3 and -1.
Looking back at the piecewise equation, you should notice that both equations have the same restriction.
The first linear equation will be graphed when the values of x are less than or equal to 1.
The second one will be graphed when the values of x are greater than or equal to 1.
Both have equal to, so just by looking at the equations, you should know that this wasn't a function.
Example 3 - Graphing a Piecewise Function Using Desmos
Let's determine if the piecewise equation (at right) is a piecewise function.
~ When the domain is less than 2, the linear function y = 3x - 2 is graphed.
~ When the domain is greater than or equal to 2, the linear function y = 4 is graphed.
~ It appears to be a function. Let's use Desmos to graph it to determine if we are correct.
We will type the following expression in Desmos:
1. y = {x < 2: 3x - 2}
2. y = {x ≥ 2: 4 }
Remember: {condition first, then function,...} (Graph at right ---->
The domain will be (-∞, ∞). The range will be (-∞, 4]. Using the vertical line test, we see that there exists one and only one range value for the domain value of x = 2. This is a piecewise function.