1
$\begingroup$

I was doing an assignment for a class in which I have to do an animation of the Riemann sum and how the area changes as the rectangles divide. So far I have the following but there is a problem with the graphs, as stated in the title I cant get the rectangles to show inside the graph.

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ You need to put the Show inside the Animate. Also it's good practice to post code not pictures. Use the formatting buttons inside the "Ask a Question" pane. $\endgroup$
    – b3m2a1
    Nov 10, 2017 at 21:57
  • $\begingroup$ Thank you very much! Also sorry for the image :( this is the first time I post but its a good thing that I now know about it! $\endgroup$
    – esteban
    Nov 10, 2017 at 22:08
  • $\begingroup$ Have you seen this thread? $\endgroup$ Nov 11, 2017 at 1:29

1 Answer 1

1
$\begingroup$
f[x_] := x^2;

a = -3;
b = 6;

m[n_] := (b - a)/n;

R[r_] := Table[
    {Opacity[0.2], FaceForm[Black], 
      Rectangle[{a + (m[r]*(i - 1)), 0}, {a + (m[r]*(i)), f[a + (m[r]*(i))]}]}
    , {i, r}
  ]

Animate[
 Show[{Plot[f[x], {x, -3, 6}], Graphics[R[c]]}, PlotRange -> All]
 , {c, 1, 100}, AnimationRunning -> False]

enter image description here

$\endgroup$

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