1
$\begingroup$

This question already has an answer here:

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

$\endgroup$

marked as duplicate by J. M. is away Aug 1 at 13:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ There are a number of previous threads on depicting Riemann sums; you might want to search for them here. $\endgroup$ – J. M. is away Nov 23 '15 at 0:54
  • $\begingroup$ Take a look at (87481), (82688), and other similar previous questions. $\endgroup$ – MarcoB Nov 23 '15 at 1:02
  • $\begingroup$ 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. $\endgroup$ – MarcoB Nov 23 '15 at 4:30
1
$\begingroup$
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]]

Mathematica graphics

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.