Riemann Sum Calculator

Approximate a definite integral with left-endpoint, right-endpoint, or midpoint rectangles. Compare all three rules, inspect the chosen sample points, and see the rectangles on a graph. Everything runs locally in your browser.

Enter a function and interval

Use ^ for powers. Supported functions include sin, cos, tan, exp, ln, log, sqrt, and abs.

Try an example

Use 1–50,000 equal subintervals. Press Ctrl/ + Enter to calculate.

Advertisement

Riemann sum results

Enter a function to calculate Δx and the selected sums.
A numerical integral reference will appear here when the function is continuous on the interval.

Calculated approximations will appear here.

Rectangle approximation graph

Calculate a sum to graph the function and its rectangles.

Calculator methodology and limits

Developed and reviewed by
Starlight Robotics calculator team
Last reviewed
Method
Divide [a,b] into n equal widths → evaluate the selected endpoint or midpoint in every subinterval → add f(xᵢ*)Δx using compensated summation.
Reference value
An adaptive Simpson estimate is shown only when the function appears finite and continuous throughout the interval. It is a comparison, not part of the Riemann sum.
Input limits
One real-valued variable, finite bounds, a 300-character expression, and 1–50,000 subintervals.
Privacy
Your function, bounds, results, graph and downloaded data remain on your device.

How to use the Riemann sum calculator

  1. Enter a function such as x^2, sin(x), or exp(-x^2).
  2. Enter lower bound a, upper bound b, and the positive integer number of equal subintervals n.
  3. Choose one sampling rule or compare left, right, and midpoint sums together.
  4. Calculate, then inspect Δx, sample points, approximation errors, and the rectangle graph. Copy the summary or download sample values as CSV if needed.

How to interpret the result

Signed rectangle area

Each contribution is f(xᵢ*)Δx. Heights below the horizontal axis are negative. Reversing the bounds also reverses the sign because Δx becomes negative.

Endpoint behavior

For an increasing nonnegative function with a<b, the left rule typically underestimates and the right rule overestimates. This shortcut does not apply to every function.

Midpoint accuracy

For sufficiently smooth functions, midpoint error often decreases faster than left- or right-endpoint error as n grows. It is not guaranteed to be best for every finite example.

Convergence

If a bounded function is Riemann-integrable, refining the partition drives valid sample-based sums toward the definite integral. A discontinuity at a selected sample can make that particular finite sum undefined.

Worked example: f(x)=x² on [0,2], n=4

Subinterval width

Δx=(2−0)/4=0.5.

Left sum

0.5[f(0)+f(0.5)+f(1)+f(1.5)]=1.75.

Right sum

0.5[f(0.5)+f(1)+f(1.5)+f(2)]=3.75.

Midpoint sum

0.5[f(0.25)+f(0.75)+f(1.25)+f(1.75)]=2.625. The exact integral is 8/3 ≈ 2.666667.

Left, right and midpoint Riemann sum formulas

For n equal subintervals on [a,b], let Δx=(b−a)/n and xᵢ=a+iΔx.

RuleSample in subinterval iSum
LeftxᵢLₙ=Δx Σᵢ₌₀ⁿ⁻¹ f(a+iΔx)
Rightxᵢ₊₁Rₙ=Δx Σᵢ₌₁ⁿ f(a+iΔx)
Midpoint(xᵢ+xᵢ₊₁)/2Mₙ=Δx Σᵢ₌₀ⁿ⁻¹ f(a+(i+1/2)Δx)

These are uniform-partition sums. The calculator does not choose unequal widths, upper/lower sums, trapezoids, or Simpson’s rule as the displayed approximation.

Riemann sum calculator FAQs

What is a Riemann sum?

It approximates a definite integral by partitioning an interval, choosing one sample point in each part, multiplying the function value by that part’s width, and adding the signed rectangle areas.

How do left, right and midpoint rules differ?

The left rule samples the start of each subinterval, the right rule samples the end, and the midpoint rule samples halfway between. All three use the same Δx.

Why does the midpoint sum often look more accurate?

For a sufficiently smooth function, midpoint rectangles balance some first-order error across each interval. Its overall error is commonly proportional to 1/n², while basic endpoint rules commonly have error proportional to 1/n. Particular functions can behave differently.

Can the lower bound be greater than the upper bound?

Yes. Then Δx is negative, so the oriented sum approximates the negative of the integral with the bounds reversed.

Why is one rule undefined while another works?

A selected endpoint may land where the function is undefined or non-real even when another rule’s samples do not. The calculator reports that rule separately; this does not by itself prove that the improper integral exists.

Does increasing n always reduce the displayed error?

No. Convergence describes long-run behavior for integrable functions, not a guarantee that every successive finite n improves every rule monotonically.

Are trigonometric inputs in radians?

Yes. As in standard calculus formulas, trigonometric function arguments are measured in radians.

Does my expression leave the browser?

No. The expression is parsed and evaluated locally. Copying or downloading happens only when you select the corresponding control.

Explore more mathematical tools

Explore more tools