{
  "id": "simpsons-rule",
  "version": "183558700517",
  "status": "published",
  "name": "Simpson's Rule Calculator",
  "question": "How do I apply Simpson's rule?",
  "summary": "Estimates a definite integral ∫ f(x) dx from a to b with Simpson’s rule and n even subintervals, beside the midpoint and trapezoidal rules, with every point and weight.",
  "category": "math",
  "subcategory": "calculus",
  "url": "https://www.acalculator.org/math/simpsons-rule-calculator",
  "markdown": "https://www.acalculator.org/math/simpsons-rule-calculator.md",
  "kind": "function",
  "method": "Sₙ = Δx/3 × [f(x₀) + 4f(x₁) + 2f(x₂) + 4f(x₃) + … + 4f(xₙ₋₁) + f(xₙ)], Δx = (b − a) ÷ n, n even.",
  "assumptions": [
    "n is even for Simpson’s rule; the midpoint and trapezoidal rules take any n from 1 to 1,000.",
    "The points xᵢ = a + iΔx 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; Simpson’s rule needs an even number.",
        "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": "sqrt(1 + x^2)",
      "a": 1,
      "b": 4,
      "n": 6,
      "rule": "simpson"
    },
    "outputs": {
      "estimate": 8.145943734514185,
      "simpson": 8.145943734514185,
      "midpoint": 8.143073112905324,
      "trapezoid": 8.151209108801526,
      "dx": 0.5,
      "steps": "x₀ = 1: f = 1.414213562, weight 1; x₁ = 1.5: f = 1.802775638, weight 4; x₂ = 2: f = 2.236067977, weight 2; x₃ = 2.5: f = 2.692582404, weight 4; x₄ = 3: f = 3.16227766, weight 2; x₅ = 3.5: f = 3.640054945, weight 4; x₆ = 4: f = 4.123105626, weight 1",
      "name": "Simpson’s rule"
    },
    "text": "The Simpson’s rule estimate of the integral of sqrt(1 + x^2) from 1 to 4 with n = 6 is 8.145943735."
  },
  "examples": [
    {
      "given": {
        "f": "sqrt(1 + x^2)",
        "a": 1,
        "b": 4,
        "n": 6,
        "rule": "simpson"
      },
      "expect": {
        "estimate": 8.145943734514185,
        "midpoint": 8.143073112905324,
        "trapezoid": 8.151209108801526,
        "dx": 0.5
      },
      "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.46: S₆ ≈ 8.14594; Example 3.40: M₆ ≈ 8.1431); Python 3 with exact nodes"
    },
    {
      "given": {
        "f": "x^3",
        "a": 0,
        "b": 1,
        "n": 2,
        "rule": "simpson"
      },
      "expect": {
        "estimate": 0.25,
        "simpson": 0.25,
        "dx": 0.5
      },
      "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.45: S₂ = 1/4)"
    },
    {
      "given": {
        "f": "x^2",
        "a": 0,
        "b": 1,
        "n": 4,
        "rule": "trapezoid"
      },
      "expect": {
        "estimate": 0.34375,
        "midpoint": 0.328125,
        "simpson": 0.3333333333333333,
        "steps": "x₀ = 0: f = 0, weight 1; x₁ = 0.25: f = 0.0625, weight 2; x₂ = 0.5: f = 0.25, weight 2; x₃ = 0.75: f = 0.5625, weight 2; x₄ = 1: f = 1, weight 1"
      },
      "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.41: T₄ = 11/32; Example 3.39: M₄ = 21/64)"
    }
  ],
  "sources": [
    "OpenStax, Calculus Volume 2, §3.6 Numerical Integration (the midpoint, trapezoidal and Simpson’s rules, Theorems 3.3 to 3.6, their error bounds, and Examples 3.39 to 3.46). https://openstax.org/books/calculus-volume-2/pages/3-6-numerical-integration (retrieved 2026-10-02)"
  ],
  "related": [
    "midpoint-rule",
    "integral",
    "area-between-curves"
  ],
  "changelog": []
}
