b

a

x

n = 8 (slider from 1 to 100, step 1)
f'(x) = cos(x)
B = Point(xAxis)
b: x(B)
A = Point(xAxis)
X = Point(Segment[A, B])
a: x(A)
u(x) = a + x * (b - a) / n
k_x = If(X ≟ B, n - 1.0, floor((x(X) - a) * n / (b - a)))
r = OrthogonalLine(A, xAxis)
C = Point(r)
c: y(C)
P': (x(X), f'(u(k_x)))
campione = Sequence((u(k), f'(u(k))), k, 0.0, n)
scala = Function(f'(u(floor((x - a) * n / (b - a)))), a, b)
serie = Sequence((u(k), c + (b - a) * Sum[y(campione), k] / n), k, 0.0, n)
d = Line(Element[serie, k_x + 1.0], Element[serie, k_x + 2.0])
e = Segment(B, (b, f'(b)))
φ = Integral(f')
f(x) = φ(x) + c - φ(a)
D = (-1, 0)
g = Line(D, d)
Q = Intersect(g, yAxis)
h = Segment(D, Q)
i = Segment(P', Q)
suddivisione = Sequence((u(k), 0.0), k, 0.0, n)
plurirettangolo = Append(Sequence[Polygon[(u(k), 0.0), (u(k + 1.0), 0.0), (u(k + 1.0), f'(u(k))), (u(k), f'(u(k))), (u(k), 0.0)], k, 0.0, k_x - 1.0], Polygon[(u(k_x), 0.0), X, (x(X), f'(u(k_x))), (u(k_x), f'(u(k_x))), (u(k_x), 0.0)])
area_{con segno} = Sum(Append[Sequence[f'(u(k)) * (b - a) / n, k, 0.0, k_x - 1.0], f'(u(k_x)) * (x(X) - u(k_x))])
P: (x(X), c + area_{con segno})
Δy = Segment((x(P), c), P)
j = Segment(C, (x(P), c))
testo1: "area=" + area_{con segno} + ""
testo2: "Δy=" + (y(P) - c)