---
title: Domain, range and piecewise functions
heading: An amplifier that runs out of room
eyebrow: A2 · Lesson 2 · Domain, range and piecewise functions
xp: 40
---

::: hook
Feed a small signal into an amplifier and the output is the input times the gain. Turn the input up and at some point the output stops growing, because it can't go beyond the supply voltage. The graph of output against input is a straight line in the middle with flat shelves on each side. No single formula like $y = gx$ describes it. It's a function defined in pieces, and many real circuits (rectifiers, limiters, switches) are like that.

::: play
- The graph shows an amplifier's output against its input. The dashed line is what the gain alone would give.
- Raise the gain $g$. Where do the flat shelves start now?
- Lower the limit $L$, the most the output can swing. How wide is the range of inputs that come out undistorted?
:::
:::

```sim plot
view: graph
x: x = -5..5 V
y: y = -14..14 V
slider: g = 0.5..10 = 3
slider: L = 1..12 = 9 V
plot: g*x | dashed | color: ch2 | label: gain alone
plot: (abs(g*x + L) - abs(g*x - L))/2 | label: output
marker: x = L/g | label: clipping starts
marker: x = -L/g
readout: undistorted inputs, up to ± = L/g V | digits: 3
```

::: predict
## The amplifier has a gain of 3 and its output can't go beyond ±9 V. What does it put out for an input of 4 V?

- [ ] 12 V
- [x] 9 V
- [ ] 4 V
- [ ] 0 V

::: reveal
9 V. The gain alone would ask for 12 V, but the output stops at its limit. Inputs up to $9/3 = 3$ V come through amplified; anything bigger lands on the shelf. To use a piecewise function, first decide which piece the input falls in.
:::
:::

::: nameit
## Where a formula works, and what it can give

The **domain** of a function is the set of inputs it accepts. A formula rules some inputs out:
- **Division:** the bottom can't be zero. $\dfrac{1}{x - 2}$ accepts every $x$ except 2.
- **Even roots:** what's under a square root can't be negative. $\sqrt{4 - x^2}$ needs $x^2 \le 4$, so $-2 \le x \le 2$.
- **Logarithms:** the argument must be positive. $\ln(x - 1)$ needs $x > 1$.

Physics often narrows the domain further: a resistance can't be negative, and time after a switch closes starts at $t = 0$.

The **range** is the set of outputs. $x^2$ gives only values $\ge 0$; $e^x$ gives only positive values; $\sin x$ stays between −1 and 1. Reading the range off a graph means looking at how high and how low the curve goes.

## Functions in pieces

A **piecewise function** uses different formulas on different parts of its domain:

$$y = \begin{cases} -L & gx \le -L \\ gx & -L < gx < L \\ L & gx \ge L \end{cases}$$

That's the clipping amplifier above. Its linear range is $|x| < L/g$. To evaluate a piecewise function, find the piece whose condition the input meets, then use only that piece's formula.

Three piecewise functions appear all through electrical engineering:
- **Absolute value:** $|x| = x$ for $x \ge 0$ and $-x$ for $x < 0$. It's the distance from zero, and $|x - a|$ is the distance from $a$.
- **The unit step:** $u(t) = 0$ for $t < 0$ and $1$ for $t \ge 0$. It's a switch closing at $t = 0$; $u(t - 2)$ closes at $t = 2$.
- **The ideal rectifier:** passes positive inputs and blocks negative ones, $y = x$ for $x > 0$ and $0$ otherwise. In one formula, $y = \frac{1}{2}(x + |x|)$.

Where two pieces meet, they may join (the clipper's shelves meet its slope) or jump (the step leaps from 0 to 1). A jump in a graph means something changed instantly, which in a circuit is an idealization: real switches take some time.
:::

::: example
## What is the domain of $f(x) = \dfrac{\sqrt{x - 1}}{x - 3}$?

::: solution
1. **Condition from the square root.** It needs $x - 1 \ge 0$, so $x \ge 1$.
2. **Condition from the bottom.** It can't be zero, so $x \ne 3$.
3. **Combine them.** Both must hold: $x \ge 1$ with $x = 3$ removed. Written as intervals,
   $$[1, 3) \cup (3, \infty)$$

**Answer:** the domain is every $x \ge 1$ except $x = 3$, which is $[1, 3) \cup (3, \infty)$.
:::
:::

::: example
## A silicon diode rectifier passes nothing until the input reaches 0.7 V, then follows the input 0.7 V lower. Write its output as a piecewise function, and find the output when the input is 5 V and when it's 0.5 V.

::: solution
1. **Write the two pieces.**
   $$y = \begin{cases} 0 & x \le 0.7 \\ x - 0.7 & x > 0.7 \end{cases}$$
2. **Input of 5 V.** It's above 0.7 V, so use the second piece:
   $$\begin{aligned} y &= 5 - 0.7 \\ &= 4.3\ \text{V} \end{aligned}$$
3. **Input of 0.5 V.** The first piece applies, so $y = 0$.
4. **Where the pieces meet.** At $x = 0.7$ both give 0, so the graph has a corner there and no jump.

**Answer:** the output is 0 up to 0.7 V and $x - 0.7$ above it, so 5 V in gives 4.3 V out, and 0.5 V in gives 0.
:::
:::

::: example
## An amplifier with a gain of 10 runs from ±12 V supplies and can't swing past them. Write its output as a piecewise function of the input, give its range, and find the output for inputs of 0.5 V and 2 V.

::: solution
1. **Find where it clips.** The output follows $10x$ until that would pass a rail, which happens at $x = \pm 1.2$ V.
2. **Write the pieces.**
   $$v_\text{out}(x) = \begin{cases} -12 & x \le -1.2 \\ 10x & -1.2 < x < 1.2 \\ 12 & x \ge 1.2 \end{cases}$$
3. **Domain and range.** The domain is every input, and the range is $[-12, 12]$ V.
4. **Input of 0.5 V.** It's inside the linear piece, so it gives
   $$10 \times 0.5 = 5\ \text{V}$$
5. **Input of 2 V.** It's past the corner, so the output sits at 12 V, and a sine wave that big comes out with its tops flattened.

**Answer:** the output is −12 V below an input of −1.2 V, $10x$ in between, and 12 V above 1.2 V. Its range is $[-12, 12]$ V; 0.5 V in gives 5 V out, and 2 V in gives 12 V.
:::
:::

::: check
given: g = 5 | 10; L = 3 | 5; x = 1.5 | 2 | 4
answer: L
unit: V

## An amplifier with a gain of {g} can't put out more than ±{L} V. What is its output for an input of {x} V?

::: right
Right. The gain alone would ask for $\given{g} \times \given{x}$ V, beyond the limit, so the output sits at {L} V.
:::

::: misses
- [g*x] That's the gain alone. The output can't go beyond ±{L} V.
- [x] The amplifier still has gain. Find which piece the input falls in.
- [any] Not yet. Check whether $\given{g} \times \given{x}$ is inside the limit first.
:::
:::

::: check
given: g = 2 | 5 | 10 | 20; L = 3 | 5 | 12
answer: L/g
unit: V

## An amplifier with a gain of {g} clips at ±{L} V. Up to what input voltage does it amplify without clipping?

::: right
Right. Clipping starts where $\given{g}x = \given{L}$, at $x$ = {answer}.
:::

::: misses
- [L*g] That's the output the gain would give for an input of {L} V. Solve $\given{g}x = \given{L}$ for the input.
- [L] That's the output limit. The input that reaches it is smaller by the gain.
- [any] Not yet. The output reaches the limit when $\given{g}x = \given{L}$.
:::
:::

::: check
kind: choice

## What is the domain of $\sqrt{9 - x^2}$?

- [ ] $x \le 3$
- [x] $-3 \le x \le 3$
- [ ] $x \ge -3$
- [ ] Every real number

::: right
Right. The root needs $9 - x^2 \ge 0$, so $x^2 \le 9$, which holds from −3 to 3.
:::

::: misses
- [1] For $x = -5$, $9 - 25$ is negative. Large negative numbers fail too, since $x^2$ is positive.
- [any] Find where $9 - x^2$ is zero or positive.
:::
:::

::: check
given: k = 2 | 9 | 16 | 25
answer: sqrt(k)

## $f(x) = \dfrac{1}{x^2 - \given{k}}$. At what positive $x$ is $f$ undefined?

::: right
Right. The bottom is zero when $x^2 = \given{k}$, at $x = \pm$ {answer}.
:::

::: misses
- [k] Set the bottom to zero: $x^2 = \given{k}$, then take the square root.
- [k/2] Solve $x^2 = \given{k}$ for $x$.
- [any] Not yet. Find where the bottom is zero.
:::
:::

::: check
given: x = -3 | -2 | 0.5 | 2 | 3 | 4
answer: x^2*(1 - step(x - 1)) + (2*x - 1)*step(x - 1)
tolerance: 0.5%

## $f(x) = x^2$ for $x < 1$, and $f(x) = 2x - 1$ for $x \ge 1$. What is $f(\given{x})$?

::: right
Right. {x} falls in the piece where {answer} comes out.
:::

::: misses
- [(2*x - 1)*(1 - step(x - 1)) + x^2*step(x - 1)] That's the other piece's formula. Check which condition {x} meets first.
- [any] Not yet. Decide whether {x} is below 1 or not, then use that piece only.
:::
:::

::: check
given: a = 1 | 2 | 3 | 5; b = 2 | 4 | 7
answer: a + b

## $|x - \given{a}| = \given{b}$ has two solutions. What is the larger one?

::: right
Right. $x$ is {b} away from {a}, so it's $\given{a} + \given{b}$ or $\given{a} - \given{b}$. The larger is {answer}.
:::

::: misses
- [a - b] That's the smaller solution.
- [b] That's the distance. Measure it from {a}.
- [any] $|x - \given{a}|$ is the distance from $x$ to {a}.
:::
:::

::: check
kind: choice

## A switch is closed at $t$ = 2 s, connecting a 5 V source. Which describes the voltage?

- [ ] $5\,u(t + 2)$
- [x] $5\,u(t - 2)$
- [ ] $u(5t - 2)$
- [ ] $5 + u(t - 2)$

::: right
Right. $u(t - 2)$ is 0 until $t - 2$ reaches 0, at $t = 2$, and multiplying by 5 makes the jump 5 V.
:::

::: misses
- [1] $u(t + 2)$ switches at $t = -2$, before time zero. Set the inside to zero to find the switching time.
- [4] That would sit at 5 V before the switch and jump to 6 V.
- [any] The step switches where its argument becomes zero.
:::
:::

::: check
kind: parts
given: p1 = 12 | 15; p2 = 20 | 25; E1 = 300 | 500; E = 700 | 900

## Electricity costs {p1} cents per kWh for the first {E1} kWh in a month and {p2} cents for every kWh after that.

::: part
answer: (p1*E1 + p2*(E - E1))/100
tolerance: 0.5%

### What is the bill, in dollars, for a month that uses {E} kWh?

::: misses
- [p2*E/100] Only the energy above {E1} kWh is charged at the higher rate.
- [p1*E/100] The energy above {E1} kWh costs {p2} cents.
- [any] Two pieces: {E1} kWh at {p1} cents, and the rest at {p2} cents.
:::
:::

::: part
answer: (p1*E1 + p2*(E - E1))/E
tolerance: 0.5%

### What is the average price that month, in cents per kWh?

::: misses
- [(p1 + p2)/2] That would be true only if the two pieces were the same size. Divide the bill by the energy.
- [any] The bill in cents divided by {E} kWh.
:::
:::

::: part
answer: E1 + 5000/p2
tolerance: 0.5%

### How many kWh make the bill exactly 50 dollars more than the bill for {E1} kWh?

::: misses
- [E1 + 5000/p1] Past {E1} kWh, each one costs {p2} cents.
- [5000/p2] That's only the energy past {E1} kWh. Add the first piece back.
- [any] Past {E1} kWh, 5000 cents buys $5000/\given{p2}$ kWh.
:::
:::
:::

::: check
kind: derivation
vars: g = 2..50, L = 1..15

## An amplifier with gain $g$ clips at $\pm L$. Derive where its linear piece ends.

::: step
answer: L/g

### At what input does the output first reach $+L$?

::: misses
- [L*g] The output is $g$ times the input, so divide.
:::
:::

::: step
answer: -L/g

### At what input does it reach $-L$?
:::

::: step
answer: 2*L/g

### How wide is the range of inputs that come out undistorted?
:::

::: right
Right. The linear piece runs from $-L/g$ to $L/g$, a span of $2L/g$: more gain means a narrower window before clipping.
:::
:::

::: explain
## Why does the graph of an amplifier's output against its input have to be piecewise, and what sets where the pieces change?

::: model
An amplifier makes its output out of its power supply, so the output can't swing beyond the supply's voltages. For small inputs the output is the gain times the input, a straight line. Once that product would pass the limit, the output stays at the limit, a flat piece. The change happens where the gain times the input equals the limit, so a bigger gain or a smaller supply makes the straight part narrower.
:::
:::

::: practice

::: check
given: a = 1 | 2 | 3 | 7
answer: a

## $f(x) = \ln(x - \given{a})$. Its domain is $x > c$. What is $c$?

::: misses
- [-a] The logarithm needs $x - \given{a} > 0$, so $x > \given{a}$.
- [any] Solve $x - \given{a} > 0$.
:::
:::

::: check
given: a = 4 | 9 | 16 | 25 | 36
answer: sqrt(a)

## $f(x) = \sqrt{\given{a} - x^2}$. What is the largest $x$ in its domain?

::: misses
- [a] Solve $x^2 \le \given{a}$: take the square root.
- [any] The root needs $\given{a} - x^2 \ge 0$.
:::
:::

::: check
given: g = 4 | 8 | 20; L = 2 | 6 | 10; x = 0.05 | 0.08
answer: g*x
unit: V

## An amplifier with a gain of {g} clips at ±{L} V. What is its output for an input of {x} V?

::: misses
- [L] Check first: $\given{g} \times \given{x}$ is inside the limit, so it isn't clipped.
- [any] Is $\given{g} \times \given{x}$ inside ±{L}? Then that's the output.
:::
:::

::: check
given: g = 3 | 6 | 15 | 50; L = 4 | 9 | 13
answer: L/g
unit: V

## A gain-of-{g} amplifier clips at ±{L} V. What is the largest input it passes undistorted?

::: misses
- [L*g] Divide the limit by the gain.
- [L] That's the output limit.
- [any] Solve $\given{g}x = \given{L}$.
:::
:::

::: check
given: x = -2 | -0.5 | 0.5 | 1.5 | 3; c = 1 | 2
answer: x*(1 - step(x - c)) + c*step(x - c)
tolerance: 0.5%

## $f(x) = x$ for $x < \given{c}$, and $f(x) = \given{c}$ for $x \ge \given{c}$. What is $f(\given{x})$?

::: misses
- [c*(1 - step(x - c)) + x*step(x - c)] That's the other piece. Compare {x} with {c} first.
- [any] Decide which piece {x} falls in.
:::
:::

::: check
given: v = -4 | -1 | 0.5 | 2 | 5 | 9
answer: (v - 0.7)*step(v - 0.7)
tolerance: 0.01

## A diode rectifier puts out 0 for inputs up to 0.7 V and the input minus 0.7 V above that. What is its output for {v} V?

::: misses
- [v] Above 0.7 V the output is 0.7 V lower than the input.
- [any] Decide whether {v} V is above 0.7 V, then use that piece.
:::
:::

::: check
given: a = 2 | 3 | 6; b = 1 | 5 | 8
answer: a - b

## What is the smaller solution of $|x - \given{a}| = \given{b}$?

::: misses
- [a + b] That's the larger one.
- [any] The solutions are {b} either side of {a}.
:::
:::
:::
