# How do I use the midpoint rule?

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.

- Page: https://www.acalculator.org/math/midpoint-rule-calculator
- JSON spec: https://www.acalculator.org/math/midpoint-rule-calculator.json
- Version: e83e1e62a11b

## Default answer

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.

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| f | f(x) | The function to integrate, in x, for example x^2, sqrt(1 + x^2) or sin(x). |
| a | Lower limit (a) | Where the integral starts. |
| b | Upper limit (b) | Where the integral ends; it may be below a. |
| n | Subintervals (n) | How many equal pieces [a, b] is cut into. |
| rule | Rule | Which rule heads the answer; the other two are shown below for comparison. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| estimate | Estimate of the integral | The chosen rule’s estimate of ∫ₐᵇ f(x) dx. |
| simpson | Simpson’s rule (Sₙ) | Δx/3 × [f(x₀) + 4f(x₁) + 2f(x₂) + … + 4f(xₙ₋₁) + f(xₙ)]; needs an even n. |
| midpoint | Midpoint rule (Mₙ) | Δx × [f(m₁) + f(m₂) + … + f(mₙ)], with mᵢ the middle of each piece. |
| trapezoid | Trapezoidal rule (Tₙ) | Δx/2 × [f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)]. |
| dx | Width Δx | (b − a) ÷ n, exact from the typed decimals. |
| steps | Points used | Each point of the chosen rule with f there and its weight, for n up to 20. |
| name | Rule | The rule that heads the answer. |

## Method

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

## Assumptions

- 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.

## Worked examples

1. f = x^2, a = 0, b = 1, n = 4, rule = midpoint gives estimate = 0.328125, trapezoid = 0.34375, dx = 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 = sqrt(1 + x^2), a = 1, b = 4, n = 6, rule = midpoint gives estimate = 8.143073, simpson = 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 = sin(x), a = 0, b = 3.141593, n = 4, rule = midpoint gives estimate = 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).

## FAQ

### 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.

## Sources

- OpenStax, Calculus Volume 2, §3.6 Numerical Integration (the midpoint rule, Theorem 3.3, its error bound M(b − a)³ ÷ 24n², and Examples 3.39 and 3.40: M₄ = 21/64 for ∫₀¹ x² dx and M₆ ≈ 8.1431 for ∫₁⁴ √(1 + x²) dx). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (retrieved 2026-10-02)
