Riemann Sums
Author: John Maharry

f = 2 (slider from -10 to 10, step 0.01)
e = -2 (slider from -10 to 10, step 0.01)
d = 1 (slider from -10 to 10, step 0.01)
c = 0 (slider from -10 to 10, step 0.01)
n = 7 (slider from 1 to 50, step 1)
A = Point(xAxis)
B = Point(xAxis)
a: x(A)
g(x) = c * x^(3.0) + d * x^(2.0) + e * x + f
b: x(B)
U = UpperSum(g, a, b, n)
L = LowerSum(g, a, b, n)
LowerSum = false
UpperSum = false
MidPointSum = false
FunctionSilders = true
delta: (b - a) / n
LeftLines1 = Sequence(Segment[(x(A) + (i - 1.0) * delta, 0.0), (x(A) + (i - 1.0) * delta, g(x(A) + (i - 1.0) * delta))], i, 1.0, n)
LeftLines2 = Sequence(Segment[(x(A) + (i - 1.0) * delta, g(x(A) + (i - 1.0) * delta)), (x(A) + i * delta, g(x(A) + (i - 1.0) * delta))], i, 1.0, n)
LeftLines3 = Sequence(Segment[(x(A) + i * delta, g(x(A) + (i - 1.0) * delta)), (x(A) + i * delta, 0.0)], i, 1.0, n)
LeftSum = true
LeftPolygons = Sequence(Polygon[(x(A) + (i - 1.0) * delta, 0.0), (x(A) + (i - 1.0) * delta, g(x(A) + (i - 1.0) * delta)), (x(A) + i * delta, g(x(A) + (i - 1.0) * delta)), (x(A) + i * delta, 0.0)], i, 1.0, n)
RightSum = true
Trapezoid = false
RightPolygons = Sequence(Polygon[(x(A) + (i - 1.0) * delta, 0.0), (x(A) + (i - 1.0) * delta, g(x(A) + i * delta)), (x(A) + i * delta, g(x(A) + i * delta)), (x(A) + i * delta, 0.0)], i, 1.0, n)
RightLines1 = Sequence(Segment[(x(A) + (i - 1.0) * delta, 0.0), (x(A) + (i - 1.0) * delta, g(x(A) + i * delta))], i, 1.0, n)
RightLines2 = Sequence(Segment[(x(A) + (i - 1.0) * delta, g(x(A) + i * delta)), (x(A) + i * delta, g(x(A) + i * delta))], i, 1.0, n)
LSum = 0
RightLines3 = Sequence(Segment[(x(A) + i * delta, g(x(A) + i * delta)), (x(A) + i * delta, 0.0)], i, 1.0, n)
MidPolygons = Sequence(Polygon[(x(A) + (i - 1.0) * delta, 0.0), (x(A) + (i - 1.0) * delta, g(x(A) + (2.0 * i - 1.0) * delta / 2.0)), (x(A) + i * delta, g(x(A) + (2.0 * i - 1.0) * delta / 2.0)), (x(A) + i * delta, 0.0)], i, 1.0, n)
MidLines1 = Sequence(Segment[(x(A) + (i - 1.0) * delta, 0.0), (x(A) + (i - 1.0) * delta, g(x(A) + (2.0 * i - 1.0) * delta / 2.0))], i, 1.0, n)
MidLines2 = Sequence(Segment[(x(A) + (i - 1.0) * delta, g(x(A) + (2.0 * i - 1.0) * delta / 2.0)), (x(A) + i * delta, g(x(A) + (2.0 * i - 1.0) * delta / 2.0))], i, 1.0, n)
MidLines3 = Sequence(Segment[(x(A) + i * delta, g(x(A) + (2.0 * i - 1.0) * delta / 2.0)), (x(A) + i * delta, 0.0)], i, 1.0, n)
TrapPolygons = Sequence(Polygon[(x(A) + (i - 1.0) * delta, 0.0), (x(A) + (i - 1.0) * delta, g(x(A) + (i - 1.0) * delta)), (x(A) + i * delta, g(x(A) + i * delta)), (x(A) + i * delta, 0.0)], i, 1.0, n)
TrapLines1 = Sequence(Segment[(x(A) + (i - 1.0) * delta, 0.0), (x(A) + (i - 1.0) * delta, g(x(A) + (i - 1.0) * delta))], i, 1.0, n)
TrapLines2 = Sequence(Segment[(x(A) + (i - 1.0) * delta, g(x(A) + (i - 1.0) * delta)), (x(A) + i * delta, g(x(A) + i * delta))], i, 1.0, n)
TrapLines3 = Sequence(Segment[(x(A) + i * delta, g(x(A) + i * delta)), (x(A) + i * delta, 0.0)], i, 1.0, n)
Exact = Integral(g(x), a, b)
rightFlag = Sequence(If[g(x(A) + i * delta) ≥ 0.0, 1.0, -1.0], i, 1.0, n)
leftFlag = Sequence(If[g(x(A) + (i - 1.0) * delta) ≥ 0.0, 1.0, -1.0], i, 1.0, n)
midFlag = Sequence(If[g(x(A) + (2.0 * i - 1.0) * delta / 2.0) ≥ 0.0, 1.0, -1.0], i, 1.0, n)
T1: "a = " + a
T2: "b = " + b
text1: "g(x) = " + g