FAQ
overflow

Great Answers to
Questions About Everything

QUESTION

I am trying to graphically represent the error in a Riemann sum. My current code looks like:

    Show[DiscretePlot[Log[t], {t, 1, 10, 1}, ExtentSize -> Left, PlotMarkers -> "Point"], 
          Plot[Log[t], {t, 1, 10}]]

The output of the above code

I would know like to plot JUST the curve-linear triangles above the plot of ln(x) that represents the error in the Riemann Sum.

{ asked by Matthew Kemnetz }

ANSWER

If only visual matters - then use filling to mask everything under the curve:

Show[DiscretePlot[Log[t], {t, 1, 10, 1}, ExtentSize -> Left, PlotMarkers -> "Point"], 
 Plot[Log[t], {t, 1, 10}, Filling -> Bottom, FillingStyle -> White]]

enter image description here

You can also get crafty to show with color varying size of error triangles. And also give a vague opaque hint on underlying vertical rectangles - as their discreteness is the reason for error:

Show[
  DiscretePlot[Log[t], {t, 1, 10, 1}, ExtentSize -> Left, 
  ExtentMarkers -> {"Filled", "Empty"}, ColorFunction -> "Rainbow", 
  ExtentElementFunction -> "GlassRectangle"],

 Plot[Log[t], {t, 1, 10}, Filling -> Bottom, 
  FillingStyle -> Directive[White, Opacity[.8]]],

 DiscretePlot[Log[t], {t, 1, 10, 1}, 
  PlotStyle -> Directive[Dashed, Thick, Black]]  ]

enter image description here

{ answered by Vitaliy Kaurov }
Tweet