{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionadded",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionadded 1.12.0"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The composite Simpson's 1/3 method can be used to approximate the definite integral of a sampled input function "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "y(x)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The method assumes a quadratic relationship over the interval containing any three consecutive sampled points."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Consider three consecutive points: "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "(x_1, y_1), (x_2, y_2), (x_3, y_3)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Assuming a quadratic relationship over the three points, the integral over the subinterval between "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is given by formula (8) of "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\int_{x_1}^{x_2} y(x) dx\\ &= \\frac{x_2-x_1}{6}\\left[\\\n\\left\\{3-\\frac{x_2-x_1}{x_3-x_1}\\right\\} y_1 + \\\n\\left\\{3 + \\frac{(x_2-x_1)^2}{(x_3-x_2)(x_3-x_1)} + \\\n\\frac{x_2-x_1}{x_3-x_1}\\right\\} y_2\\\\\n- \\frac{(x_2-x_1)^2}{(x_3-x_2)(x_3-x_1)} y_3\\right]"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The integral between "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is given by swapping appearances of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The integral is estimated separately for each subinterval and then cumulatively summed to obtain the final result."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For samples that are equally spaced, the result is exact if the function is a polynomial of order three or less "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and the number of subintervals is even. Otherwise, the integral is exact for polynomials of order two or less."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Array API Standard Support"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "cumulative_simpson",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.integrate._quadrature:cumulative_simpson"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "SCIPY_ARRAY_API=1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "====================  ====================  ====================\nLibrary               CPU                   GPU\n====================  ====================  ====================\nNumPy                 ✅                     n/a                 \nCuPy                  n/a                   ✅                   \nPyTorch               ✅                     ✅                   \nJAX                   ⛔                     ⛔                   \nDask                  ⚠️ computes graph     n/a                 \n====================  ====================  ====================",
          "execution_status": null
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "See "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "dev-arrayapi",
                  "domain": null,
                  "role": "ref",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " for more information."
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "res",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The result of cumulative integration of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " along "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "initial"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None, the shape is such that the axis of integration has one less value than "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "initial"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is given, the shape is equal to that of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Cumulatively integrate y(x) using the composite Simpson's 1/3 rule. The integral of the samples at every point is calculated by assuming a quadratic relationship between each point and the two adjacent points."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "y",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Values to integrate. Requires at least one point along "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If two or fewer points are provided along "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", Simpson's integration is not possible and the result is calculated with "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "cumulative_trapezoid",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.integrate._quadrature:cumulative_trapezoid"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "x",
              "annotation": "array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The coordinate to integrate along. Must have the same shape as "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or must be 1D with the same length as "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " along "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must also be strictly increasing along "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None (default), integration is performed using spacing "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "dx"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " between consecutive elements in "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "dx",
              "annotation": "scalar or array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Spacing between elements of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Only used if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is None. Can either be a float, or an array with the same shape as "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", but of length one along "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Default is 1.0."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Specifies the axis to integrate along. Default is -1 (last axis)."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "initial",
              "annotation": "scalar or array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If given, insert this value at the beginning of the returned result, and add it to the rest of the result. Default is None, which means no value at "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "x[0]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is returned and "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "res",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": null,
                        "version": null,
                        "kind": "local",
                        "path": "res"
                      },
                      "kind": "local"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " has one element less than "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " along the axis of integration. Can either be a float, or an array with the same shape as "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "y"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", but of length one along "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/integrate/_quadrature.py",
  "item_line": 618,
  "item_type": "function",
  "aliases": [
    "scipy.integrate.cumulative_simpson"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy import integrate\nimport numpy as np\nimport matplotlib.pyplot as plt\nx = np.linspace(-2, 2, num=20)\ny = x**2\ny_int = integrate.cumulative_simpson(y, x=x, initial=0)\nfig, ax = plt.subplots()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.plot(x, y_int, 'ro', x, x**3/3 - (x[0])**3/3, 'b-')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.grid()\nplt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-35afedfc9810fe71.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe output of `cumulative_simpson` is similar to that of iteratively\ncalling `simpson` with successively higher upper limits of integration, but\nnot identical.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def cumulative_simpson_reference(y, x):\n    return np.asarray([integrate.simpson(y[:i], x=x[:i])\n                       for i in range(2, len(y) + 1)])\nrng = np.random.default_rng(354673834679465)\nx, y = rng.random(size=(2, 10))\nx.sort()\nres = integrate.cumulative_simpson(y, x=x)\nref = cumulative_simpson_reference(y, x)\nequal = np.abs(res - ref) < 1e-15\nequal  # not equal when `simpson` has even number of subintervals\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThis is expected: because `cumulative_simpson` has access to more\ninformation than `simpson`, it can typically produce more accurate\nestimates of the underlying integral over subintervals."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "cumulative_trapezoid",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.integrate._quadrature:cumulative_trapezoid"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "cumulative integration using the composite trapezoidal rule"
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "numpy.cumsum",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "numpy.cumsum"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "simpson",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.integrate._quadrature:simpson"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "integrator for sampled data using the Composite Simpson's Rule"
            }
          ]
        }
      ],
      "type": "func"
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "y",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "dx",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "1.0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "-1"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "initial",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "cumulative_simpson"
  },
  "references": [
    ".. [1] Wikipedia page: https://en.wikipedia.org/wiki/Simpson's_rule",
    ".. [2] Cartwright, Kenneth V. Simpson's Rule Cumulative Integration with",
    "        MS Excel and Irregularly-spaced Data. Journal of Mathematical",
    "        Sciences and Mathematics Education. 12 (2): 1-9"
  ],
  "qa": "scipy.integrate._quadrature:cumulative_simpson",
  "arbitrary": [],
  "local_refs": [
    "axis",
    "dx",
    "initial",
    "res",
    "x",
    "y"
  ]
}