Area under a curve

This is the method of Archimedes in which the x-interval is repeatedly bisected and nested polygons (Triangles) are created from corresponding ordinates on the curve.  The resulting approximation to the area under the curve is found by subtracting the sum of the polygons from the bounding trapezium.

Alter the n-slider to increase the number of nested polygons.

Drag Points A and B to alter the limits of intergation.

Individual Polygon Areas

Freq      Area

A = Point(xAxis)
B = Point(xAxis)
n = 1 (slider from 1 to 8, step 1)
f(x) = x^(2)
Polygons = Sequence(Sequence[Polygon[Sequence[(((2^(n) - (2 * k - d) * 2^(n - L)) * x(A) + (2 * k - d) * 2^(n - L) * x(B)) / 2^(n), f(((2^(n) - (2 * k - d) * 2^(n - L)) * x(A) + (2 * k - d) * 2^(n - L) * x(B)) / 2^(n))), d, 0, 2]], k, 1, 2^(L - 1)], L, 1, n)
PolygonPoints = Sequence(Sequence[Sequence[(((2^(n) - (2 * k - d) * 2^(n - L)) * x(A) + (2 * k - d) * 2^(n - L) * x(B)) / 2^(n), f(((2^(n) - (2 * k - d) * 2^(n - L)) * x(A) + (2 * k - d) * 2^(n - L) * x(B)) / 2^(n))), d, 0, 2], k, 1, 2^(L - 1)], L, 1, n)
TotalPolygonArea = Sum(Join[Polygons])
C = Point(PolygonPoints)
D = Point(PolygonPoints)
TrapeziumArea, a, b, c, d = Polygon(A, B, C, D)
AreaUnderCurve: TrapeziumArea - TotalPolygonArea
T_A = false
A_A = true
h = Integral(f, x(A), x(B))
AreaPercentageError: (AreaUnderCurve - h) * 100 / h
text4: "Area under Curve = " + AreaUnderCurve + " (" + AreaPercentageError + "% Error)"
text5: "Trapezium Area = " + TrapeziumArea + ""
C_A = false
PolyAreas = Sequence(Element[Polygons, k, 1], k, 1, n)
PolyNumber = Sequence(2^(k), k, 0, n - 1)
text1 = TableText({PolyNumber, PolyAreas}, "vc|_|")
AllPolyAreas = TableText({Join[Polygons]}, "vc|_|")
SumofPolys = Sum(PolyNumber)
text7: "Number of Polygons = " + SumofPolys + ""
text3: "Archimedes Polygons' Area = " + TotalPolygonArea + ""