Skip to content
Math & Scientific

Upper And Lower Sums Calculator

Upper And Lower Sums Calculator

Approximate a definite integral with n rectangles and get both the upper sum and the lower sum, shown side by side with the gap between them.

The function is split into n equal rectangles over the interval below.

Upper sum

Lower sum

Finding the exact area under a curve usually requires integration, but long before anyone learns antiderivatives, there is a simpler idea: trap the area between two estimates made of rectangles. The upper sum uses rectangles that reach at least as high as the curve, and the lower sum uses rectangles that stay at or below it. The true area must lie somewhere between the two.

This calculator computes both sums at once for five common functions, shows them side by side, and reports the gap between them so you can see exactly how tight your trap is. This guide explains the geometry behind the numbers, the formulas, the domain rules, and how the gap shrinks as you add more rectangles.

What Upper And Lower Sums Are

Start with a function f(x) and an interval from a to b. Split the interval into n equal pieces, each of width delta x, which equals b minus a divided by n. Over each small piece, draw one rectangle. The collection of rectangles is called a Riemann sum.

For the upper sum, the height of each rectangle is the largest value the function takes on that small piece. The rectangle therefore covers the curve completely, and the sum of all the rectangle areas is guaranteed to be at least as big as the true area under the curve.

For the lower sum, the height of each rectangle is the smallest value the function takes on that piece. These rectangles fit underneath the curve, so their total area is guaranteed to be at most the true area. Together the two sums bracket the integral: lower sum is less than or equal to the integral, which is less than or equal to the upper sum.

The formula is:

upper sum = (M1 + M2 + ... + Mn) x delta x

lower sum = (m1 + m2 + ... + mn) x delta x

Here M1 through Mn are the maximum values of f on each of the n subintervals, m1 through mn are the minimum values on each subinterval, and delta x equals (b minus a) divided by n. Add up the heights, multiply by the common width, and you have the total rectangle area for each sum.

Rectangles Under A Curve: The Basic Idea

A curve is hard to measure directly, but rectangles are easy. If you slice the region under a curve into thin vertical strips and replace each strip with a rectangle, the rectangles approximate the region. Thinner strips mean better rectangles, which is why increasing n improves both sums.

The choice of height is what separates the different Riemann sums. Left-endpoint sums use the function value at the left edge of each strip, right-endpoint sums use the right edge, and midpoint sums use the center. Upper and lower sums are stricter: they use the actual maximum and minimum on each strip, whatever point produces them.

That strictness is the point. Left and right sums can overshoot or undershoot without telling you which, but upper and lower sums give you a guaranteed interval that contains the true area. The calculator finds each maximum and minimum by sampling many points inside every subinterval, which handles even wavy functions like sine correctly.

Why Two Sums Instead Of One

A single Riemann sum gives one number with no information about its error. The upper and lower sums give two numbers that trap the truth between them, so the gap between them is a built-in error bound. If the upper sum is zero point four six eight eight and the lower sum is zero point two one eight eight, you know the integral is somewhere in that range, and the gap of zero point two five tells you the worst case.

This trapping idea is the foundation of the definite integral itself. As n grows, both sums converge to the same value, and that common limit is defined as the integral. Watching the gap shrink on the calculator is watching the definition of integration happen numerically.

In practice, two sums also catch mistakes. If your upper sum comes out smaller than your lower sum, something is wrong with the setup, because the upper sum can never legitimately fall below the lower sum on any subinterval.

Monotone Functions: A Shortcut Worth Knowing

When a function is always increasing or always decreasing on the interval, the maximum and minimum on each subinterval sit at the endpoints, and you can compute the sums by hand. For an increasing function like x squared on zero to one, the lower sum uses the left endpoints and the upper sum uses the right endpoints.

For a decreasing function like one over x on one to two, the roles reverse: the left endpoints give the larger values, so they build the upper sum, while the right endpoints build the lower sum. The calculator handles this automatically, but knowing the pattern lets you verify small cases by hand.

Non-monotone functions like sine on zero to pi rise and then fall, so the maximum on a middle subinterval sits in the interior, not at an endpoint. Endpoint-only methods would miss it, which is why the calculator samples inside each subinterval rather than trusting the edges.

How The Number Of Rectangles N Controls Accuracy

Every time you double n, the width of each strip halves, and the rectangles hug the curve more closely. For smooth functions the gap between the sums shrinks roughly in proportion to one over n, so doubling the rectangles roughly halves the gap.

The worked examples below show this directly: x squared on zero to one with four rectangles gives a gap of zero point two five, while eight rectangles gives a gap of zero point one two five. The trap tightens exactly as the theory predicts.

There is no rule that n must be large to be useful. Even n equals four or six gives a genuine bracket around the integral, and for quick estimates a small n computed by hand is often enough. Use a large n when you need digits, and a small n when you need understanding.

The Gap As An Error Bound

The gap, upper sum minus lower sum, measures the total area of the uncertainty: the collection of thin slivers between the overestimating rectangles and the underestimating ones. The true integral can be at most the full gap away from either sum, and at most half the gap away from their average.

This makes the midpoint of the two sums a natural best guess. For x squared on zero to one with four rectangles, the average of zero point four six eight eight and zero point two one eight eight is zero point three four three eight, which is already close to the exact value of one-third.

When the calculator reports the gap, read it as a confidence statement. A gap of zero point zero one means you know the integral to within a hundredth. A gap of one means you know almost nothing yet and should raise n.

Domain Rules: Square Root And One Over X

Not every function is defined everywhere, and the calculator enforces the domain rules before computing anything. The square root of x is only defined for x of zero or more, so the left endpoint a must be zero or greater when you select the square root function. An interval starting at a negative number has no valid sum.

One over x is undefined at x equals zero, where it blows up to infinity. The calculator rejects any interval that touches or crosses zero: a must be strictly positive or b must be strictly negative. An interval like negative one to one is invalid, and so is zero to two, because the function has no finite maximum on a strip containing zero.

These are not arbitrary restrictions. An upper sum requires a finite maximum on every subinterval, and near a vertical asymptote no finite maximum exists. Respecting the domain keeps the sums meaningful.

Choosing A And B

The interval endpoints define the region you are measuring. The calculator requires b to be greater than a, so the interval always runs left to right and every rectangle width is positive. Swapping them would describe the same geometric region but with a sign convention from integral theory that the calculator keeps out of the picture.

Pick endpoints that match the question you are asking. If you want the area under x squared from zero to one, set a to zero and b to one. If you want a symmetric region around a peak of the sine function, center the interval on pi over two.

Longer intervals are not harder than short ones; the formula divides the total length by n either way. But a longer interval with the same n means wider strips and a looser trap, so raise n when you stretch the interval to keep the gap small.

Upper And Lower Sums And The Definite Integral

The definite integral from a to b of f is the exact signed area under the curve, and the upper and lower sums are its two-sided approximation. As n approaches infinity, both sums approach the integral, provided the function is well behaved on the interval.

This convergence is why calculus courses introduce Riemann sums before the Fundamental Theorem. The theorem gives a fast exact route through antiderivatives, but the sums explain what the integral means: the limit of better and better rectangle approximations.

You can use the calculator to guess an integral before learning to compute it exactly. If both sums hover near zero point six nine three for one over x on one to two, you have discovered numerically that the integral equals the natural logarithm of two, which is approximately zero point six nine three one.

Where This Shows Up In Real Life

Numerical integration powers any computation where areas or accumulations matter and no formula is available. Engineers estimate the total load on a beam from sensor readings taken at intervals, which is exactly a Riemann sum over measured data rather than a known function.

In finance, the total interest accrued under a varying rate curve is an integral approximated by sums over reporting periods. In medicine, the total drug exposure from a concentration curve over time is the area under that curve, estimated from blood samples at discrete times.

Even computer graphics relies on the same idea: rendering an image samples light at discrete points, and the upper and lower sums are the theoretical guarantee that finer sampling converges to the true picture.

Common Mistakes Students Make

The most common mistake is mixing up which endpoints give the upper sum. For increasing functions the right endpoints give the upper sum, but for decreasing functions the left endpoints do. Always check the direction of the function before assigning endpoints by hand.

The second mistake is using n as the width instead of the count. Delta x equals b minus a divided by n; n itself is just how many rectangles you draw. Forgetting to divide makes every rectangle far too wide.

The third mistake is ignoring the domain. Computing sums for one over x across zero, or for the square root of x on negative numbers, produces nonsense because the function values do not exist there. The calculator blocks these cases, and you should block them in hand calculations too.

Worked Example: X Squared From 0 To 1 With 4 Rectangles

Take f(x) equals x squared on the interval zero to one with n equals four. The width is delta x equals one minus zero divided by four, which is zero point two five. Because x squared is increasing on this interval, the lower sum uses the left endpoints and the upper sum uses the right endpoints.

Left endpoints are zero, zero point two five, zero point five, and zero point seven five. Squaring each gives zero, zero point zero six two five, zero point two five, and zero point five six two five. Their sum is zero point eight seven five, and multiplying by zero point two five gives a lower sum of zero point two one eight seven five.

Right endpoints are zero point two five, zero point five, zero point seven five, and one. Squaring gives zero point zero six two five, zero point two five, zero point five six two five, and one. Their sum is one point eight seven five, times zero point two five, giving an upper sum of zero point four six eight seven five.

The gap is zero point four six eight seven five minus zero point two one eight seven five, which equals zero point two five. The exact integral is one-third, about zero point three three three, which sits comfortably between the two sums.

Worked Example: X Squared From 0 To 1 With 8 Rectangles

Double the rectangles to n equals eight and watch the trap tighten. Delta x becomes one divided by eight, which is zero point one two five. The function is still increasing, so left endpoints build the lower sum and right endpoints build the upper sum.

The right-endpoint squares are one through eight squared, all over sixty-four: one, four, nine, sixteen, twenty-five, thirty-six, forty-nine, and sixty-four sixty-fourths. Their sum is two hundred four over sixty-four, which is three point one eight seven five. Multiply by zero point one two five to get an upper sum of zero point three nine eight four.

The left-endpoint squares are zero through seven squared over sixty-four, summing to one hundred forty over sixty-four, which is two point one eight seven five. Multiply by zero point one two five to get a lower sum of zero point two seven three four.

The gap is now zero point one two five, exactly half the gap with four rectangles. Both sums moved closer to one-third, and doubling n again would halve the gap once more.

Worked Example: One Over X From 1 To 2 With 4 Rectangles

Take f(x) equals one over x on the interval one to two with n equals four. Delta x equals two minus one divided by four, which is zero point two five. One over x is decreasing here, so the left endpoints now give the upper sum and the right endpoints give the lower sum.

Left endpoints are one, one point two five, one point five, and one point seven five. Their reciprocals are one, zero point eight, zero point six six six seven, and zero point five seven one four. The sum is three point zero three eight one, and times zero point two five the upper sum is zero point seven five nine five.

Right endpoints are one point two five, one point five, one point seven five, and two. Their reciprocals are zero point eight, zero point six six six seven, zero point five seven one four, and zero point five. The sum is two point five three eight one, and times zero point two five the lower sum is zero point six three four five.

The gap is zero point one two five. The exact integral is the natural logarithm of two, about zero point six nine three one, which lies between the two sums as guaranteed.

Worked Example: Sine From 0 To Pi With 6 Rectangles

Take f(x) equals sine of x on zero to pi with n equals six. Delta x equals pi divided by six, about zero point five two three six. Sine rises to a peak at pi over two and then falls, so the maximum on the middle subintervals sits inside the strip, not at an endpoint.

The calculator samples many points inside each subinterval to find the true maximum and minimum. The upper sum comes out to two point four seven seven seven and the lower sum to one point four three zero five.

The gap is two point four seven seven seven minus one point four three zero five, which equals one point zero four seven two. The exact area under sine from zero to pi is two, which sits between the two sums.

This example shows why sampling matters: a pure left-endpoint or right-endpoint rule would miss the interior peak and produce sums that are not true upper and lower bounds. The guaranteed bracket only holds when each strip uses its genuine maximum and minimum.

Frequently Asked Questions

1. What is an upper sum?

An upper sum approximates the area under a curve with rectangles whose heights are the maximum value of the function on each subinterval. Because every rectangle covers the curve, the upper sum is always greater than or equal to the true integral.

2. What is a lower sum?

A lower sum uses rectangles whose heights are the minimum value of the function on each subinterval. Every rectangle fits under the curve, so the lower sum is always less than or equal to the true integral.

3. What is the gap between the sums?

The gap is the upper sum minus the lower sum. It measures the total uncertainty in the estimate: the true integral lies somewhere inside a range of that width. Smaller gaps mean better estimates.

4. Why must b be greater than a?

The interval is split into n pieces of width b minus a divided by n, and that width must be positive for the rectangles to make sense. The calculator therefore requires the right endpoint to be strictly greater than the left endpoint.

5. Why must n be a whole number of at least 1?

You cannot draw a fractional number of rectangles, so n must be an integer, and you need at least one rectangle to cover the interval. The calculator rejects zero, negative, and non-integer values of n.

6. Why does 1 over x reject intervals crossing zero?

One over x is undefined at x equals zero and grows without bound nearby, so no finite maximum exists on any subinterval containing zero. Without a finite maximum there is no valid upper sum, so the calculator requires intervals that stay strictly positive or strictly negative.

7. Why does the square root need a to be zero or more?

The square root of a negative number is not a real number, so the function has no values on any part of the interval below zero. The calculator requires the left endpoint a to be zero or greater when the square root function is selected.

8. For an increasing function, which endpoints give the upper sum?

The right endpoints. On an increasing function the largest value on each subinterval sits at its right edge, so right-endpoint rectangles build the upper sum and left-endpoint rectangles build the lower sum.

9. For a decreasing function, which endpoints give the upper sum?

The left endpoints. On a decreasing function the largest value on each subinterval sits at its left edge, so the roles reverse compared with an increasing function.

10. What happens to the gap when n doubles?

For smooth functions the gap shrinks roughly by half each time n doubles, because each strip becomes half as wide and the rectangles hug the curve more closely. The x squared examples show the gap falling from zero point two five to zero point one two five when n goes from four to eight.

11. Can the upper sum ever be smaller than the lower sum?

No. On every subinterval the maximum is at least the minimum, so the upper sum is always greater than or equal to the lower sum. If you ever compute an upper sum below a lower sum, check your endpoint assignment or your arithmetic.

12. How do upper and lower sums relate to the definite integral?

The definite integral is the exact area under the curve, and the sums bracket it: lower sum is less than or equal to the integral, which is less than or equal to the upper sum. As n grows, both sums converge to the integral.

13. Why does the calculator sample inside each subinterval?

For functions that are not monotone, like sine, the maximum or minimum on a subinterval can sit in the interior rather than at an endpoint. Sampling many points inside each strip finds the true extreme values so the sums remain genuine upper and lower bounds.

14. Is the average of the two sums a good estimate?

Yes, it is often a very good one. The true integral can be at most half the gap away from the midpoint of the two sums. For x squared on zero to one with four rectangles, the midpoint is zero point three four three eight, close to the exact one-third.

15. Which function should I start with to learn this?

Start with x squared on zero to one with four rectangles. It is increasing, so the endpoint rule is simple, the arithmetic stays clean, and you can verify the lower sum of zero point two one eight eight and upper sum of zero point four six eight eight by hand.