{
  "id": "trapezoidal-rule",
  "version": "6cde2fba25d9",
  "status": "published",
  "name": "Trapezoidal Rule Calculator",
  "question": "What does the trapezoidal rule give?",
  "summary": "Approximates the definite integral of f(x) from a to b with the trapezoidal rule in n subintervals, with every point, the midpoint rule and Simpson’s rule for comparison.",
  "category": "math",
  "subcategory": "calculus",
  "url": "https://www.acalculator.org/math/trapezoidal-rule-calculator",
  "markdown": "https://www.acalculator.org/math/trapezoidal-rule-calculator.md",
  "kind": "schedule",
  "method": "Δx = (b − a) ÷ n; xᵢ = a + iΔx; Tₙ = Δx/2 × (f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)); Mₙ = Δx × Σ f(a + (i − ½)Δx); Sₙ = Δx/3 × (f(x₀) + 4f(x₁) + 2f(x₂) + … + 4f(xₙ₋₁) + f(xₙ)).",
  "assumptions": [
    "f must have a real value at every point used (and at every midpoint).",
    "xᵢ comes exactly from the typed decimals; f and the sums are in double precision.",
    "1 to 1,000 subintervals; a and b from −10⁹ to 10⁹, and different. Simpson’s rule needs an even n."
  ],
  "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 or sqrt(1 + x^2).",
        "type": "string",
        "maxLength": 200
      },
      "a": {
        "title": "Lower limit (a)",
        "description": "Where the interval starts.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "b": {
        "title": "Upper limit (b)",
        "description": "Where the interval ends; it may be below a.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "n": {
        "title": "Subintervals (n)",
        "description": "How many equal subintervals (trapezoids), from 1 to 1,000.",
        "type": "integer",
        "minimum": 1,
        "maximum": 1000
      }
    }
  },
  "outputs": {
    "trapezoid": {
      "label": "Trapezoidal rule Tₙ",
      "description": "Δx/2 × (f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)).",
      "format": "number"
    },
    "dx": {
      "label": "Δx",
      "description": "(b − a) ÷ n, exactly from the typed decimals.",
      "format": "number"
    },
    "midpoint": {
      "label": "Midpoint rule Mₙ",
      "description": "Δx × (f(m₁) + … + f(mₙ)), where mᵢ is the middle of each subinterval.",
      "format": "number"
    },
    "simpson": {
      "label": "Simpson’s rule Sₙ",
      "description": "Δx/3 × (f(x₀) + 4f(x₁) + 2f(x₂) + … + 4f(xₙ₋₁) + f(xₙ)); for even n only.",
      "format": "number"
    },
    "sum": {
      "label": "Weighted sum",
      "description": "f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ), before × Δx/2.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "f": "x^2",
      "a": 0,
      "b": 1,
      "n": 4
    },
    "outputs": {
      "trapezoid": 0.34375,
      "dx": 0.25,
      "midpoint": 0.328125,
      "simpson": 0.3333333333333333,
      "sum": 2.75
    },
    "text": "The trapezoidal rule with n = 4 gives 0.34375 for the integral of x^2 from 0 to 1."
  },
  "examples": [
    {
      "given": {
        "f": "x^2",
        "a": 0,
        "b": 1,
        "n": 4
      },
      "expect": {
        "trapezoid": 0.34375,
        "midpoint": 0.328125,
        "dx": 0.25,
        "simpson": 0.3333333333333333
      },
      "source": "OpenStax, Calculus Volume 2, §3.6 Numerical Integration (midpoint rule, trapezoidal rule, Simpson’s rule; Examples 3.39, 3.41 and 3.45). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (T₄ = 11/32, M₄ = 21/64)"
    },
    {
      "given": {
        "f": "x^3",
        "a": 0,
        "b": 1,
        "n": 2
      },
      "expect": {
        "simpson": 0.25,
        "trapezoid": 0.3125
      },
      "source": "OpenStax, Calculus Volume 2, §3.6 Numerical Integration (midpoint rule, trapezoidal rule, Simpson’s rule; Examples 3.39, 3.41 and 3.45). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (S₂ = 1/4); hand calculation in content.mdx: T₂ = 0.25 × (0 + 0.25 + 1) = 0.3125"
    },
    {
      "given": {
        "f": "sqrt(1 + x^2)",
        "a": 1,
        "b": 4,
        "n": 6
      },
      "expect": {
        "midpoint": 8.143073112905324,
        "simpson": 8.145943734514185,
        "trapezoid": 8.151209108801526
      },
      "source": "OpenStax, Calculus Volume 2, §3.6 Numerical Integration (midpoint rule, trapezoidal rule, Simpson’s rule; Examples 3.39, 3.41 and 3.45). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (M₆ ≈ 8.1431, S₆ ≈ 8.14594); Python 3 from the same formulas: M₆ = 8.143073112905324, S₆ = 8.145943734514185, T₆ = 8.151209108801526",
      "tolerance": 1e-12
    }
  ],
  "sources": [
    "OpenStax, Calculus Volume 2, §3.6 Numerical Integration (midpoint rule Mₙ, trapezoidal rule Tₙ, Simpson’s rule Sₙ, error bounds; Examples 3.39 M₄ = 21/64, 3.40 M₆ ≈ 8.1431, 3.41 T₄ = 11/32, 3.45 S₂ = 1/4, 3.46 S₆ ≈ 8.14594). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (retrieved 2026-10-02)"
  ],
  "related": [
    "integral",
    "area-between-curves",
    "eulers-method",
    "summation"
  ],
  "changelog": []
}
