The Wayback Machine - https://web.archive.org/web/20240930221434/https://www.geeksforgeeks.org/piecewise-function/
Open In App

Piecewise Function

Last Updated : 12 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Piecewise Function is a function that behaves differently for two types of input. As we know a function is a mathematical object which associates each input with exactly one output. For example: If a function takes on any input and gives the output as 3. It can be represented mathematically as f(x) = 3. But in the case of the Piecewise function, it is defined by individual expressions for each interval.

A piecewise function is defined across different intervals, each with its own specific function rule. A well-known example of such a function is the absolute value. Other examples of piecewise functions include the Heaviside step function, the rectangle function, and the triangle function, each characterized by distinct behaviors over their respective intervals.

In this article, we will study about piecewise function, how to graph a piecewise function, and how to evaluate it.

Piecewise Function

Piecewise Function

What is Piecewise Function?

Piecewise Function is a function that is defined differently on a sequence of intervals. In other words, a piecewise function is a mathematical function that is defined by multiple sub-functions, with each sub-function being valid only in a certain interval or region of the domain. In other words, a piecewise function is a function that is defined differently on different parts of its domain.

The general piecewise function can be written mathematically as:

[Tex]\bold{f(x) =\begin{cases} f_1(x),& \text{if } x < a \\ f_2(x),& \text{if } a \leq x < b \\ f_3(x),& \text{if } b \leq x \end{cases}} [/Tex]

Where,

  • f1(x), f2(x), and f3(x) are three different functions, and
  • a, b, and c are some real numbers.

The above expression for piecewise function means that for x less than a, the function takes on the value of f1(x), for x between a and b, it takes on the value of f2(x), and for x greater than or equal to b, it takes on the value of f3(x).\\

Piecewise Function Definition

A piecewise function, also known as a piecewise-defined function, is a function that is defined by different expressions or formulas on different intervals of its domain. This enables us to accurately describe functions that exhibit varying behaviors or properties within different ranges of input values.

Domain and Range of Piecewise Function

Domain and Range of a piecewise function can be calculated using the domain and range of the individual pieces and taking the union of that range and domains. 

Example: Find the Range and Domain of function f(x) which is defined as follows:

[Tex]\bold{f(x) = \begin{cases} x, & x<1 \\ 2, & 1 \leq x \leq 5\\ x^2, & x>5 \end{cases}} [/Tex]

Solution:

As the function is defined for all the real numbers, so its domain is R if is defined for some portion of R then that portion becomes its domain.

Now for Range of function, for x<2, f(x) = x, thus range for this part is x<2

For 2 ≤ x ≤ 5, f(x) = 2, thus its range is 2 as it is a constant function for this interval.

For x > 5, f(x) = x2, f(5) = 25 and x2 is continuous and increasing function for x > 0, thus range is x>25.

Now, the union of all the ranges is {x<2} U {2} U {x>25} = (-∞, 2] U (25, ∞)

Piecewise Function Graph

To graph the Piecewise Function, we just need to graph the function individually for all the different intervals it is defined.

Example: Plot the graph of the function defined as follows:

[Tex]\bold{f(x) = \begin{cases} x, & x<-1 \\ 2, & -1 \leq x \leq 2\\ x^2, & x>2 \end{cases}} [/Tex]

Solution:

As the domain of the function is the complete set of real numbers, thus there is no such values in R for which the function is not defined.

Now, for the first piece of graph for x < -1, is given as f(x) = x, which can be easily plotted. So the graph of a function for x < -1  is a straight line with a slope of 1 that passes through the origin. 

For the second piece of the graph for -1 ≤ x ≤ 2, the given function is a constant function as f(x) = 2. So the graph of a function for -1 ≤ x ≤ 2 is again a straight horizontal line which is at a 2 unit distance from the x-axis.

For the third piece of the graph for x > 2, the given function is a parabolic curve that opens upwards and x2 is a increasing and continuous function, so the graph starts at the point (2, 4) goes in the upward direction as parabolic curve.

Plot these three pieces of the graph to obtain the required graph of the function.

Graph of Piecewise Function

Piecewise Function Examples

There are many famous examples of piecewise functions, some of which are as follows:

Modulus Function

It is also called the absolute value function, and it is defined in two pieces as follows:

[Tex] \bold{f(x)= \begin{cases}x,& \text{if } x\geq 0\\-x,& \text{if } x<0 \end{cases}} [/Tex]

The graph of this function is as follows:

Graph of Modulus Function

Greatest Integer Function or Floor Function

The floor function also called the greatest integer function or integer value, gives the largest integer less than or equal to x. The domain for this function is all the real numbers R while the range of this function is all the integers Z. 

Graph of Floor Function

Question 1: What is the Floor of 1.43?

Solution:

Floor of a number is the greatest Integer lesser or equal to that number. Therefore, here the Floor of 1.43 is 1.

Floor of 1.43

Question 2: What is the Floor of -5.66? 

Solution:

On Negative axis, the greatest Integer lesser than -5.66 is -6.

Hence, -6 is the Floor of -5.66.

Least Integer Function or Ceiling Function

This function returns the smallest successive integer. The ceiling function of a real number x is the least integer that is greater than or equal to the given number x. The domain for this function is R and range Z. 

Graph of Ceiling Function

Similar to the floor function, the domain of the ceiling function is R and the range is all the integers I. 

Example 1: What is the Ceiling of 1.43?

Solution:

The ceiling of the 1.43 should be its smallest successive Integer, hence the ceiling of 1.43 is 2.

Ceiling of 1.43

Example 2: What is the ceiling of -7.8?

Solution:

The smallest successive Integer of -7.8 is -7.

Hence, -7 is the ceiling of -7.8.

Unit Step Function

Unit Step Function is yet another type of function used a lot in Signals and systems studies. It is defined as, 

[Tex]\bold{f(x) = \begin{cases}0,&x<0\\ 1,&x\geq0\end{cases}} [/Tex]

This function has no value at x = 0. It is called a step function because, at t = 0, it takes a step from 0 to 1. The domain for this function is R – {0} and range {0,1}. 

Graph of Unit Step Function

Signum Function

This function shows the polarity of the input number if the number is negative function spits out -1 as output and if the number is positive the signum function spits out +1 as output and for 0 which is neutral in nature signum function spits 0 as output. Mathematically signum function is defined as

[Tex]\bold{sgn(x) = \begin{cases} 1, & x>0\\ 0, & x = 0\\ -1, & x<0 \end{cases}} [/Tex]

The graph of the signum function is as follows:

Evaluating Piecewise Functions

Let’s consider the following examples of piecewise functions to evaluate their value at any given point.

Example: Find the value of the following function at x = -2 and x = 10. 

[Tex]\bold{f(x) =\left\{\begin{matrix}x^{2},& \text{if } x\geq 0\\ -x,& \text{otherwise}\end{matrix}\right.} [/Tex]

Solution:

[Tex]f(x)= \begin{cases} x^{2},& \text{if } x\geq 0\\ -x,& \text{otherwise} \end{cases} [/Tex]

at x = -2, x < 0 so the f(-2) = -2. 

at x = 10, x > 0, so f(10) = 102  = 100. 

Example: An arcade game charges the following prices depending on the length of time: 

  1. Up to 6 minutes costs Rs.10
  2. Over 6 and up to 15 minutes costs Rs.15
  3. Over 15 minutes costs Rs.15 plus Rs.1 per minute above 15 minutes

Represent this as a piecewise function and tell the price charged if Anil played the game for 13 minutes and Raju played for 20 minutes. 

Solution:

These kind of prices charges can be represented as, 

[Tex]f(t)= \begin{cases} 10, & \text{if } t\leq 6\\ 15 & \text{if } t \leq 15 \text{ and } t \gt 6 \\ 15 + 1(t – 15), & \text{otherwise} \end{cases} [/Tex]

at x = 13, f(13) = Rs.15 and x = 20, f(20 ) = 15 + 1( 20 – 15) = 20. 

Piecewise Continuous Function

A Piecewise Continuous Function is a function that is continuous across its entire domain i.e., each piece of the function is continuous itself and all the intersection points are the same for each piece so where each piece ends another piece of function starts from there in the graph.

An example of a Piecewise Continuous Function is given as follows:

[Tex]\bold{f(x) = \begin{cases} x^2,& x < 0\\ 2x,& x \geq 0\end{cases}} [/Tex]

This function is continuous across the entire domain because the limit of f(x) as x approaches 0 from the left (for x < 0) is equal to the limit of f(x) as x approaches 0 from the right (For x ≥ 0), and both limits are equal to 0. Therefore, f(x) is continuous at x = 0.

Piecewise Continuous Function Graph

A Piecewise Continuous Function Graph is given below. The graph of a piecewise continuous function often resembles a series of connected segments, each representing the function’s behavior within a specific interval. At the points where intervals meet, the function may experience jumps, breaks, or other types of discontinuities.

[Tex]f(x) = \begin{cases} x+3, & x<-1\\ 2, & -1\leq x \leq 2 \\ x^2 – 2, & x>2 \end{cases} [/Tex]

Continuous Graph of Piecewise Function

Read more: Continuity of Functions

Let’s consider another example continuous piecewise function as follows:

[Tex]\bold{f(x) = \begin{cases} x^2,& x < -1\\ x + 1,& -1 \leq x < 0\\ x – 1,& 0 \leq x < 1 \\ -x,& x \geq 1 \end{cases}} [/Tex]

This function is continuous across the entire domain as  [Tex]\lim_{x\to-1} f(x), \lim_{x\to0} f(x), and \lim_{x\to1} f(x) [/Tex], all exists.

Piecewise Function Worksheet

1. Given the piecewise function f(x) = [Tex]f(x) = \begin{cases} x^2, & \text{if } x \leq 2 \\ 3x – 1, & \text{if } x > 2 \end{cases} [/Tex]. Find f(0)

2. Evaluate the piecewise function g(x) = [Tex]g(x) = \begin{cases} 2x + 1, & \text{if } x < 0 \\ x^2, & \text{if } x \geq 0 \end{cases} [/Tex] at x = 3.

3. Determine the domain of the piecewise function h(x) = [Tex]h(x) = \begin{cases} \sqrt{x}, & \text{if } x \geq 0 \\ \frac{1}{x}, & \text{if } x < 0 \end{cases} [/Tex]

4. Find the value of k(2) for the piecewise function k(x) = [Tex]k(x) = \begin{cases} x^3, & \text{if } x \leq 1 \\ x^2, & \text{if } x > 1 \end{cases} [/Tex]

5. Determine the range of the piecewise function n(x) = [Tex]n(x) = \begin{cases} x^2, & \text{if } x \leq 2 \\ 3, & \text{if } x > 2 \end{cases} [/Tex]

Piecewise Function – FAQs

Define the Piecewise function in Maths.

A Piecewise function is a function that is defined for different sequences of intervals differently.

How do you write a Piecewise Function?

To write peicewise function, we need to write expression for each defined domaine individually. Let’s consider an example as follows:

[Tex]\bold{f(x) = \begin{cases} 2x + 1,& \text{if } x < 0 \\ x^2,& \text{if } 0 ≤ x < 2 \\ 5,& \text{if } x ≥ 2 \end{cases}} [/Tex]

OR 

f(x) = 2x + 1, if x < 0
f(x) = x2, if 0 ≤ x < 2
f(x) = 5, if x ≥ 2

How to Graph a Piecewise Function?

To graph a peicewise function we need to plot the graph of each individual defined expression for given domain.

What is a Piecewise Continuous Function?

If the lower limit and the upper limit of successive sequence of function are same then a piecewise function is continuous. In other words, a piecewise function is continuous when the function is continuous in the entire domain of the given function.

What is a Differentiable Piecewise Function?

If the function is differentiable at all the boundary points as well in the entire domain, the piecewise function is called differentiable.

Give an Example of a Piecewise Linear Function.

[Tex]f(x) = \begin{cases} 2x + 3, & if ~x < 0 \\ -x + 5, & if ~0 \leq x \leq 3 \\ x – 3, & if ~x > 3\end{cases}[/Tex]

This is a piecewise linear function as its graph will be a straight line in all the three pieces.



Previous Article
Next Article

Similar Reads

Definite Integrals of Piecewise Functions
Imagine a graph with a function drawn on it, it can be a straight line or a curve or anything as long as it is a function. Now, this is just one function on the graph, can 2 functions simultaneously occur on the graph? Imagine two functions simultaneously occurring on the graph, say, a straight line and a curve, and the limits on the x-axis for whi
5 min read
Find the power function that the graph of f resembles for large values of |x|, given the function f(x) = (x + 6)2 (x - 2)2
Mathematics is not only about numbers but it is about dealing with different calculations involving numbers and variables. This is what basically known as Algebra. Algebra is defined as the representation of calculations involving mathematical expressions that consist of numbers, operators, and variables. Numbers can be from 0 to 9, operators are t
5 min read
Why independent judiciary is necessary to carry out this important function?
To provide justice and enforce laws in the country, it is important to have an independent judiciary. An independent judiciary simply means a kind of judicial system which is free from any type of external or internal influence. Only an independent judiciary can act freely in accordance with the constitutional laws and uphold justice and equality f
6 min read
Counting Boolean function with some variables
Prerequisite - Canonical and Standard Form In the below articles, we will see some varieties of problems with three variables. Statement-1: Counting the number of Boolean functions possible with two variables such that there are exactly two min terms. Explanation: As we already know that from two variables (a and b) four [Tex](2^2)[/Tex] numbers (0
5 min read
Class 11 NCERT Solutions- Chapter 3 Trigonometric Function - Exercise 3.3 | Set 2
Question 15: cot 4x (sin 5x + sin 3x) = cot x (sin 5x – sin 3x) Solution: Taking LHS in consideration, we get = cot 4x (sin 5x + sin 3x) =[Tex]\frac{cos \hspace{0.1cm}4x}{sin \hspace{0.1cm}4x} [/Tex](sin 5x + sin 3x) Using the identity, sin A + sin B = 2 sin[Tex]\mathbf{(\frac{A+B}{2})} [/Tex]cos[Tex]\mathbf{(\frac{A-B}{2})}[/Tex] =[Tex]\frac{cos \
6 min read
How to Insert a Function in Excel?
MS Excel has many inbuilt in functions that we can use in our formula. If you want to see all the functions by category choose Formulas Tab and then Insert Function. Then Insert function Dialog appears from which we can choose function. Some important functions of Excel by categories are: Text Functions Lower: Converts all characters in a given tex
4 min read
Difference between write() and writelines() function in Python
In Python, there are many functions for reading and writing files. Both reading and writing functions work on open files (files opened and linked via a file object). In this section, we are going to discuss the write functions to manipulate our data through files. write() functionThe write() function will write the content in the file without addin
2 min read
What is the Arctan Function in Trigonometry?
Trigonometry is a branch that deals with the evaluation of sides and angles of a right-angled triangle. The trigonometric operations involve the calculation for sides, angles, and trigonometric ratios. The trigonometric ratios are defined as the values of trigonometric functions which are derived from the ratios of sides and angles of the given tri
3 min read
SET ROWCOUNT Function in SQL Server
The ROWCOUNT Set Function causes the server to stop the query processing after the specified number of records is returned. One may limit the number of records returned by all subsequent SELECT statements within the session by using the keyword SET ROWCOUNT. Or we can say that this function causes Transact-SQL statements to stop processing when the
2 min read
How to find the Equation of a Quadratic Function?
A quadratic equation is defined as an algebraic equation second-degree equation with one unknown variable. The word quadratic is derived from the Latin word "quadratum" which means "square". The standard form of a quadratic equation is given as ax2 + bx + c = 0, where a, b are the coefficients and a≠0, c is a constant and x is the unknown variable.
6 min read
Meiosis - Definition, Stages, Function and Purpose
When a single cell divides into two or more cells, we say that cell division has occurred. The single cell that divides itself is known as a parent cell or parental cell. The resulting cells from the parent cell are known as daughter cells. A cell cycle can be defined as the sequence of events in which cell synthesizes the other constituents of cel
6 min read
What is Hemoglobin? Definition, Structure and Function
Hemoglobin is a two-way respiratory transporter, carrying oxygen from the lungs to the tissues and working with the return carry of carbon dioxide. In the blood vessel circulation, hemoglobin has a high affinity for oxygen and a low affinity for carbon dioxide, natural phosphates, and hydrogen and chloride ions. In the venous circulation, these ove
8 min read
How to make the Table of Values of a Linear Function?
In mathematics, a function defines a relationship between an independent variable and a dependent variable. In simple words, a function is a relationship between inputs and outputs in which each input is connected to exactly one output. If every element in set A has exactly one and only one image in set B, then the relation is said to be a function
7 min read
Cranial Nerves : Function, Anatomy and Location
Cranial Nerves: Function, Anatomy, and Location: Cranial nerves are a group of nerves that arises from the brain. Cranial nerves are mainly of two types of conducting nerves; cranial nerves which arise from the brain and spinal nerves which arises from the spinal cord. They are mainly part of the peripheral nervous system i.e. helps in the transmis
5 min read
Synapse | Anatomy, Function & Types
Synapse - Definition, Parts, Types: A synapse is a small space between two neurons, where nerve impulses are relayed through a neurotransmitter from the axon of a presynaptic (to send information) neuron to the dendrite of a postsynaptic (receive Information ) neuron. The term "synaptic cleft" or "synaptic gap" refers to it. A synapse is a point of
8 min read
Ceiling Function
Ceiling Function is an important function in mathematics that returns the smallest integer which is not smaller than the input decimal. It is usually expressed as a function of a variable and denoted either by f(x) or by ceil(x) or ⌈x⌉. Ceiling Function has applications in various fields such as physics, electronics, and AI due to which it becomes
7 min read
Rational Function
Rational Function is a type of function that is expressed as a fraction where both the numerator and denominator must be a polynomial and the denominator can never equal zero. Thus a rational function is similar to a fraction but the numerator and denominator are polynomial functions. In simple words, the rational function can be defined as the rat
12 min read
Cytoplasm - Structure and Function
Cytoplasm is a semi-fluid, gel-like substance found in all living cells, both prokaryotic and eukaryotic. It surrounds the cell's organelles and nucleus. It acts as the medium in which various cellular processes like protein synthesis, metabolism, and many chemical reactions take place. The cytoplasm contains water, ions, nutrients, and various mol
6 min read
Bijective Function
Bijective Function is a special type of function that represents the relationship between two sets in such a way that all elements in the domain have an image in the codomain and each element in the codomain has a pre-image in the domain. Bijective Function is also called one-to-one correspondence due to the relationship between domain and codomain
10 min read
Composition and Function of Lymph in Human
Composition and function of lymph are essential aspects of the body’s immune system. Lymph is a clear, watery fluid that primarily consists of white blood cells, proteins, and interstitial fluid from tissues. It plays a crucial role in supporting the immune system and maintaining fluid balance. The lymph comprises components such as Lymph plasma, L
6 min read
Skeletal System: Anatomy and Function, Diagram
The Skeletal system provides structural support, protects our internal organs, and facilitates movement. The skeletal system of humans is primarily formed by bones, cartilage, ligaments, and tendons. All these work together to form the structure of the human body. The skeletal system also takes part in the hormone regulation and storage of essentia
11 min read
Harmonic Function
Harmonic functions are one of the most important functions in complex analysis, as the study of any function for singularity as well residue we must check the harmonic nature of the function. For any function to be Harmonic, it should satisfy the lapalacian equation i.e., ∇2u = 0. In this article, we have provided a basic understanding of the conce
5 min read
Types and Function of Nutrients
Nutrients are organic molecules that are necessary for all organisms to grow, make energy, develop, and reproduce. They are broadly classified into two; macronutrients and micronutrients. Nutrients that are needed in large quantities are called macronutrients and the nutrients needed in smaller quantities are micronutrients. Nutrients are the found
7 min read
Microtubules: Structure & Function
Microtubules are small polymerized tubular structures made up of tubulin proteins. Microtubules, microfilaments, and intermediate filaments are the important parts of the cytoskeleton. Microtubule is an important component of cell structure in plant and animal cells. It plays a major role in the functions of a variety of processes including cell di
6 min read
Apical Meristem: Meaning and Function
The apical meristem is a group of cells that can divide and help in primary growth. These cells are found at the tips of growing roots and shoots. The apical meristems create the main parts of the plant and make the roots and shoots longer. The apical meristem is located at the root tip, shoot tip, and the tip of the leaves. The meristematic cell c
5 min read
Fibrous Joints - Examples, Diagram, Function & Movement of Joint
Fibrous Joints are joints formed by fibrous tissue, like collagen. These are also called fixed or immobile joints as there is no movement. The hard tissue with a lot of collagen fibers connects the fibrous joints. There are different types of fibrous joints such as sutures, fontanelles, synostosis, syndesmoses, etc. The skull is the best example of
5 min read
Thyroid Gland - Anatomy, Function and Clinical Aspects
The thyroid organ is an endocrine organ that is situated in the front piece of the lower neck, underneath the larynx (voice box). The thyroid secretes chemicals fundamental to digestion and development. Any development of the thyroid, paying little mind to the cause, is known as a goiter. Life systems of the thyroid organ The thyroid emerges from a
14 min read
Areolar Connective Tissue | Function and Location
Areolar connective tissue is a loose connective tissue found throughout the body. It contains fibroblasts, collagen, and elastic fibers within a gel-like matrix. It is located under the skin, around organs, blood vessels, and nerves. It supports organs, cushions them, facilitates nutrient exchange, defends against infections, aids in wound healing,
6 min read
Autocrine Signaling: Definition, Function & Example
Autocrine Signaling is a cell signaling process in the human body. Signaling is the process that will help to comminate one cell with another. There are several cell signaling processes are present in the human body. Among them, Autocrine Signaling is a separate cell signaling process. Often a cell sends signals to other cells, that cell might pres
8 min read
Synaptic Cleft- Anatomy, Structure, Disease & Function
Synaptic Cleft: The neurons are the functional units of the nervous system which transmit electrical impulses from one neuron to the other. The space between the two neurons across the impulse which is transmitted by a neurotransmitter is called the synaptic cleft. The synaptic cleft is also known as the synaptic gap. It is important for the cells
4 min read