{
  "id": "riemann-sum",
  "version": "5d8634a249f7",
  "status": "published",
  "name": "Riemann Sum Calculator",
  "question": "What is the Riemann sum of f(x)?",
  "summary": "Finds the left, right and midpoint Riemann sums of f(x) on [a, b] with n equal subintervals, with every sample point.",
  "category": "math",
  "subcategory": "calculus",
  "url": "https://www.acalculator.org/math/riemann-sum-calculator",
  "markdown": "https://www.acalculator.org/math/riemann-sum-calculator.md",
  "kind": "function",
  "method": "Δx = (b − a)/n. Lₙ = Δx Σ f(a + (i − 1)Δx), Rₙ = Δx Σ f(a + iΔx), Mₙ = Δx Σ f(a + (i − ½)Δx), i = 1 … n.",
  "assumptions": [
    "Sample points are exact from the typed decimals before f is evaluated.",
    "Angles in radians."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "f": {
        "title": "f(x)",
        "description": "The function, in x.",
        "type": "string",
        "maxLength": 200
      },
      "a": {
        "title": "From x = a",
        "description": "The left end.",
        "type": "number",
        "minimum": -1000000000,
        "maximum": 1000000000
      },
      "b": {
        "title": "To x = b",
        "description": "The right end, more than 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": "Sample point",
        "description": "Which point of each subinterval sets the rectangle height.",
        "type": "string",
        "enum": [
          "left",
          "right",
          "midpoint"
        ]
      }
    }
  },
  "outputs": {
    "sum": {
      "label": "Riemann sum",
      "description": "Σ f(xᵢ*) Δx with the chosen sample points.",
      "format": "number"
    },
    "left": {
      "label": "Left sum Lₙ",
      "description": "Heights at the left ends.",
      "format": "number"
    },
    "right": {
      "label": "Right sum Rₙ",
      "description": "Heights at the right ends.",
      "format": "number"
    },
    "midpoint": {
      "label": "Midpoint sum Mₙ",
      "description": "Heights at the middles.",
      "format": "number"
    },
    "dx": {
      "label": "Width Δx",
      "description": "(b − a) ÷ n, exact from the typed decimals.",
      "format": "number"
    },
    "steps": {
      "label": "Rectangles",
      "description": "Each sample point and f there, for n up to 20.",
      "format": "text"
    },
    "name": {
      "label": "Rule",
      "description": "The sample point used.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "f": "x^2",
      "a": 0,
      "b": 2,
      "n": 4,
      "rule": "left"
    },
    "outputs": {
      "sum": 1.75,
      "left": 1.75,
      "right": 3.75,
      "midpoint": 2.625,
      "dx": 0.5,
      "steps": "x1* = 0: f = 0; x2* = 0.5: f = 0.25; x3* = 1: f = 1; x4* = 1.5: f = 2.25",
      "name": "left"
    },
    "text": "The left Riemann sum of x^2 from 0 to 2 with n = 4 is 1.75."
  },
  "examples": [
    {
      "given": {
        "f": "x^2",
        "a": 0,
        "b": 2,
        "n": 4,
        "rule": "left"
      },
      "expect": {
        "sum": 1.75,
        "left": 1.75,
        "right": 3.75,
        "midpoint": 2.625,
        "dx": 0.5
      },
      "source": "OpenStax, Calculus Volume 1, section 5.1 Approximating Areas (https://openstax.org/books/calculus-volume-1/pages/5-1-approximating-areas), Example 5.4: L₄ = 1.75 and R₄ = 3.75; M₄ by hand in content.mdx"
    },
    {
      "given": {
        "f": "10 - x^2",
        "a": 1,
        "b": 2,
        "n": 4,
        "rule": "right"
      },
      "expect": {
        "sum": 7.28125
      },
      "source": "OpenStax, Calculus Volume 1, section 5.1 Approximating Areas (https://openstax.org/books/calculus-volume-1/pages/5-1-approximating-areas), Example 5.5: the lower sum (right ends) is about 7.28; exact 233/32 by hand and Python 3",
      "tolerance": 1e-12
    },
    {
      "given": {
        "f": "(x - 1)^3 + 4",
        "a": 0,
        "b": 2,
        "n": 4,
        "rule": "left"
      },
      "expect": {
        "left": 7.5,
        "right": 8.5
      },
      "source": "OpenStax, Calculus Volume 1, section 5.1 Approximating Areas (https://openstax.org/books/calculus-volume-1/pages/5-1-approximating-areas), the opening example (Figure 5.7 to 5.9): L₄ = 7.5, R₄ = 8.5"
    }
  ],
  "sources": [
    "OpenStax, Calculus Volume 1, section 5.1 Approximating Areas (retrieved 2026-10-03): https://openstax.org/books/calculus-volume-1/pages/5-1-approximating-areas"
  ],
  "related": [
    "midpoint-rule",
    "simpsons-rule",
    "integral",
    "summation"
  ],
  "changelog": []
}
