All formulas

Numerical methods

Composite Simpson's rule

num.simpsonAlso called simpson, simpsons rule, simps, simpson rule

S=h3(y0+4∑i=1my2i−1+2∑i=1m−1y2i+yn−1)S = \frac{h}{3}\left(y_{0} + 4\sum_{i=1}^{m} y_{2i-1} + 2\sum_{i=1}^{m-1} y_{2i} + y_{n-1}\right)

wherem=n−12m = \frac{n - 1}{2}

Integral estimate from an odd number n of equally spaced samples with spacing h: weights 1, 4, 2, 4, …, 2, 4, 1 times h/3. Exact for cubic polynomials.

Notation

yy

function values at equally spaced points y0 … yn−1

y ∈ ℝn

hh

spacing between points

h > 0 · default 1

nn

number of sample points (odd)

Size, at least 3, odd

SS

Result: the integral estimate

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    y=[0,1,4],h=1y = [0, 1, 4], h = 1

    Result

    S=83\displaystyle S = \frac{8}{3}

    ≈ 2.66666666667

  2. Given

    y=[0,1/8,1,27/8,8],h=0.5y = [0, 1/8, 1, 27/8, 8], h = 0.5

    Result

    S=4\displaystyle S = 4

    x3 on [0, 2]; Simpson's rule is exact for cubics.

  3. Given

    y=[1,1,1],h=2y = [1, 1, 1], h = 2

    Result

    S=4\displaystyle S = 4

Common mistakes

  • Swaps the weights 4 and 2

    Odd-indexed samples get weight 2 and even-indexed interior samples weight 4.

    Fix: Weight odd-indexed samples (y1, y3, …) by 4 and even-indexed interior samples by 2.

  • Uses h/6 in place of h/3

    The factor h/6 belongs to the single-panel form written with the full panel width 2h.

    Fix: Multiply by h/3, where h is the spacing between samples.

Source

  • DLMF, eqs. 3.5.6 and 3.5.7

    NIST Digital Library of Mathematical Functions. https://dlmf.nist.gov/ Release 1.2.8 of 2026-09-15. F. W. J. Olver, A. B. Olde Daalhuis, D. W. Lozier, B. I. Schneider, R. F. Boisvert, C. W. Clark, B. R. Miller, B. V. Saunders, H. S. Cohl, and M. A. McClain, eds.

    dlmf.nist.gov