acalculator

How do I use the midpoint rule?

Type f(x), the limits a and b, and the number of subintervals n. The midpoint rule calculator adds f at the middle of each subinterval and multiplies by the width, lists every midpoint, and compares the trapezoidal and Simpson’s estimates.

Your numbers

Rule
Estimate of the integral
0.328125

The midpoint rule estimate of the integral of x^2 from 0 to 1 with n = 4 is 0.328125.

Simpson’s rule (Sₙ)
0.3333333333
Midpoint rule (Mₙ)
0.328125
Trapezoidal rule (Tₙ)
0.34375
Width Δx
0.25
Points used
m₁ = 0.125: f = 0.015625, weight 1; m₂ = 0.375: f = 0.140625, weight 1; m₃ = 0.625: f = 0.390625, weight 1; m₄ = 0.875: f = 0.765625, weight 1
Rule
midpoint rule

Estimate of the integral: 0.328125. The midpoint rule estimate of the integral of x^2 from 0 to 1 with n = 4 is 0.328125.

How to calculate

Estimates a definite integral ∫ f(x) dx from a to b with the midpoint rule (a midpoint Riemann sum) and n subintervals, beside the trapezoidal and Simpson’s rules.

Example with the default inputs (f(x) x^2, Lower limit (a) 0, Upper limit (b) 1, Subintervals (n) 4, Rule Midpoint rule): The midpoint rule estimate of the integral of x^2 from 0 to 1 with n = 4 is 0.328125.

Method: Mₙ = Δx × [f(m₁) + f(m₂) + … + f(mₙ)], Δx = (b − a) ÷ n, mᵢ = a + (i − ½)Δx.

  • n is any whole number from 1 to 1,000; Simpson’s rule, shown for comparison, needs an even n.
  • The midpoints are exact from the typed decimals before f is evaluated in double precision.
  • f must have a real value at every point the rule uses; angles are in radians.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. f(x) x^2, Lower limit (a) 0, Upper limit (b) 1, Subintervals (n) 4, Rule Midpoint rule gives Estimate of the integral 0.328125, Trapezoidal rule (Tₙ) 0.34375, Width Δx 0.25.Source: OpenStax, Calculus Volume 2, §3.6 Numerical Integration, https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (retrieved 2026-10-02) (Example 3.39: M₄ = 21/64 ≈ 0.328; Example 3.41: T₄ = 11/32)
  2. f(x) sqrt(1 + x^2), Lower limit (a) 1, Upper limit (b) 4, Subintervals (n) 6, Rule Midpoint rule gives Estimate of the integral 8.143073, Simpson’s rule (Sₙ) 8.145944.Source: OpenStax, Calculus Volume 2, §3.6 Numerical Integration, https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (retrieved 2026-10-02) (Example 3.40: M₆ ≈ 8.1431; Example 3.46: S₆ ≈ 8.14594)
  3. f(x) sin(x), Lower limit (a) 0, Upper limit (b) 3.141593, Subintervals (n) 4, Rule Midpoint rule gives Estimate of the integral 2.052344.Source: OpenStax, Calculus Volume 2, §3.6 Numerical Integration, https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (retrieved 2026-10-02)

How it works

Type f(x), the limits a and b (each from −10⁹ to 10⁹; b may be below a) and n (1 to 1,000). Then Δx = (b − a) ÷ n, worked out exactly from the typed decimals, and:

  • Midpoints mᵢ = a + (i − ½)Δx for i = 1 to n; points xᵢ = a + iΔx for i = 0 to n. Each is exact before it becomes a double.
  • Midpoint rule: Mₙ = Δx × [f(m₁) + … + f(mₙ)]
  • Trapezoidal rule: Tₙ = Δx/2 × [f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)]
  • Simpson’s rule (n even): Sₙ = Δx/3 × [f(x₀) + 4f(x₁) + 2f(x₂) + … + 4f(xₙ₋₁) + f(xₙ)]

The rule you pick heads the answer (the midpoint rule unless you change it); the other two are listed for comparison, Simpson’s only when n is even, and each only when f has a real value at every point it uses and its estimate is in range. The f values are divided by one power of two near the largest |f| before the sum (which changes no digit), so the sum cannot overflow.

What f(x) can hold

Numbers (2, 0.5, 1e-3), the letter x, + − * / and ^ (power), brackets, and implicit products (2x is 2 × x). Functions: sin, cos, tan, sec, csc, cot, asin, acos, atan, sinh, cosh, tanh, sqrt, cbrt, abs, exp, ln and log (both natural logarithms), log10; constants pi and e. Angles are in radians.

Rules

  • There is no answer when f(x) cannot be read, or when f has no real value at a point a rule uses (for example sqrt(x) below 0, or a division by 0), or when |f| passes 10³⁰⁰ there. The message names the point.
  • Simpson’s rule, if picked, needs an even n.
  • There is no answer when an estimate is past the double range.

Output format. Estimates and Δx to 10 significant digits. For n up to 20, “Points used” lists each midpoint as “m₁ = 0.125: f = 0.015625, weight 1”, numbers to 10 significant digits with a true minus sign, joined by “; ”.

Worked examples by hand

∫₀¹ x² dx, n = 4. Δx = 0.25; midpoints 0.125, 0.375, 0.625, 0.875; f = 0.015625, 0.140625, 0.390625, 0.765625, sum 1.3125. M₄ = 0.25 × 1.3125 = 0.328125 = 21/64. The trapezoidal rule gives 0.34375; the exact value is 1/3.

∫₁⁴ √(1 + x²) dx, n = 6. Δx = 0.5; midpoints 1.25, 1.75, 2.25, 2.75, 3.25, 3.75; f = 1.600781, 2.015564, 2.462214, 2.926175, 3.400368, 3.881044, sum 16.286146. M₆ = 0.5 × 16.286146 = 8.143073 (OpenStax: 8.1431). Simpson’s S₆ = 8.145944.

∫₀^π sin(x) dx, n = 4. Δx = π/4; midpoints π/8, 3π/8, 5π/8, 7π/8; sines 0.382683, 0.923880, 0.923880, 0.382683, sum 2.613126. M₄ = 0.785398 × 2.613126 = 2.052344; the exact value is 2.

Other questions people ask

What is the midpoint rule?

A Riemann sum that uses the middle of each subinterval: Mₙ = Δx × [f(m₁) + f(m₂) + … + f(mₙ)], with Δx = (b − a) ÷ n and mᵢ the midpoint of the i-th subinterval. It estimates ∫ₐᵇ f(x) dx.

How do I use the midpoint rule step by step?

Find Δx = (b − a) ÷ n, find each midpoint a + (i − ½)Δx, evaluate f there, add, and multiply by Δx. For ∫₀¹ x² dx with n = 4: Δx = 0.25, midpoints 0.125, 0.375, 0.625, 0.875, and M₄ = 0.25 × 1.3125 = 21/64 ≈ 0.328.

How accurate is the midpoint rule?

Its error is at most M(b − a)³ ÷ (24n²), where M bounds |f″(x)| on [a, b]. Doubling n cuts that bound by 4. That is half the trapezoidal rule’s bound, M(b − a)³ ÷ (12n²).

Is the midpoint rule an overestimate or an underestimate?

For a function that curves up (f″ > 0), the midpoint rule underestimates and the trapezoidal rule overestimates; for one that curves down it is the other way round. For x² on [0, 1], M₄ = 0.328 < 1/3 < T₄ = 0.344.

How is the midpoint rule related to Simpson’s rule?

Simpson’s rule is a weighted average of the midpoint and trapezoidal rules: S₂ₙ = (2Mₙ + Tₙ) ÷ 3. The page shows Simpson’s estimate for the same n when n is even.

What can I type for f(x)?

Numbers, x, + − * / ^, brackets and functions such as sqrt, sin, cos, tan, exp, ln, log10 and abs, with pi and e. Angles are in radians.