Home » Math Theory » Algebra » Piecewise Functions

# Piecewise Functions

## What is a function?

The concept of function is of paramount importance in mathematics and among other disciplines as well. Let us now recall some of the concepts related to functions that are relevant to the understanding of piecewise functions.

### Function as a set of ordered pairs

Let A and B be two non-empty sets. A relation from A to B i..e a subset of A x B is called a function or a mapping or a map from A to B if,

1. For each a ∈ b, there exists b ∈ B such that ( a, b ) ∈ f
2. ( a, b ) ∈ f and ( a, c ) ∈ f ⇒ b = c

Thus a non-void subset of A x B is a function from A to B if each element of A appears in some ordered pair in f and no two pairs in f have the same first element.

### Domain, Co-domain and Range of a Function

Let f : A → B. then the set A is known as the domain of f and the set B is known as the range co-domain of f. the set of all f-images of elements of A is known as the range of f or image set of A under f and is denoted by f ( A ).

Thus f ( A ) = { f (x)  : x ∈ A } = Range of f

Let us now understand what we mean by piecewise functions

## What are Piecewise Functions?

There are instances where the expression for the functions depends on the given interval of the input values. In such circumstances, the functions are known as piecewise functions. Hence, piecewise functions can be defined as –

A piecewise function is a function that is defined by different formulas or functions for each given interval. It’s also in the name: piece. The function is defined by pieces of functions for each part of the domain.

Let us understand the piecewise functions through an example.

Suppose we have a function defined in a manner that f( x ) will have different values in accordance to different positions of x, such as,

f ( x ) will be equal to 2x if x > 0

f ( x ) will be equal to 1 if x = 0

f ( x ) will be equal to – 2x if x < 0

The above function can be written as

f ( x)  = {2x for x>0 1 if x=0 – 2x if x<0

The above function is thus a piecewise function.

## How to write a Piecewise Function ?

The following steps are used to identify the conditions in a piecewise function and write it in mathematical form –

1. Identify the intervals for which different rules apply.
2. Determine formulas that describe how to calculate an output from an input in each interval.
3. Use braces and if-statements to write the function.

Let us understand this through an example.

Example

A museum charges £10 per person for a guided tour with a group of 1 to 9 people or a fixed £100 fee for a group of 10 or more people. Write a function relating the number of people, n, to the cost, C.

Solution

We have been given the condition that a museum charges £10 per person for a guided tour with a group of 1 to 9 people or a fixed £100 fee for a group of 10 or more people. In this statement we can clearly see that there are two conditions depending upon the number of people. The two conditions are  –

1. If the number of people ranges from  1 – 9, the fee charged is £10 per person.
2. If the number of people is 10 and above, the fee charged is £100.

We can see that in the first condition, the value is dependent upon the number of people, n. This condition can be mathematically stated as a fee of £10n for n ranging between 1 and 9.

The second condition involves a constant value of £100 for n greater than or equal to 10.

The function f ( x ) to the cost C can thus be defined as –

C =  {5n, if 0<n<10 100, if n ≥10

Hence the function for the statement, “A museum charges £10 per person for a guided tour with a group of 1 to 9 people or a fixed £100 fee for a group of 10 or more people” will be

C =  {5n, if 0<n<10 100, if n ≥10

Now that we know how to write a piecewise function, it is important to learn about some standard piecewise functions. There are many functions that we use in everyday mathematics which are actually piecewise function. Let us learn about some of such standard functions.

## Modulus Function

The function f ( x) is defined by

f ( x ) = | x | = {-x,  x<0 x,  x≥0

is called a modulus function. It is also called an absolute value function. We observe that the domain of the modulus function is the set R of all real numbers and the range is the set of all non-negative real numbers. This means that,

R+ = { x ∈ R : x≥0 }

### Properties of Modulus function

The following are the properties of a modulus function –

1. For any real number x, we have, $\sqrt{x^{2}}$ = | x |

For example,

$\sqrt{cos^{2}}x$ = | cos x | = {coscos x, 0 ≤x ≤ $\frac{\pi}{2}$  -coscos x , $\frac{\pi}{2}$<x<π

1. If a, b are positive real numbers, then,
1. x2 $\leq$ a2 ⬄| x | $\leq$ a ⬄ – a $\leq$ x $\leq$ a
2. x2 $\geq$ a2 ⬄| x | $\geq$ a ⬄ x $\geq$ a or  $\leq$ x $\leq$   – a
3. x2 < a2 ⬄ | x | < a ⬄ – a < x < a
4. x2 > a2 ⬄ | x | > a ⬄ x < – a or x > a
2. For real numbers, x and y we have,
1. | x  + y | =  | x | + | y |, if ( x $\geq$ 0 and y $\geq$ 0 ) or ( x < 0 and y < 0 )
2. | x  – y | =  | x | – | y |, if ( x $\geq$ 0 and | x | $\geq$ | y | ) or ( x $\leq$ 0, y $\leq$ 0 and | x | $\geq$ | y | )
3. | x $\neq$ y | $\leq$ | x | + | y |
4. | x $\neq$ y | >  | | x | – | y | |

## Logarithmic Function

If a > 0 and a $\neq$ 1 then the function defined by f ( x )  = x , x > 0 is called the logarithmic function.

Logarithmic function is an inverse functions.

Recall that in case inverse functions,

Let f : A → B be a bijection. Then a function g : B → A which associates each element y B to a unique element x A such that f ( x )  = y is called the inverse of f.

Now, since logarithmic function is an inverse function, this means,

x = y ⬄ x = ay

Let us now check the domain and the range of this piecewise function.

We observe that the domain and the range of the logarithmic function is the set of all positive real numbers. This means that ( 0, $\infty$ ) is the domain of the function and the range is the set R of all real numbers.

As a > 0 and a $\neq$ 1, So we have the following cases –

Case 1 When a > 1

In this case, we have

y = x {<0 for 0<x<1 =0 for x=1 >0 for x>1

Also, the values of y increase with the increase in x.

Now, let us consider the second case, where a lies between 0 and 1

Case 2 When 0 < a  < 1

In this case we have,

y = x {  >0 for 0<x<1 =0 for x=1 <0 for x>1

### Properties of Logarithmic Functions

Following are the properties of logarithmic functions –

1. 1 = 0, where a > 0, a $\neq$ 1
2. a = 1, where a > 0, a $\neq$ 1
3. (x y ) =  | x | + | y | ,  where a > 0, a $\neq$ 1 and  x y > 0
4. ( $\frac{x}{y}$ ) =  | x | – | y | ,  where a > 0, a $\neq$ 1 and $\frac{x}{y}$ > 0
5. xn = n | x | ,  where a > 0, a $\neq$ 1 and  xn > 0

## Graphs of Piecewise Functions

Now that we have learnt that piecewise functions contain different functions for each of the given intervals, this means that when graphing piecewise functions, we should expect to graph different functions for each interval as well. For a better understanding of how to plot graphs of piecewise functions, let us analyse the graphs of some standard piecewise functions.

### Graph of Modulus Function

The graph of the modulus function is shown in the below figure.

It is important to note here that for x > 0 the graph of the modulus function coincides with the graph of the identity function, i.e. the line y =  x and for x < 0 it is coincident to the line y =  -x.

### Graph of Logarithmic Function

We have leant above the definition of a logarithmic function. We have also discussed about two different cases depending upon the values of a.

So, there are two different graphs based upon these different values.

Let us first plot the graph for the first case where b > 1

y = x {<0 for 0<x<1 =0 for x=1 >0 for x>1

The graph of this function will be represented as –

Now let us plot the graph of case 2.

Case 2 When 0 < a  < 1

In this case we have,

y = x {  >0 for 0<x<1 =0 for x=1 <0 for x>1

The graph of this function will be represented as –

## Evaluating Piecewise Functions

Now that we have understood what piecewise functions are and how they are written in mathematical form, let us move towards solving these functions for different values of x. the following [points must be taken into account while evaluating piecewise functions –

1. Double-check where x lies in the given interval.
2. Evaluate the value using the corresponding function.

Let us understand this through an example.

Example Evaluate f(x) when x = – 3, x = 2, and x =  4. Then plot the graph f(x).

f ( x ) = {x+1, if x<2 -2x+7, if x ≥2

Solution We have been given different values of f ( x)  depending upon the values of x. Clearly, this function is a representation of a piecewise function.

Evaluating a piecewise function adds an extra step to the whole proceedings. We have to decide which piece of the function to choose from. Since -3 is less than 2, we use the first function to evaluate x = -3.

We can see that for x = -3, we will have to use the first condition, which mentions the value of x for x < 2. We will have,

f ( x )  = x + 1

Substituting x = 3 in the above equation, we get,

f ( – 3 ) = -3 + 1 = -2

Hence, f ( – 3 )  = – 2

Now, let us come to x = 2

We can see that the number is the boundary line of the two conditions of the function. So, we need to check the condition that includes x = 2, which in our case is the second condition. We have,

f ( x ) = -2 x + 7

Substituting x = 2 in the above equation, we get,

f ( 2 ) = -2 ( 2 ) + 7 = 3

Hence f ( 2 ) = 3

The second function continues to be used, from 2 onward to infinity—and beyond. Therefore, for obtaining the value of the function at x = 4, we are required to use the second condition. We, therefore, have,

f(x) = -2x + 7

Substituting x = 4 in the above equation, we get,

f ( 4 ) = -2 ( 4 ) + 7 = – 1

Hence, f ( 4 ) = – 1

Now, let us move to plot the function.

To the left of x = 2, f ( x ) = x + 1. The graph will go right up to, but not touch, f ( 2 ) = 2 + 1 = 3. Then f ( x ) = -2x + 7 to the right of and including x = 2. We can also use the three points having different values of x, we have just obtained.

So, we have,

For x = -2, f ( x  ) = -2

For x = 2, f ( x  ) = 3

For x = 4, f ( x  ) = -1

For x = 0, f ( x  ) = 1

Plotting these values on the x-y axis we will get the following graph.

## Remember

1. A piecewise function is a function that is defined by different formulas or functions for each given interval.
2. A non-void subset of A x B is a function from A to B if each element of A appears in some ordered pair in f and no two pairs in f have the same first element.
3. Let f : A → B. then the set A is known as the domain of f and the set B is known as the range co-domain of f. the set of all f-images of elements of A is known as the range of f or image set of A under f and is denoted by f ( A ).
4. The function f ( x) is defined by
f ( x ) = | x | = {-x,  x<0 x,  x≥0
is called a modulus function. It is also called an absolute value function.
5. For any real number x, we have, $\sqrt{x^{2}}$ = | x |
6. If a > 0 and a $\neq$ 1 then the function defined by f ( x )  = x , x > 0 is called the logarithmic function.
7. Logarithmic function is inverse functions.
8. For x > 0 the graph of the modulus function coincides with the graph of the identity function, i.e. the line y =  x and for x < 0 it is coincident to the line y =  -x.
9. 1 = 0, where a > 0, a $\neq$ 1
10. a = 1, where a > 0, a $\neq$ 1
11. (x y ) =  | x | + | y | ,  where a > 0, a 1 and  x y > 0
12. ( $\frac{x}{y}$ ) =  | x | – | y | ,  where a > 0, a $\neq$ 1 and $\frac{x}{y}$ > 0
13. xn = n | x | ,  where a > 0, a $\neq$ 1 and  xn > 0
14. While evaluating a piecewise function, double-check where x lies in the given interval. Evaluate the value using the corresponding function.