Sub topic 12
Piecewise Functions and Their Domains
Prerequisites and the basic idea
Assume you can solve linear inequalities, use interval notation, and evaluate ordinary functions. A piecewise function is a function defined by different formulas on different parts of its domain. Each input uses exactly one formula, determined by a condition.
For example,
\[ f(x)= \begin{cases} x+2, & x<1\\ x^2, & x\ge 1 \end{cases} \]
has two rules:
- Use \(x+2\) when \(x<1\).
- Use \(x^2\) when \(x\ge 1\).
The conditions must describe which inputs belong to each piece. They should not overlap in a way that gives one input two possible outputs.
Evaluating a piecewise function
To evaluate a piecewise function, first determine which condition contains the input. Then use only the formula attached to that condition.
For the function above:
- Since \(0<1\), \(f(0)=0+2=2\).
- Since \(3\ge1\), \(f(3)=3^2=9\).
- Since \(1\ge1\), \(f(1)=1^2=1\).
The endpoint \(x=1\) belongs to the second piece because its condition uses \(\ge\). The first piece does not include 1 because it uses \(<\).
def f(x):
if x < 1:
return x + 2
else:
return x ** 2
print(f(0)) # 2
print(f(1)) # 1
print(f(3)) # 9A computer program often uses if, elif, and else to represent the conditions. The order matters when conditions overlap, so write the conditions carefully.
Finding the domain
The domain is the set of inputs for which the function has a defined output. For a piecewise function, find the domain covered by every condition, then combine those sets.
Consider
\[ g(x)= \begin{cases} \sqrt{x+4}, & -4\le x<2\\ \dfrac{1}{x-2}, & x>2 \end{cases} \]
The first formula is defined on the interval \([-4,2)\), as stated by its condition. The second formula is defined on \((2,\infty)\). Therefore,
\[ \text{Domain of }g=[-4,2)\cup(2,\infty). \]
The value \(x=2\) is excluded from both pieces. It is excluded from the first condition because that condition says \(x<2\), and it is excluded from the second because that condition says \(x>2\). The second formula would also be undefined at \(x=2\) because its denominator would be zero.
| Piece | Condition | Domain contribution |
|---|---|---|
| \(\sqrt{x+4}\) | \(-4\le x<2\) | \([-4,2)\) |
| \(\frac{1}{x-2}\) | \(x>2\) | \((2,\infty)\) |
If a condition does not fully state the restrictions of its formula, check those restrictions separately. For instance, \(\sqrt{x-1}\) requires \(x\ge1\), even if its listed condition is wider.
Graphs and boundary points
On a graph, each piece is drawn only over its stated input interval. Use a closed dot when an endpoint is included and an open dot when it is excluded.
For
\[ h(x)= \begin{cases} 2x+1, & x\le0\\ x-2, & x>0 \end{cases} \]
the first line ends at \((0,1)\) with a closed dot. The second line begins at \((0,-2)\) with an open dot. The function has one output for \(x=0\), namely \(h(0)=1\).
The graph can have a jump at a boundary and still represent a function. Continuity is a separate property. A piecewise function only needs to assign one output to each input in its domain.
Exercise
Let p(x) = { 3 - x for x < 2; x^2 for x ≥ 2 }. Find p(2), p(5), and the domain of p.
Show answer
Because 2 ≥ 2, p(2) = 2^2 = 4. Because 5 ≥ 2, p(5) = 5^2 = 25. The conditions cover every real number, so the domain is (-∞, ∞).