Riemann Sum Calculator

Approximate a definite integral with left, right, midpoint, trapezoidal or Simpson's sums. See every rectangle, Δx, the steps and the error as n grows.

Riemann Sum Calculator

Calculate Riemann sums to approximate the definite integral of a function. Choose left, right or midpoint rectangles, the trapezoidal rule, or Simpson's rule. Riemann sums are fundamental in understanding integration and calculus.

Function and Interval

Use ^ for powers; 2x and 2*x both work. Functions: sin, cos, tan, ln (natural log), log (base 10), sqrt, abs, exp. Constants: pi, e
Bounds accept numbers or expressions with pi and e, such as pi/2 or 2*e.

Riemann Sum Method

Left Riemann Sum: Uses the left endpoint of each subinterval to determine rectangle height.

Display Options

Riemann Sum Calculator: Stop Guessing Approximations

Most students assume a left Riemann sum with 10 rectangles gives a decent answer for any function. It does not. For a function that curves sharply, that estimate can be off by 20% or more. The calculator shows you the actual error for each method, so you can check homework and see exactly where the estimate breaks down. You enter f(x), the interval [a, b], and the number of subintervals n, then choose Left, Right, Midpoint, Trapezoidal, or Simpson's rule. The calculator returns the sum, the interval width Δx, the absolute error, and the relative error. It also shows the calculation steps and a visual graph of the rectangles or trapezoids.

  • What You Enter: f(x) using ^ for powers, sin, cos, tan, ln, log, sqrt, abs, exp; constants pi and e; lower bound a and upper bound b (numbers or expressions like pi/2); number of subintervals n (1 to 1000); method: Left, Right, Midpoint, Trapezoidal, or Simpson's Rule
  • What You Get: Riemann sum approximation, interval width Δx, number of subintervals, method used, reference integral (exact value from power rule or high-precision Simpson's with n=20,000), absolute approximation error, relative error percentage, optional calculation steps and visual graph
  • Method Comparison: Compare all available methods at once using the 'Compare all methods' checkbox to see how each rule performs for your function, interval, and n
  • Display Options: Adjust decimal places (2-6), show or hide calculation steps, show or hide visual graph, compare all methods simultaneously

How to Enter f(x), a, b and n

Type your function into the Function f(x) field using standard mathematical notation. Use ^ for powers: x^2 for x squared, 2*x^3 for 2x cubed. Multiplication can be implicit (2x) or explicit (2*x). Supported functions include sin, cos, tan, ln (natural log), log (base 10), sqrt, abs, and exp. Constants pi and e are recognised. For example, sin(x^2), exp(-x), ln(x+1), and abs(x) are all valid.

Enter the lower bound a and upper bound b as numbers or expressions involving pi and e. You can type pi/2, 2*e, or 3.14159 directly. The bounds must satisfy a < b.

Set the number of subintervals n to any integer from 1 to 1000. For Simpson's Rule, n must be even. If you enter an odd n with Simpson's selected, the calculator will prompt you to change it.

Choose the approximation method from the dropdown: Left Riemann Sum, Right Riemann Sum, Midpoint Riemann Sum, Trapezoidal Rule, or Simpson's Rule. Click Calculate to see the results.

What Each Result Means: Δx, Approximation, Error, Relative Error

The interval width Δx is (b-a)/n. This is the width of each subinterval or the base of each rectangle or trapezoid. A smaller Δx means more subintervals and a finer partition.

The Riemann Sum Approximation is the sum of the areas of the shapes (rectangles or trapezoids) calculated with your chosen method. This is your numerical estimate of the definite integral.

The Reference Integral is the exact value of the integral calculated either via the power rule (for simple polynomials like x^2, x^3, or constant multiples) or via a high-precision Simpson's rule with n=20,000 subintervals. If the reference value cannot be computed reliably (e.g., near singularities), it is omitted.

The Approximation Error is the absolute difference between your sum and the reference integral: |approximation - exact|. The Relative Error expresses this as a percentage of the exact value: (|approximation - exact| / |exact|) × 100. A relative error of 5% means your approximation is off by 5% of the true area.

These error figures tell you exactly how good or bad your approximation is. If the relative error is above 10%, you likely need more subintervals or a different method.

Left, Right, Midpoint, Trapezoid and Simpson's at a Glance

How Each Method Picks the Sample Point

The Left Riemann Sum uses the left endpoint of each subinterval: xi* = xi-1. The Right Riemann Sum uses the right endpoint: xi* = xi. The Midpoint Riemann Sum uses the midpoint: xi* = (xi-1 + xi)/2. The Trapezoidal Rule averages the left and right heights, using trapezoids instead of rectangles. Simpson's Rule fits a parabola through each pair of subintervals (requires n even) and is usually the most accurate for smooth functions.

Which One to Use

For a quick check, Left and Right sums are the simplest but least accurate. Midpoint and Trapezoidal give better accuracy for the same n, and Simpson's is best for smooth functions. If you are working from a table of values, Left, Right, Midpoint, and Trapezoidal all work; Simpson's requires evenly spaced points and even n.

Over- and Underestimates

For an increasing function, the Left sum underestimates and the Right sum overestimates. For a decreasing function, the opposite holds. The Midpoint sum and Trapezoidal rule depend on concavity: for a concave-up function, the Trapezoidal rule overestimates and the Midpoint sum underestimates; for concave-down, the reverse is true. These relationships are tested on the AP Calculus exam and are critical for justifying your choice of method.

Riemann Sum Methods Compared: Rule, Sample Point, Formula
MethodSample Point xᵢ*Formula
Left Riemann SumLeft endpoint: xᵢ₋₁Lₙ = Δx · [f(x₀) + f(x₁) + ... + f(xₙ₋₁)]
Right Riemann SumRight endpoint: xᵢRₙ = Δx · [f(x₁) + f(x₂) + ... + f(xₙ)]
Midpoint Riemann SumMidpoint: (xᵢ₋₁ + xᵢ)/2Mₙ = Δx · [f(m₁) + f(m₂) + ... + f(mₙ)]
Trapezoidal RuleAverage of left and right endpointsTₙ = (Δx/2) · [f(x₀) + 2f(x₁) + ... + 2f(xₙ₋₁) + f(xₙ)]
Simpson's RuleParabola through three points (n even)Sₙ = (Δx/3) · [f(x₀) + 4f(x₁) + 2f(x₂) + 4f(x₃) + ... + f(xₙ)]

Worked Example: f(x) = x² on [0, 2] with Every Method Compared

Consider the function f(x) = x² on the interval [0, 2]. The exact integral is ∫₀² x² dx = (2³)/3 = 8/3 ≈ 2.6667. We use n = 4 subintervals, so Δx = (2-0)/4 = 0.5. The partition points are x₀=0, x₁=0.5, x₂=1.0, x₃=1.5, x₄=2.0.

Left Riemann Sum

Evaluate at left endpoints: f(0)=0, f(0.5)=0.25, f(1)=1, f(1.5)=2.25. Sum = 0+0.25+1+2.25 = 3.5. Multiply by Δx: L₄ = 0.5 × 3.5 = 1.75. Error = |1.75 - 2.6667| = 0.9167. Relative error = 34.4%.

Right Riemann Sum

Evaluate at right endpoints: f(0.5)=0.25, f(1)=1, f(1.5)=2.25, f(2)=4. Sum = 0.25+1+2.25+4 = 7.5. R₄ = 0.5 × 7.5 = 3.75. Error = |3.75 - 2.6667| = 1.0833. Relative error = 40.6%.

Midpoint Riemann Sum

Midpoints are at x=0.25, 0.75, 1.25, 1.75. f(0.25)=0.0625, f(0.75)=0.5625, f(1.25)=1.5625, f(1.75)=3.0625. Sum = 5.25. M₄ = 0.5 × 5.25 = 2.625. Error = |2.625 - 2.6667| = 0.0417. Relative error = 1.6%.

Trapezoidal Rule

T₄ = (Δx/2)[f(0)+2f(0.5)+2f(1)+2f(1.5)+f(2)] = 0.25[0+0.5+2+4.5+4] = 0.25 × 11 = 2.75. Error = |2.75 - 2.6667| = 0.0833. Relative error = 3.1%.

Simpson's Rule

S₄ = (Δx/3)[f(0)+4f(0.5)+2f(1)+4f(1.5)+f(2)] = (0.5/3)[0+1+2+9+4] = (0.1667) × 16 = 2.6667. Error = essentially zero for this quadratic (Simpson's is exact for quadratics and cubics). Relative error ≈ 0%.

This example shows why the Midpoint sum (1.6% error) and Trapezoidal rule (3.1%) outperform Left and Right sums (34% and 41%) for the same n. Simpson's rule gives the exact answer because x² is a quadratic.

Why the Error Shrinks as n Increases

As n increases, Δx becomes smaller. Each rectangle or trapezoid covers a narrower slice of the function, so the difference between the function's actual shape and the approximating shape shrinks. For Left and Right Riemann sums, the error is proportional to 1/n. For Midpoint and Trapezoidal rules, the error is proportional to 1/n². For Simpson's rule, the error is proportional to 1/n⁴. This means doubling n cuts the Left/Right error by half, but cuts the Midpoint/Trapezoidal error by a factor of four, and the Simpson's error by a factor of sixteen.

In practice, for the worked example x² on [0,2] with n=4, the Midpoint sum already gives a relative error of 1.6%. Increasing n to 8 would reduce the Midpoint error to about 0.4%, and n=16 would bring it below 0.1%. The same pattern holds for any smooth function: the error drops rapidly with more subintervals, especially for the higher-order methods.

One caveat: for functions with discontinuities or sharp corners, the error may not follow these theoretical rates. The calculator's error display lets you verify convergence directly.

Common Questions

What is a Riemann sum?

A Riemann sum is an approximation of a definite integral by a finite sum. It is calculated by dividing the region into shapes (rectangles or trapezoids) that together form a region similar to the region being measured, then summing the areas of these shapes. The definite integral is the limit of these sums as n approaches infinity.

Which Riemann sum method is most accurate?

For a given n, Simpson's Rule is generally the most accurate for smooth functions, followed by the Midpoint and Trapezoidal rules, which are similar in accuracy. Left and Right sums are the least accurate. The accuracy of all methods improves as n increases.

How does the number of subintervals (n) affect accuracy?

Increasing n reduces the error. For Left and Right sums, error is proportional to 1/n. For Midpoint and Trapezoidal, error is proportional to 1/n². For Simpson's, error is proportional to 1/n⁴. Doubling n roughly halves the Left/Right error, quarters the Midpoint/Trapezoidal error, and reduces Simpson's error by a factor of 16.

Can I use trigonometric or exponential functions?

Yes. The calculator supports sin(x), cos(x), tan(x), ln(x) (natural log), log(x) (base 10), sqrt(x), abs(x), and exp(x). Use ^ for powers, and constants pi and e are recognised.

Why does the calculator show a reference integral?

The reference integral gives you the exact value (when the function is a simple polynomial) or a high-precision numerical approximation (Simpson's with n=20,000). This lets you see the absolute and relative error of your chosen method, so you can verify homework and understand how close your approximation really is.

Guides on this site