f(x)=

a=

b=

+

-

↑

↓

+

-

↑

↓

exact

n=

p = 0
f(x) = x^(3) / 3 - 2 * x^(2) + 12
a = -2
b = 7
n = 9
dx: (b - a) / n
K = (-1.600943396226415, 55.66972109505507)
fpoints = Sequence((a + (i + p) * dx, f(a + (i + p) * dx)), i, 0, n)
flines = Sequence(Segment[Element[fpoints, i] - p * (dx, 0), Element[fpoints, i] + (1 - p) * (dx, 0)], i, 1, n)
D = (-1.600943396226415, 0)
G = Element(First[RemoveUndefined[Sequence[Intersect[Element[flines, i], OrthogonalLine[(Max[a, Min[b, x(D)]], 0), xAxis]], i, 1, n]]], 1)
y0 = 0
fint0 = Integral(f)
fvals = Sequence(f(a + (i + p) * dx), i, 0, n)
fint = Function(fint0(x) - fint0(a) + y0, a, b)
cumsum: Sequence[Sum[fvals, i], i, 0, n] * dx
feest = Sequence((a + dx * i, y0 + Element[cumsum, i + 1]), i, 0, n)
feconnect = PolyLine(feest)
g: x = a
h: x = b
inputBox1 = Textfield(f)
inputBox4 = Textfield(a)
inputBox5 = Textfield(b)
maxn = 5000
centery1 = 13.047618865966797
centery2 = 59.78606396628372
height1 = 15.625
height2 = 74.50580596923831
miny1: centery1 - height1
miny2: centery2 - height2
maxy2: centery2 + height2
maxy1: centery1 + height1
minx: a - (b - a) * 0.1
A = DynamicCoordinates(D, x(G), y(G))
E: (If[x(A) < b - dx, floor((x(A) - a) / dx) * dx + a, b - dx], y(A))
highlightseg1 = Segment(E, E + (dx, 0))
F = Intersect(OrthogonalLine[E, xAxis], feconnect)
highlightseg2 = Segment(F, F + dx * (1, y(E)))
c: x(E)
fc: y(E)
yc: y(F)
exact = false
ycp1: yc + fc * dx
J = Intersect(h, feconnect)
ytfinal: y(J)
yfinalexact: fint(b)
ytfinalerror: abs(ytfinal - yfinalexact)
poly1, e1, i, j, k = Polygon(E, E + (dx, 0), (x(E) + dx, 0), (x(E), 0))
fcdx: fc * dx
text3: "$f(" + (LaTeX[c]) + ")= " + (LaTeX[fc]) + "$
$\begin{align}\text{Area rect}&=f(" + (LaTeX[c]) + ")\Delta x\\
&= " + (LaTeX[fc]) + "\cdot " + (LaTeX[dx]) + "=" + (LaTeX[fcdx]) + "\end{align}$"
cp1: c + dx
text4: "$ \hat{A}(" + (LaTeX[cp1]) + ")= " + (LaTeX[ycp1]) + " $"
ycp1exact: fint(cp1)
ycp1errror: abs(ycp1 - ycp1exact)
text5: "$A(" + (LaTeX[cp1]) + ")=" + (LaTeX[ycp1exact]) + "$
Error: $|" + (LaTeX[ycp1]) + "-" + (LaTeX[ycp1exact]) + "|=" + (LaTeX[ycp1errror]) + "$"
text2: "$\Delta x=" + (LaTeX[dx]) + "$"
C = Intersect(OrthogonalLine[(Max[a, Min[b, x(K)]], 0), xAxis], feconnect)
maxx: b + (b - a) * 0.1
rsum = RectangleSum(f, a, b, n, p)
B = DynamicCoordinates(K, x(C), y(C))
n1 = 9
inputBox2 = Textfield(n1)
defint = Integral(f, a, b)