Mathwords logoReference LibraryMathwords

Piecewise Linear Function

A piecewise linear function is a function built from two or more straight-line segments, each applying to a specific interval of the domain. The formula changes from one interval to the next, but every piece is a linear expression.

A piecewise linear function is defined by a set of linear expressions fi(x)=mix+bif_i(x) = m_i x + b_i, each valid on a distinct interval of the domain. The overall function f(x)f(x) switches between these expressions at specified boundary points. The graph consists entirely of line segments (or rays), though the segments may or may not connect at the boundary points.

Key Formula

f(x)={m1x+b1,x<c1m2x+b2,c1x<c2m3x+b3,xc2f(x) = \begin{cases} m_1 x + b_1, & x < c_1 \\ m_2 x + b_2, & c_1 \le x < c_2 \\ m_3 x + b_3, & x \ge c_2 \end{cases}
Where:
  • mim_i = the slope of the line segment on the $i$-th interval
  • bib_i = the y-intercept of the linear expression on the $i$-th interval
  • c1,c2c_1, c_2 = the boundary points where the function switches between expressions

Worked Example

Problem: Evaluate the piecewise linear function at x=1x = -1, x=2x = 2, and x=5x = 5: f(x)={x+4,x<12x+7,1x3x2,x>3f(x) = \begin{cases} x + 4, & x < 1 \\ -2x + 7, & 1 \le x \le 3 \\ x - 2, & x > 3 \end{cases}
Step 1: For x=1x = -1: since 1<1-1 < 1, use the first piece.
f(1)=(1)+4=3f(-1) = (-1) + 4 = 3
Step 2: For x=2x = 2: since 1231 \le 2 \le 3, use the second piece.
f(2)=2(2)+7=3f(2) = -2(2) + 7 = 3
Step 3: For x=5x = 5: since 5>35 > 3, use the third piece.
f(5)=52=3f(5) = 5 - 2 = 3
Step 4: Check continuity at the boundary points. At x=1x = 1: the first piece gives 1+4=51 + 4 = 5, and the second piece gives 2(1)+7=5-2(1) + 7 = 5. They match, so the function is continuous there. At x=3x = 3: the second piece gives 2(3)+7=1-2(3) + 7 = 1, and the third piece gives 32=13 - 2 = 1. They match as well.
Answer: f(1)=3f(-1) = 3, f(2)=3f(2) = 3, and f(5)=3f(5) = 3. The function is continuous at both boundary points.

Visualization

Why It Matters

Piecewise linear functions model situations where a rate changes abruptly. Tax brackets, for instance, apply different rates to different income ranges — each bracket is a separate linear segment. In data science and computer graphics, smooth curves are often approximated by chains of short line segments, which is exactly what a piecewise linear function describes.

Common Mistakes

Mistake: Using the wrong piece for a boundary point
Correction: Pay close attention to whether each interval uses << or \le. The inequality symbols tell you exactly which formula applies at the boundary. Only one piece should cover each boundary value.
Mistake: Assuming the function must be continuous
Correction: Piecewise linear functions can have jumps. The segments do not have to connect at boundary points — always check by plugging the boundary value into both adjacent pieces.

Related Terms

  • Piecewise FunctionGeneral category that includes nonlinear pieces
  • LinearEach individual piece is a linear expression
  • Step FunctionSpecial case where each piece is a constant