The Drawer of Piecewise Functions

A Tutorial Applet by Dr. Gary Kerbaugh

To the Program

 

The Concept

Simply put, a function is a mechanism for taking a number from you and then giving you a number back. In a math class, this is usually a sequence of arithmetic operations. Usually, the function behaves ignorantly, applying the same process no matter what number you give it. A piecewise function behaves more realistically. It looks at the number first, and decides what to do based on the number itself. The first example most people see is the absolute value function. This function needs to know whether the number given it is positive or negative before deciding what to do with it. If the number is already positive, the absolute value leaves it alone. However if the number is negative, the absolute value function has to change its sign.

Piecewise functions generally decide what formula to put a number into on the basis of "where" the number is found. In the above example, positive numbers are found "to the right" of zero and negative numbers are found "to the left" of zero. For the purpose of graphing, it is useful to consider how this relates to the x-y plane. The set of all points associated with a given value of x, such as 2, would be the vertical line of points situated above and below the 2 on the x-axis. Similarly, the points of the plane associated with an interval of points on the x-axis would be a vertical strip of points lying directly above and below the interval. This is akin to specifying the location of an airplane in terms of the ground over which the plane is flying. The control space of a region on the ground is a vertical strip of air directly above that region.

To give you a feel for this, the program colors these strips in pastel colors. Of course, like any graphing program, first you must put the function into the program. When you first do this, you see the graph of the function over the entire window. However, when you view the function along with the others, you see only the part of the graph that appears within the originally specified strip. Do you know how the program achieves this? It gives the function only values of x that are within the specified strip.

Graphing a Piecewise Function

This program draws the graph one strip at a time, using a different function to determine the heights of the graph for each strip. Kids, don't try this at home. Wait a minute, you're not kids and so you must try this at home. Use the tables that I have shown you in class. Make an x column with lots of values, but arranged in increasing order. Make a different y column for each of the functions in your graph. Here's an important step: divide the table into horizontal strips, according to which x values go with which function. The boundaries of these strips are found in the "if" statements in the definition of the function. They must also be used to determine which strips go with which function. At this point make sure that each strip has a reasonable number of x values in it. Consider the following piecewise function:

We first look to the if statements and find that we will be dealing with boundaries at x = -2 and at x = 2. Let's create a table below with sufficient x values and the appropriate headers:

x
       
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6

Now, Let's divide the table into strips. At home, it would be sufficient to simply draw a dark horizontal line, but here I will actually have to break the table into pieces:

x
 
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6

Of course, I have given the functions in the problem in order of increasing x. If you were not as fortunate, you may want to rearrange the functions. Notice that the first group of numbers, -6, -5, -4, -3, and -2, satisfy the inequality x < -2. Since this is the inequality in the "if" statement beside the first function: if x < -2, I will use this function to determine the y for these x's and place those y values in the corresponding ( first ) column:

x
 
-6
2
-5
-1
-4
-2
-3
-1
-2
2
-1
0
1
2
3
4
5
6

The next group of numbers satisfy the inequality, -2 < x < 2. Since this is the inequality written beside the second function, when I evaluate the y's for these X's, I will put these results in the second column. Similarly, I will put the results for the last group in X's in the last column. The end result will be the following table:

x
 
-6
2
-5
-1
-4
-2
-3
-1
-2
2
-1
1
0
0
1
-1
2
-2
3
1
4
2
5
1
6
-2

Notice that there are only two numbers, an x value and a y value in each row. If I plot all of these x and y values and connect the dots between them, I should get a reasonable picture of the piecewise function. On the other hand, I could ask the computer to plot thousands of values and paint the background different colors according to which function was being plotted. I will do this now. The result appears below:

Of course, now you can do this too! Before you try it, let me give you a brief overview of the controls.

Graphing by Hand

Hopefully, this program will give you a feel what is going on that will help improve your ability to graph by hand. (since you can't use the program on a test) Naturally, you begin by simply plotting the points in a table like the one above. However, there is a pattern here, which, when understood can make the process much simpler. By this point in the course you should recognize and be able to sketch the graphs of a number of functions. If you can develop the ability to sketch just the part of the graph that is "in the strip" then you are halfway there. I often have students begin by drawing an entire graph on a sheet of paper and then literally cut out the strip. After doing this a few times, you should then try visualizing the entire function in your mind, but only drawing the part "in the strip". After you learn to do that, you need to be able to find the strip. For this you simply look at the "if" statement beside the function. Suppose you see -3 < x < 1. This is a vertical strip that is four units wide. The left hand boundary is the vertical line over x = -3 (three units to the left of the y axis) and the right hand boundary is the vertical line over x = 1. (one unit to the right of the y axis) When you can readily visualize the strip and the part of the full graph of the function that goes in it, you should be able to sketch piecewise functions. To help you do this, this program colors the strips to help you visualize them and it shows you the entire function before displaying just the part in the strip. You should have some examples with you that you have already graphed. If not, use the tables above to graph two or three homework problems. (making note of the points discussed in this paragraph) Then read below to find out how to use the program to do the job for you. (and hopefully, with you)

The Program

View Controls

The main panel of this program is the colored graphing panel. The default view is as you see above, but you may alter that view with the slidebars. The inner slidebars control the vertical and horizontal scales. You may view a picture that goes from -2 to 2 or you may view a picture that goes from almost -40 to 40. Of course you may view anything in between and you set the vertical and horizontal scales independently. The outer scrollbars simply slide the picture vertically and horizontally. Unfortunately, the implementation of Java in many browsers is incorrect and some fail to support more than two slidebars. Also, the program redraws the screen as you move, which leads to considerable flicker. To me, being able to see where I am as I move is worth the flicker. The default screen, however will display the functions given in most math problems, so it may be best to leave the scrollbars alone unless you need them. If moving them causes problems with the browser display, simply hit reload on the browser to start anew.

Setting Boundaries

The first thing you may want to do is locate the boundaries of your function. Again, these are the numbers that follow the "if" statements. All you have to do is click on the "Set Boundary" button, on the right hand control panel, and then click on the screen where you want the boundary to appear. A vertical line appears where you clicked. When the screen next redraws, it will be divided into differently colored strips and the boundary between the colors will be where that vertical line was. You may see that at any time by clicking the "Display Result" button. To add another boundary you must again click on "Set Boundary". This divides the screen into vertical strips, each to contain the graph of a different function.

Entering a Function

To enter a function, you first specify the region where you want the function to go. Click on the "Choose Region" button and then click on the screen anywhere within the desired region. The region is then painted red signifying that it is ready for you to specify a region. You then click on the "Select Function" button. A new window appears that contains templates for three types of functions, polynomials, rational functions, and square roots. You simply have to choose the type of function that you want and then enter the coefficients of the appropriate terms. You then hit the enter key to get the graph on the screen. You may reposition the function window to see the screen or click on the browser window to bring it to the front. Clicking on the "Select Function" button again brings the function window back to the front. You may make as many changes to the function as you like and the new function will be applied to the strip in red when you are done. When you are done click on the "Display Result" button to see the function in its strip. You may now repeat this procedure to put a function into another strip or to edit one already there. Just click on "Choose Region", click in the region on the screen, click on "Select Function", type in the appropriate coefficients, and click on "Display Result".

Further Editing

You may, of course, add new boundaries at any time. Adding a new boundary divides the strip containing it into two new strips. If there was a function graphed in the old strip, it is graphed in both of the new strips. You then simply select the new strip you want to change and put in a new function. You may edit over a function as many times as you like. Unfortunately, as there is currently no mechanism to select a boundary, there is no way to erase one. All you can do is click on "Clear All" and begin again. This is why I suggest that you put in the boundaries first. That way starting over is not a major inconvenience. Currently, the program connects graphs that do not meet at the boundaries. Mathematically, this is incorrect and will be fixed in the next version.

Enjoy

Piecewise functions can be a difficult concept to master. Practice is the best thing that you can do. This program gives you something different and visual to practice at. You should learn to graph a piecewise function using the tables above. However, after you are comfortable with that you may then use this program to generate the graphs you need on remaining homework problems. Hopefully, this program will save you some time on your homework. Just try to imagine what the program is doing and how you would do it yourself. I hope that you both enjoy the program and find it useful. I would love to here your feedback on it.

Go to the Program