Approximate Integration
Author: Jamie Mulholland

To approximate the definite integral we split the region up into many thin slices.  For each slice we may approximate its area using rectandles, in which case we could either use right-endpoints, left-endpoints, or midpoints to work out the height of the approximating rectangle (seen in blue).  We could also use trapezoids to approximate each slice (seen in red). Drag the slider labeled n to increase the number of slices used.

On the other hand, we may group two sub-intervals together and use a parabola to approximate the top of the slice. This is a technique known as Simpson's Method (or Simpson's Rule).

If you wish to change the function f, say to sin(x), then just type f(x)=sin(x) in the input field at the bottom of the applet.

Left Sum

Midpoint

Right Sum

Rectangles (Right, Left, Midpoint)

Number of rectangles

Definite Integral

Trapezoid Rule

show errors

Simpson's Rule (for n even)

p = 0 (slider from 0 to 1, step 0.1)
B = Point(xAxis)
A = Point(xAxis)
f(x) = x^(2.0)
n = 4 (slider from 1 to 50, step 1)
a: x(A)
b: x(B)
c = LowerSum(f, a, b, n)
g(x) = f(a + p * (b - a) / n + floor((x - a) * n / (b - a) + 1.0E-4) * (b - a) / n)
d = LowerSum(g, a, b, n)
T1: "position=" + p
T6: "a = " + a
T7: "b = " + b
LA = Segment(A, (a, f(a)))
LB = Segment(B, (b, f(b)))
rectangles = true
L = Sequence(f(a + (i - 1.0 + p) * (b - a) / n), i, 1.0, n)
RS: Sum[L] * (b - a) / n
actualarea = Integral(f, a, b)
integral = false
trapezoidsum = TrapezoidalSum(f, a, b, n)
trapezoid = false
T5: "Rectangle Area Sum = " + RS
text3: "Trapezoid area sum = " + trapezoidsum
showerrors = true
errorR: "|E_{Rectangle}| =" + (abs(actualarea - RS))
errorT: "|E_{T}| =" + (abs(actualarea - trapezoidsum))
Δx: (b - a) / n
text4: "\Delta x = " + Δx
X = Sequence(a + i * Δx, i, 0.0, n)
S = Sequence(Determinant[{{Element[X, 2.0 * i - 1.0]^(2.0), Element[X, 2.0 * i - 1.0], 1.0}, {Element[X, 2.0 * i]^(2.0), Element[X, 2.0 * i], 1.0}, {Element[X, 2.0 * i + 1.0]^(2.0), Element[X, 2.0 * i + 1.0], 1.0}}], i, 1.0, n / 2.0, 1.0)
P = Sequence(Determinant[{{Element[X, 2.0 * i - 1.0], f(Element[X, 2.0 * i - 1.0]), 1.0}, {Element[X, 2.0 * i], f(Element[X, 2.0 * i]), 1.0}, {Element[X, 2.0 * i + 1.0], f(Element[X, 2.0 * i + 1.0]), 1.0}}], i, 1.0, n / 2.0, 1.0)
Q = Sequence(Determinant[{{Element[X, 2.0 * i - 1.0]^(2.0), f(Element[X, 2.0 * i - 1.0]), 1.0}, {Element[X, 2.0 * i]^(2.0), f(Element[X, 2.0 * i]), 1.0}, {Element[X, 2.0 * i + 1.0]^(2.0), f(Element[X, 2.0 * i + 1.0]), 1.0}}], i, 1.0, n / 2.0, 1.0)
R = Sequence(Determinant[{{Element[X, 2.0 * i - 1.0]^(2.0), Element[X, 2.0 * i - 1.0], f(Element[X, 2.0 * i - 1.0])}, {Element[X, 2.0 * i]^(2.0), Element[X, 2.0 * i], f(Element[X, 2.0 * i])}, {Element[X, 2.0 * i + 1.0]^(2.0), Element[X, 2.0 * i + 1.0], f(Element[X, 2.0 * i + 1.0])}}], i, 1.0, n / 2.0, 1.0)
simp = Sequence(If[x ≥ Element[X, 2.0 * i - 1.0] ∧ x ≤ Element[X, 2.0 * i + 1.0], -1.0 / Element[S, i] * (Element[P, i] * x^(2.0) - Element[Q, i] * x - Element[R, i])], i, 1.0, n / 2.0)
simpsonpieces = Sequence(Integral[Element[simp, i], Element[X, 2.0 * i - 1.0], Element[X, 2.0 * i + 1.0]], i, 1.0, n / 2.0)
simparea = If(Mod[n, 2.0] ≟ 0.0, Sum[simpsonpieces], "undefined")
simpson = false
text5: "Simpson's Rule Sum = " + simparea
text6: "|E_{S}| =" + (abs(actualarea - simparea))
simpsonpiece1 = Integral(Element[simp, 1.0], Element[X, 1.0], Element[X, 3.0])
simpsonpiece2 = Integral(Element[simp, 2.0], Element[X, 3.0], Element[X, 5.0])
simpsonpiece3 = Integral(Element[simp, 3.0], Element[X, 5.0], Element[X, 7.0])
simpsonpiece4 = Integral(Element[simp, 4.0], Element[X, 7.0], Element[X, 9.0])
simpsonpiece5 = Integral(Element[simp, 5.0], Element[X, 9.0], Element[X, 11.0])
simpsonpiece6 = Integral(Element[simp, 6.0], Element[X, 11.0], Element[X, 13.0])
simpsonpiece7 = Integral(Element[simp, 7.0], Element[X, 13.0], Element[X, 15.0])
simpsonpiece8 = Integral(Element[simp, 8.0], Element[X, 15.0], Element[X, 17.0])
simpsonpiece9 = Integral(Element[simp, 9.0], Element[X, 17.0], Element[X, 19.0])
simpsonpiece10 = Integral(Element[simp, 10.0], Element[X, 19.0], Element[X, 21.0])
text2: "\int_{" + a + "}^{" + b + "} " + f + "dx = " + actualarea