show estimates

x_0

x_1

x_2

x_3

x_4

x_5

x_6

x_7

x_8

x_9

x_{10}

show rectangles

b = 2
a = -1
n = 2 (slider from 2 to nmax, step 1)
f(x) = x + ℯ^((-2 * x))
side = 0 (slider from 0 to 1, step 1)
dx: (b - a) / n
ncut = Min(n, 10)
fpoints = Sequence((a + ((i + side) * dx), f(a + ((i + side) * dx))), i, 0, n)
flines = Sequence(Segment[Element[fpoints, i] - (side * (dx, 0)), Element[fpoints, i] + ((1 - side) * (dx, 0))], i, 1, n)
midpoints = Zip(Midpoint[a], a, flines)
terms = Sequence((dx * y(Element[midpoints, i])), i, 1, n)
xmax = 2.2
xmin = -1.2
ymax = 11
ymin = -2
side_text = If(side ≟ 0, "Left", "Right")
estimate_text: "" + side_text + "-hand estimate"
psums = Sequence(Sum[terms, i], i, 1, ncut)
xpoints = Sequence((a + (dx * i), 0), i, 0, ncut)
show_estimates = true
nmax = 100
fshow(x) = If[a ≤ x ≤ b, f(x)]
text4: "Δx=" + dx + ""
l1: "" + (y(Element[midpoints, 1])) + ""
l10: "" + (y(Element[midpoints, 10])) + ""
l2: "" + (y(Element[midpoints, 2])) + ""
l3: "" + (y(Element[midpoints, 3])) + ""
l4: "" + (y(Element[midpoints, 4])) + ""
l5: "" + (y(Element[midpoints, 5])) + ""
l6: "" + (y(Element[midpoints, 6])) + ""
l7: "" + (y(Element[midpoints, 7])) + ""
l8: "" + (y(Element[midpoints, 8])) + ""
l9: "" + (y(Element[midpoints, 9])) + ""
rsum = RectangleSum(f, a, b, n, side)
show_rectangles = true
fxdx_text: "f(x_{i" + (If[side ≟ 0, "-1", ""]) + "})\Delta x"
fx_text: "f(x_{i" + (If[side ≟ 0, "-1", ""]) + "})"
chart: "\small\begin{array}{cccc}\text{Interval}&\text{Height}&\text{Area}&\text{Total Area}\\" + (Sum[Sequence[x(Element[xpoints, i]) + " \text{ to } " + x(Element[xpoints, i + 1]) + "&" + y(Element[midpoints, i]) + "&" + Element[terms, i] + "&" + Element[psums, i] + "\\", i, 1, ncut]]) + "\end{array}"
areas = Zip((y(a) * dx), a, fpoints)
A1: "" + (Element[areas, 1]) + ""
A2: "" + (Element[areas, 2]) + ""
A3: "" + (Element[areas, 3]) + ""
A4: "" + (Element[areas, 4]) + ""
A6: "" + (Element[areas, 6]) + ""
A7: "" + (Element[areas, 7]) + ""
A8: "" + (Element[areas, 8]) + ""
A9: "" + (Element[areas, 9]) + ""
A10: "" + (Element[areas, 10]) + ""
area_actual = Integral(f, a, b)
A5: "" + (Element[areas, 5]) + ""
sumtexttot: "\displaystyle I_" + (If[side ≟ 0, "l", "r"]) + " = \sum_{i=1}^{" + n + " } f(t_{i " + If[side ≟ 0, "-1", ""] + "})\Delta x =" + rsum + ""