This question is related to Graphically approximating the area under a curve as a sum of rectangular regions.
I now was trying to adapt the code by MarcoB to get the approximation of the integral by trapezoids, and I used the function Line
. I only need to color the trapezoids now. Is it possible to adapt the following code to do that?
Thank you
f[x_] = Sin[x]
Manipulate[
lines = Table[ {Blue,
Line[{{a + i (b - a)/n,
f[a + i (b - a)/n]}, {a + (i + 1) (b - a)/n,
f[a + (i + 1) (b - a)/n]}}] }, {i, 0, n - 1, 1}];
Show[{Plot[f[x], {x, a, b}, PlotStyle -> {Red, Thick},
AxesOrigin -> {0, 0}], Graphics[{Thick, lines}]},
ImageSize -> Large],
{{a, 0}, -10, 10},
{{b, 6}, -10, 10},
{{n, 15} , 1, 40, 1}
]