Tutorials › Calculus I › A Worked Riemann-Sum Integral for a Piecewise Function

Riemann Sums and the Integral · Tutorial 969 of 1495

A Worked Riemann-Sum Integral for a Piecewise Function

Learn to build and evaluate tagged-sum limits for piecewise functions, including how breakpoint values and signed contributions affect the calculation.

Intermediate 9 min read

What You'll Learn

  • Define a tagged partition and its Riemann sum.
  • Set up subdivisions aligned with piecewise-function breakpoints.
  • Track how interval widths and tag choices enter each sum.
  • Evaluate signed contributions from different pieces.
  • Account for tags that land exactly at a breakpoint.
  • Check a limiting integral by examining the component sums.

From a Piecewise Formula to a Tagged Sum

A definite integral can be computed directly from the limit of tagged sums. For a piecewise function, the main work is to keep track of which formula applies on each subinterval, how wide that subinterval is, and whether its contribution is positive or negative.

Breakpoints deserve particular care. A partition can be chosen to include them, so each small interval lies within one piece. A tag can still land exactly on a breakpoint, however, where the function may take the value from a neighboring piece. We will account for that possibility explicitly.

Definition: A tagged partition of \([a,b]\) consists of partition points \(a=x_0<x_1<\cdots<x_N=b\) and tags \(\xi_i\in[x_{i-1},x_i]\). Its Riemann sum for \(f\) is \(\sum_{i=1}^{N} f(\xi_i)(x_i-x_{i-1})\). The mesh is the largest subinterval width. If the tagged sums approach one common limit as the mesh tends to zero, \(f\) is Riemann integrable and that limit is \(\int_a^b f(x)\,dx\).

Each term is a function value multiplied by a width. Omitting the width changes the quantity being calculated. For a piecewise function, it is useful to form separate sums over the pieces, while remembering that all the terms together make up the original tagged sum.

A Piecewise Function with Three Contributions

Consider the bounded function \(f:[0,3]\to\mathbb{R}\) defined by

$$ f(x)= \begin{cases} x, & 0\le x<1,\\ -2, & 1\le x<2,\\ 2-x, & 2\le x\le 3. \end{cases} $$

The breakpoints are \(1\) and \(2\). The first piece is nonnegative, the middle piece is negative, and the last piece is nonpositive. Divide each unit interval into \(m\) equal subintervals. Every subinterval then has width \(\Delta x=1/m\), and the mesh is \(1/m\), which tends to zero as \(m\) increases.

Worked Example: Evaluating the tagged-sum limit

On the first unit interval, write the tags as \(\xi_i=(i-1+\alpha_i)/m\), where \(0\le\alpha_i\le1\), for \(i=1,\ldots,m\). If no tag is the right endpoint \(1\), the first piece contributes

$$ \frac{1}{m}\sum_{i=1}^{m}\xi_i = \frac{1}{m^2}\sum_{i=1}^{m}(i-1+\alpha_i) = \frac{m-1}{2m}+\frac{1}{m^2}\sum_{i=1}^{m}\alpha_i. $$

Here \(\sum_{i=1}^{m}(i-1)=m(m-1)/2\), and \(0\le\sum\alpha_i\le m\). Therefore this expression lies between \((m-1)/(2m)\) and \((m+1)/(2m)\), and tends to \(1/2\). If the last tag is \(1\), the actual value is \(f(1)=-2\), rather than the first-piece value \(1\). That one term changes the sum by \((-2-1)/m=-3/m\), which also tends to zero. Thus the first piece contributes a limit of \(1/2\) for any permitted tags.

Every tag in the middle interval has function value \(-2\), except that a tag at its right endpoint \(2\) has value \(f(2)=0\). The middle contribution is therefore \(-2\), possibly with a correction of \(2/m\) if a tag equals \(2\). Its limit is \(-2\).

For the last interval, write the tags as \(\zeta_i=2+(i-1+\gamma_i)/m\), where \(0\le\gamma_i\le1\). The formula \(f(x)=2-x\) applies even at \(2\), so its contribution is

$$ \frac{1}{m}\sum_{i=1}^{m}(2-\zeta_i) = -\frac{m-1}{2m}-\frac{1}{m^2}\sum_{i=1}^{m}\gamma_i. $$

Since \(0\le\sum\gamma_i\le m\), this lies between \(-(m+1)/(2m)\) and \(-(m-1)/(2m)\), and tends to \(-1/2\). Combining the three limits gives

$$ \int_0^3 f(x)\,dx = \frac12-2-\frac12 = -2. $$

As a check, the first and last contributions cancel, leaving the middle contribution \(-2\). The possible breakpoint corrections have size at most \(3/m\) and \(2/m\), so they vanish as the mesh shrinks.

Why the Limit Does Not Depend on the Tags

The calculation illustrates the key reason this method works. On each linear piece, the function values change gradually across a subinterval, so changing a tag changes its contribution by an amount controlled by the subinterval width. For a constant piece, changing the tag within the piece does not change the function value at all. There are only finitely many breakpoints, and a tag at one of them affects at most a term whose width tends to zero.

For the first piece above, the tag-dependent part of the sum is \(\sum\alpha_i/m^2\), which is between \(0\) and \(1/m\). The final piece has an analogous bound. These estimates show directly that different tag choices cannot change the limiting contributions. The exceptional endpoint changes also tend to zero. This gives a complete justification for the tagged-sum limit in the example, rather than relying only on a geometric estimate.

Takeaway: For a bounded piecewise function with finitely many pieces, align the partition with the breakpoints when convenient, compute each piece’s contribution with its own formula, and check that any exceptional terms at breakpoints vanish as the mesh shrinks.

A Step Function and an Endpoint Tag

A step function makes the width factor especially visible. Consider \(g:[0,2]\to\mathbb{R}\) given by \(g(x)=3\) for \(0\le x<1\) and \(g(x)=-1\) for \(1\le x\le2\). Divide each unit interval into \(n\) equal parts, so each width is \(1/n\).

Worked Example: A jump and its breakpoint value

If all tags in the first unit interval lie below \(1\), its contribution is \(n\) terms, each equal to \(3(1/n)\), giving \(3\). If the last tag equals \(1\), its function value is instead \(-1\), so that term is \(-1/n\) rather than \(3/n\). The first-interval sum is then \(3-4/n\).

All tags in the second unit interval have function value \(-1\), including a tag at \(2\). Its contribution is \(n(-1/n)=-1\). Thus the complete tagged sum is either \(3-1=2\), or \(3-4/n-1=2-4/n\), depending on the endpoint tag. Both possibilities tend to \(2\). Therefore

$$ \int_0^2 g(x)\,dx=2. $$

The check is the signed total: the positive piece contributes \(3\), the negative piece contributes \(-1\), and their sum is \(2\). The jump value at the single breakpoint can alter one term, but only by \(4/n\), which vanishes.

Midpoint Tags on Linear Pieces

Midpoint tags can make a calculation particularly transparent. Suppose each piece is subdivided uniformly and each tag is placed at the midpoint of its subinterval. The resulting sum still includes the width of every subinterval; the midpoint choice specifies the function value used in that term.

Worked Example: Midpoint sums with cancellation

Define \(h:[0,2]\to\mathbb{R}\) by \(h(x)=x+1\) for \(0\le x<1\), and \(h(x)=-x\) for \(1\le x\le2\). Divide each unit interval into \(n\) equal parts and use midpoint tags. The midpoints in the first interval are \((i-\tfrac12)/n\), for \(i=1,\ldots,n\). Its contribution is

$$ \frac{1}{n}\sum_{i=1}^{n}\left(1+\frac{i-\tfrac12}{n}\right) = 1+\frac{1}{n^2}\sum_{i=1}^{n}\left(i-\frac12\right) = 1+\frac{1}{n^2}\cdot\frac{n^2}{2} = \frac32. $$

The equality \(\sum_{i=1}^{n}(i-\tfrac12)=n(n+1)/2-n/2=n^2/2\) gives the intermediate value. The midpoints on the second interval are \(1+(i-\tfrac12)/n\), so that piece contributes

$$ \frac{1}{n}\sum_{i=1}^{n}\left(-1-\frac{i-\tfrac12}{n}\right) = -1-\frac{1}{n^2}\cdot\frac{n^2}{2} = -\frac32. $$

The full sum is \(3/2-3/2=0\) for every \(n\), so its limit is \(0\). Checking the result, the two computed piece contributions are exact opposites, and their sum is indeed zero.

A Common Mistake: Dropping Widths or Signs

Each term in a Riemann sum is \(f(\xi_i)\Delta x_i\), not just \(f(\xi_i)\). For the middle piece of the first example, there are \(m\) terms with value \(-2\), each multiplied by \(1/m\). The correct calculation is

$$ \sum_{i=1}^{m}(-2)\frac{1}{m} = -2\frac{m}{m} = -2. $$

Dropping the widths would give \(\sum_{i=1}^{m}(-2)=-2m\), which diverges instead of approaching the piece’s finite contribution. The correction is to include the width in every term.

A separate sign error occurs if the negative pieces are treated as positive geometric areas. In the first example, adding magnitudes would give \(1/2+2+1/2=3\), not the signed integral. The last two pieces lie below the horizontal axis, so their contributions are \(-2\) and \(-1/2\). The signed total is \(1/2-2-1/2=-2\).

A Reliable Calculation Sequence

1
List the breakpoints.
Use them to identify the intervals on which each formula applies.
2
Specify widths and tags.
Write the subinterval width and an expression for the tags used in each piece.
3
Build each contribution.
Substitute the tag into the correct formula and multiply by its interval width.
4
Take the limits and check.
Account for any endpoint tags, combine signed contributions, and verify that the stated total matches them.

This approach keeps the bookkeeping visible. It also makes clear why a finite jump at a breakpoint does not automatically disrupt the calculation: an exceptional value affects only a term whose interval width tends to zero. The essential work is to form the correct weighted sums and preserve the signs of the contributions.

Check Your Understanding

For each question, identify the widths, tags, and signed contributions before evaluating a limit.

  1. If a constant piece has value \(4\) on an interval of length \(2\), what contribution should its uniform tagged sums approach?
  2. In the first worked example, what is the correction to the first-piece sum if its last tag equals \(1\), and why does the correction vanish?
  3. For the step function \(g\), why does a tag at \(1\) change the first-interval sum by \(4/n\) rather than by an amount independent of \(n\)?
  4. What error results from summing function values without multiplying each by its subinterval width?
  5. Why is the signed total for \(f\) different from the sum of the magnitudes of its three contributions?

Test yourself: Calculus I final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon