Re: How to draw a discontinuous function (set of points)
- To: mathgroup at smc.vnet.net
- Subject: [mg79351] Re: How to draw a discontinuous function (set of points)
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Wed, 25 Jul 2007 02:10:37 -0400 (EDT)
- References: <f84j0d$ova$1@smc.vnet.net>
Domnul Mihnea wrote: > Hello! > > I would like to draw the graph of the following function in Mathematica 6, f : Zn -> Zn, f(x) = x^2 (mod n), n given. I wanted to use the plot function (n being 1000) as in: > > Plot[Mod[x^2,1000], {x, 0, 999}, PlotStyle -> {Hue[.6], PointSize[0.01]}, AxesLabel -> {n, Mod[x^2,1000]}, TextStyle -> {FontFamily -> "Times", FontSize -> 14}] > > The problem is that Plot draws the graph for ALL the real points x between 0 and 999 (the interval [0,999]), when I would require the function to be applied just to the set natural numbers from 0 to 999 (the graph should be just a set of points). > > Thanks for reading my post! Any help would be more than welcome! > The easiest way to draw this graph is to use ListPlot applied to a table of values: ListPlot[Table[Mod[x^2,1000],{x,0,999}], PlotStyle->{Hue[.6],PointSize[0.01]}, AxesLabel->{n,Mod[x^2,1000]},TextStyle->{FontFamily->"Times",FontSize->14}] (BTW, this plot has a rather interesting appearance!) For more general functions that are defined over part of the range - such as Sqrt[Sin[x]], the RegionFunction option to Plot might be useful, but I doubt if this would work well in the case of isolated points. Interestingly, I notice that at 6.0 Plot[Sqrt[Sin[x]],{x,0,10}] works without error with nothing drawn where the answer would be imaginary. At 5.2 this does not happen. David Bailey http://www.dbaileyconsultancy.co.uk