Hi, sorry I’m new to julia and I’m stuck trying to make based on the function that calculates the area of a polygon to calculate the area under the curve of a strictly non-negative function on a given interval [𝑎, 𝑏]. For this, obtain 𝑛 + 1 equidistant points in that interval ([𝑎, 𝑎 + (𝑏 − 𝑎) / 𝑛,…, 𝑏]) and with them obtain the coordinates of the vertices of the polygon that approximates the area under the curve, [𝑎, 0], [𝑎, 𝑓 (𝑎)], [𝑎 + (𝑏 − 𝑎) / 𝑛, 𝑓 (𝑎 + (𝑏 − 𝑎) / 𝑛)],…, [𝑏, 𝑓 (𝑏)] , [𝑏, 0] and finally calculates its area.
In this way:
Something like in the image, The red points are the subdivision of the inverval and the vertices of the polygon, the polygon is formed by the green lines and the function by the black curve.
I try with this, but i don´t know where is the error
area(f(x), a, b, n)
xs = a:(b-a)/n:b
deltas = diff(xs)
cs = xs[1:end-1]
sum(f(cs[i]) * deltas[i] for i in 1:length(deltas))