Ma · Mathematics

How to Differentiate a Piecewise Function

Published By the 9to5Science editorial team

At a glance

  1. 1. Differentiate each piece

    Apply the usual derivative rules separately on each interval where the formula is fixed.

  2. 2. Find the breakpoints

    Check every point where the defining formula or interval changes.

  3. 3. Test continuity

    At each breakpoint, compare the function value with the left- and right-hand limits.

  4. 4. Compare slopes

    If the function is continuous, compare the one-sided derivatives; they must agree for a derivative to exist.

A piecewise function can have a different formula on each part of its domain. To differentiate it, first differentiate each formula where that formula applies. Then check the points where the formula changes: a piecewise function may have a derivative everywhere inside its intervals but fail to be differentiable at a breakpoint.

The key test is local. At a breakpoint, the function must be continuous, and the slopes approaching from the left and right must agree. If either requirement fails, there is no derivative at that point.

Differentiate inside each interval

Suppose a function is defined by

f(x)={f1(x),x<c,f2(x),x≥c.f(x)=\begin{cases} f_1(x), & x<c,\\ f_2(x), & x\ge c. \end{cases}

For points strictly less than cc, differentiate f1f_1. For points strictly greater than cc, differentiate f2f_2. These ordinary derivative rules apply on each interval independently. The breakpoint x=cx=c needs its own check; it is not automatically covered by either formula for the derivative.

For instance, if f(x)=x2f(x)=x^2 for x<1x<1 and f(x)=3xf(x)=3x for x≥1x\ge 1, the derivatives away from 11 are 2x2x and 33, respectively. This gives the derivative on the two open intervals, but does not yet determine whether f′(1)f'(1) exists.

Check differentiability at a breakpoint

The derivative at cc is defined by the difference quotient

f′(c)=lim⁡h→0f(c+h)−f(c)h,f'(c)=\lim_{h\to 0}\frac{f(c+h)-f(c)}{h},

if this limit exists. A two-sided limit exists only if the corresponding one-sided limits both exist and are equal.

A practical test is:

  1. Find f(c)f(c) using the piece that includes cc.
  2. Check whether the left- and right-hand limits of f(x)f(x) at cc equal f(c)f(c). This is continuity at cc.
  3. Find the left-hand and right-hand limits of the difference quotient, or compute the one-sided derivatives using the adjacent formulas.
  4. Conclude that f′(c)f'(c) exists only if both one-sided derivatives are finite and equal.

Continuity is necessary but not sufficient. A graph can meet at a point and still have a corner there, giving different one-sided slopes. Conversely, if a function is discontinuous at cc, it cannot be differentiable there.

Worked example: a matching join

Consider

f(x)={x2,x≤1,2x−1,x>1.f(x)=\begin{cases} x^2, & x\le 1,\\ 2x-1, & x>1. \end{cases}

For x<1x<1, f′(x)=2xf'(x)=2x. For x>1x>1, f′(x)=2f'(x)=2. Now check the join. The function value is f(1)=12=1f(1)=1^2=1. The left-hand limit is 11, and the right-hand limit is 2(1)−1=12(1)-1=1, so the function is continuous.

The one-sided slopes are

f−′(1)=2x∣x=1=2,f+′(1)=2=2.f'_-(1)=\left.2x\right|_{x=1}=2, \qquad f'_+(1)=\left.2\right.=2.

They agree, so f′(1)=2f'(1)=2. The full derivative can therefore be written as

f′(x)={2x,x<1,2,x≥1.f'(x)=\begin{cases} 2x, & x<1,\\ 2, & x\ge 1. \end{cases}

The choice of which interval includes 11 in this derivative notation is just a way to state the value there; the derivative at 11 was established by checking both sides.

Worked example: a corner

For g(x)=∣x∣g(x)=|x|, write the function as

g(x)={−x,x<0,x,x≥0.g(x)=\begin{cases} -x, & x<0,\\ x, & x\ge 0. \end{cases}

The function is continuous at 00, since both pieces approach 00. But the derivative from the left is −1-1, while the derivative from the right is 11. Since these slopes differ, g′(0)g'(0) does not exist. Away from 00, its derivative is −1-1 for x<0x<0 and 11 for x>0x>0.

A jump gives another reason a derivative can fail to exist. For example, if the left and right formulas approach different values at a breakpoint, the function is discontinuous there, so there is no derivative at that point.

Common mistakes

  • Only differentiating the formulas: This finds the derivative away from the breakpoints, not necessarily at them.
  • Checking only continuity: A continuous join can still have a corner, as ∣x∣|x| does at 00.
  • Comparing formula values instead of limits: At a breakpoint, use the value assigned by the definition for f(c)f(c), and separately check the limits from both sides.
  • Assuming a piecewise derivative automatically includes the breakpoint: A displayed derivative formula at cc is valid only after the derivative has been shown to exist there.
  • Ignoring domain endpoints: If cc is an endpoint of the function’s domain, the usual two-sided derivative is not defined there. Some contexts define a one-sided derivative instead, so state which convention is being used.

For a piecewise function with several pieces, repeat the breakpoint test at every point where the formula changes. A derivative can exist at some joins and fail at others.

References

  1. Calculus: Early Transcendentals — James Stewart, Daniel Clegg, and Saleem Watson

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.