# Show the number of rectangles under a curve [duplicate]

I am trying to manipulate the number of rectangles under a given curve, so far I can show the size of each rectangle, but I am not sure how to tell the number of rectangles.

RiemannSum[f_] :=
Manipulate[
Show[
Plot[f, {x, 0, 20}, PlotStyle -> Thick, PlotLegends -> "Expressions"],
DiscretePlot[f, {x, 0, 20, sob}, ExtentSize -> type]
],
{type, {Full -> "Mid-Point", Left, Right}},
{{sob, 1, "size of blocks"}, 1, 0.1, Appearance -> "Labeled"}
]


Can someone give me a hint or suggestion to edit this to show the number of rectangles? Thanks

• There are a number of previous threads on depicting Riemann sums; you might want to search for them here. – J. M.'s technical difficulties Nov 23 '15 at 0:54
• Take a look at (87481), (82688), and other similar previous questions. – MarcoB Nov 23 '15 at 1:02
• On second thought, if all you want is simply the number of rectangles, you could use an Epilog e.g. in your Plot or DiscretePlot to add the number to the plot. – MarcoB Nov 23 '15 at 4:30

## 1 Answer

RiemannSum[f_] := Manipulate[
Show[
Plot[f
, {x, 0, 20}
, PlotStyle -> Thick
, PlotLegends -> "Expressions"
]
, DiscretePlot[f
, {x, 0, 20, sob}
, ExtentSize -> type
]
, PlotLabel -> Text[Round[20/sob]]
]
, {{type, Full}, {Full -> "Mid-Point", Left, Right}}
, {{sob, 1, "size of blocks"}, 1, 0.1, Appearance -> "Labeled"}]

RiemannSum[Sin[x]]