{
  "id": "midpoint-rule",
  "version": "e83e1e62a11b",
  "status": "published",
  "name": "Midpoint Rule Calculator",
  "question": "How do I use the midpoint rule?",
  "summary": "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.",
  "category": "math",
  "subcategory": "calculus",
  "url": "https://www.acalculator.org/math/midpoint-rule-calculator",
  "markdown": "https://www.acalculator.org/math/midpoint-rule-calculator.md",
  "kind": "function",
  "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."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "f": {
        "title": "f(x)",
        "description": "The function to integrate, in x, for example x^2, sqrt(1 + x^2) or sin(x).",
        "type": "string",
        "maxLength": 200
      },
      "a": {
        "title": "Lower limit (a)",
        "description": "Where the integral starts.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "b": {
        "title": "Upper limit (b)",
        "description": "Where the integral ends; it may be below a.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "n": {
        "title": "Subintervals (n)",
        "description": "How many equal pieces [a, b] is cut into.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000
      },
      "rule": {
        "title": "Rule",
        "description": "Which rule heads the answer; the other two are shown below for comparison.",
        "type": "string",
        "enum": [
          "simpson",
          "midpoint",
          "trapezoid"
        ]
      }
    }
  },
  "outputs": {
    "estimate": {
      "label": "Estimate of the integral",
      "description": "The chosen rule’s estimate of ∫ₐᵇ f(x) dx.",
      "format": "number"
    },
    "simpson": {
      "label": "Simpson’s rule (Sₙ)",
      "description": "Δx/3 × [f(x₀) + 4f(x₁) + 2f(x₂) + … + 4f(xₙ₋₁) + f(xₙ)]; needs an even n.",
      "format": "number"
    },
    "midpoint": {
      "label": "Midpoint rule (Mₙ)",
      "description": "Δx × [f(m₁) + f(m₂) + … + f(mₙ)], with mᵢ the middle of each piece.",
      "format": "number"
    },
    "trapezoid": {
      "label": "Trapezoidal rule (Tₙ)",
      "description": "Δx/2 × [f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)].",
      "format": "number"
    },
    "dx": {
      "label": "Width Δx",
      "description": "(b − a) ÷ n, exact from the typed decimals.",
      "format": "number"
    },
    "steps": {
      "label": "Points used",
      "description": "Each point of the chosen rule with f there and its weight, for n up to 20.",
      "format": "text"
    },
    "name": {
      "label": "Rule",
      "description": "The rule that heads the answer.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "f": "x^2",
      "a": 0,
      "b": 1,
      "n": 4,
      "rule": "midpoint"
    },
    "outputs": {
      "estimate": 0.328125,
      "simpson": 0.3333333333333333,
      "midpoint": 0.328125,
      "trapezoid": 0.34375,
      "dx": 0.25,
      "steps": "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",
      "name": "midpoint rule"
    },
    "text": "The midpoint rule estimate of the integral of x^2 from 0 to 1 with n = 4 is 0.328125."
  },
  "examples": [
    {
      "given": {
        "f": "x^2",
        "a": 0,
        "b": 1,
        "n": 4,
        "rule": "midpoint"
      },
      "expect": {
        "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)"
    },
    {
      "given": {
        "f": "sqrt(1 + x^2)",
        "a": 1,
        "b": 4,
        "n": 6,
        "rule": "midpoint"
      },
      "expect": {
        "estimate": 8.143073112905324,
        "simpson": 8.145943734514185
      },
      "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); Python 3 with exact nodes"
    },
    {
      "given": {
        "f": "sin(x)",
        "a": 0,
        "b": 3.141592653589793,
        "n": 4,
        "rule": "midpoint"
      },
      "expect": {
        "estimate": 2.052344305954062
      },
      "source": "hand calculation in content.mdx: (π/4)(sin(π/8) + sin(3π/8) + sin(5π/8) + sin(7π/8)); OpenStax, Calculus Volume 2, §3.6 Numerical Integration, https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (retrieved 2026-10-02); Python 3"
    }
  ],
  "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)"
  ],
  "related": [
    "simpsons-rule",
    "integral",
    "area-between-curves"
  ],
  "changelog": []
}
