How this calculation works
Divide the interval into n equal widths, evaluate the function at the selected point inside each interval, and add signed rectangle contributions. Compare all three sampling choices at the same n, then inspect the selected method with twice as many rectangles. The SVG overlays the function, rectangle outlines and sampled heights.
Δx = (b−a)/n; S = Σ f(a+(i+offset)Δx)Δx, with offset 0, 1/2 or 1A worked example
For x²+1 on [0,4] with four rectangles, Δx=1. Left heights 1,2,5,10 give 18; right heights 2,5,10,17 give 34; midpoint heights 1.25,3.25,7.25,13.25 give 25. The exact integral for this polynomial example is 76/3, about 25.333333.
Good to know
Safe bounded arithmetic expressions, finite limits within ±1000, and 1–1000 rectangles. Numerical comparisons do not certify an error bound or detect all singularities. Signed sums are not automatically unsigned geometric area. All displayed methods and comparison grids require finite sampled function values.
Reference: OpenStax Calculus: approximating areas (opens in a new tab) ↗
Build the sum one rectangle at a time
A Riemann sum replaces a varying function by a collection of constant heights over short intervals. First divide the interval from a to b into n pieces of equal signed width, Δx=(b−a)/n. Then choose one sample point in each piece. Multiply that function value by the width and add the contributions. The table displays that entire process rather than only a final total.
The graph uses the same x and y coordinates for the sampled function and the rectangle outlines. Dots mark the sample that supplies each height. Increasing n changes both the widths and the sample positions. The picture is useful for seeing how the construction works, while the table gives the numerical values behind the drawing. A smooth-looking plotted line remains a finite sample of the entered function.
Compare left, midpoint and right on the same interval
For f(x)=x²+1 on [0,4] with n=4, every width is one. The left samples are x=0,1,2,3 and the corresponding heights are 1,2,5,10. Their sum is 18. Right sampling shifts to x=1,2,3,4, giving heights 2,5,10,17 and a sum of 34. Midpoint sampling uses x=0.5,1.5,2.5,3.5; the heights 1.25,3.25,7.25,13.25 total 25.
The exact integral for this particular polynomial is 76/3. The left sum underestimates it and the right sum overestimates it because this function is increasing over the chosen interval. That statement is conditional on monotonicity and increasing bounds. For a decreasing function the endpoint behavior reverses; for a function that rises and falls, neither endpoint method has a universal direction of error. Midpoint sampling often helps on smooth functions but is not guaranteed to be best for every input.
Keep signed accumulation separate from geometric area
With increasing bounds, a sampled height below zero produces a negative rectangle contribution. Positive and negative contributions can cancel. For f(x)=x on [−1,1], a symmetric midpoint grid gives zero signed accumulation even though the two triangular regions have positive total geometric area. A result of zero therefore does not mean that the graph encloses no area.
The steps also show the sum of the absolute values of the sampled rectangle contributions. It describes those particular rectangles and is not presented as the exact integral of the absolute value of the function. A zero crossing can occur inside a rectangle. To find an exact geometric area, analyze those crossings and integrate the appropriate pieces, rather than changing the sign of a final signed result.
Use a finer grid as evidence rather than a guarantee
The result includes the same method with twice as many rectangles. For the worked quadratic, the left estimate moves from 18 at n=4 to 21.5 at n=8, and the midpoint estimate moves from 25 to 25.25. These comparisons illustrate convergence for a familiar smooth function. They do not establish that every entered function is well resolved by those particular grids.
A denser Simpson comparison is shown in the steps and copied scenario. The trapezoidal and Simpson integration calculator explains those different panel constructions. The denser run is another estimate, not an analytic true value. Oscillations can align with a sampling grid, and narrow features can lie between plotted points. Small agreement between numerical runs is not a certified error bound.
Check domains, notation and reversed limits
Enter explicit multiplication such as 2*x and use parentheses in functions such as sin(x). The parser supports a bounded mathematical language without executing code. Trigonometric arguments use radians, ln and log are natural logarithms, and real sqrt requires nonnegative arguments at every evaluated point. A failed evaluation produces an error rather than an invented zero height.
Finite sampled values still cannot prove that the function is continuous between nodes. An interval crossing a pole of 1/x or tan(x) needs mathematical analysis before ordinary Riemann approximations are interpreted. This page evaluates all three methods plus comparison grids, so a formula must be defined at every required point, even when the selected method alone would avoid that point.
Reversed bounds are supported with a negative signed width. Left and right sample names then follow traversal from the entered start to the entered end. Reversing the bounds therefore exchanges the corresponding physical endpoint sets: a reversed left sum is the negative of the forward right sum at the same n. A reversed midpoint sum is the negative of the forward midpoint sum. The copied result records bounds and sampling method so this distinction remains visible.
A few questions, answered
Is midpoint always more accurate?
No. It often improves an approximation for smooth functions, but there is no universal ordering for all possible functions and sampling grids.
Why can the total be negative?
A Riemann sum is signed accumulation. Negative sampled heights or reversed bounds can produce negative contributions.
Does the denser comparison prove the answer?
No. It is another numerical estimate. Finite grids can miss singularities or unresolved variation.
Can I download the rectangle graph?
Yes. Use the SVG export beneath the graph to retain the plotted function, rectangle outlines and sampling points.
Why can a formula fail even when my chosen sample points look valid?
All three methods, the plotted function and comparison grids are evaluated. Every required evaluation must be finite; this is still not a proof of continuity between samples.