Re: DiscretePlot

*To*: mathgroup at smc.vnet.net*Subject*: [mg96758] Re: [mg96697] DiscretePlot*From*: Chris Pemberton <cjpembo at gmail.com>*Date*: Tue, 24 Feb 2009 05:44:52 -0500 (EST)*References*: <200902220038.TAA08394@smc.vnet.net>

Helen Read wrote: > I recently started the chapter on series in my Calculus II classes. I > like to have my students make tables and plots of terms and partial sums > of series, to help them develop some intuition about what it means for a > series to converge or diverge, which leads naturally into convergence > tests. (Give them something where it's hard to determine > convergence/divergence from tables and plots, and the students will > *ask* how can we know for sure.) Prior to Mathematica 7, we always had > to start with a table, name it something, and use ListPlot to plot it. > So now with Mathematica 7, I still have my students make some smallish > tables (I like them to have numbers to look at it in addition to plots), > but now we can plot directly with the new DiscretePlot. I like > DiscretePlot a lot, except for one complaint I will get to below. > > As an example, consider the alternating harmonic series. My students > know how to define a function for the terms and a function to generate > the partial sums, then plot the terms or the partial sums with > DiscretePlot, like so. > > a[n_] = (-1)^(n + 1)/n > > s[k_] := Sum[a[n], {n, 1, k}] > > DiscretePlot[s[k], {k, 1, 100},PlotLabel->"Partial sums"] > > We can turn off the filling. (I like the filling sometimes, but not always.) > > DiscretePlot[s[k], {k, 1, 100}, Filling -> None] > > All well and good. > > However, unlike ListPlot (which has Joined->False by default), > DiscretePlot has Joined->Automatic by default. If we plot greater than > 149 points with DiscretePlot, Mathematica joins the points, and it's a > royal mess. > > DiscretePlot[s[k], {k, 1, 149}, Filling -> None] (* this is fine *) > > > DiscretePlot[s[k], {k, 1, 150}, Filling -> None] (* this is a wreck *) > > As another example, try using DiscretePlot to plot terms of the sequence > b(n)=sin(n). > > b[n_] = Sin[n]; > DiscretePlot[b[n], {n, 0, 500}, Filling -> None] > > Well that's just hideous. Students just learning about sequences and > series aren't going to have any idea what's going on. > > We can fix this behavior by setting Joined->False, like this: > > DiscretePlot[s[k], {k, 1, 150}, Filling -> None, Joined -> False] > > DiscretePlot[b[n], {n, 0, 500}, Filling -> None, Joined -> False] > > The students are having trouble remembering to do this, though, and I > wonder why on earth Wolfram would design DiscretePlot this way. When I > go to make a DiscretePlot, I do not *ever* expect -- or want -- the > points to be joined. And why are the points not joined for < 150 points, > and joined for >= 150 points? This seems completely arbitrary, and in > fact I only discovered the 150 point cut-off by trial and error, and > could find no explanation in the Documention as to what > Joined->Automatic even does. > > I'd be far happier if DiscretePlot had Joined->False by default. > > -- > Helen Read > University of Vermont > > > > I do not know why the error occurs, but I think I know how the error occurs: If you save your notebook and open it in a text editor, you will see that the correctly generated graphics use "PointBox[CompressedData[....." and the incorrect graphics use "LineBox[CompressedData[...". In fact, you can edit the notebook in a text editor, changing LineBox to PointBox, and reopen it in Mathematica and the error is mostly eliminated. Your guess is as good as mine as to why PointBox changes to LineBox when plotting more than 150 points. The DiscretePlot function seems to be implemented in a binary file called DiscretePlots.mx and as such you'll have to rely on Wolfram for a fix. Chris

**References**:**DiscretePlot***From:*Helen Read <hpr@together.net>