MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Random offsets in Plot &aliasing

  • To: mathgroup at
  • Subject: [mg8045] Random offsets in Plot &aliasing
  • From: Allan Hayes <hay at>
  • Date: Sat, 2 Aug 1997 22:32:53 -0400
  • Sender: owner-wri-mathgroup at

 Paul Abbott <paul at>
 in [mg7995] Re: Minima

 Gives the following function for finding all roots in an interval


 RootsInRange[d_, {l_, lmin_, lmax_},
   opts___] := Module[{s, p, x,
    f = Function[l, Evaluate[d]]},
   s = Plot[f[l], {l, lmin, lmax},
      Compiled -> False, Evaluate[FilterOptions[Plot, opts]]];
    p = Cases[s, Line[{x__}] -> x, Infinity];
    p = Map[First, Select[Split[p,
        Sign[Last[#2]] == -Sign[Last[#1]] & ], Length[#1] == 2 & ]
Since the initial number of sample points for Plot is 25 it looks  
as if this should fail for

RootsInRange[x, {x, -12, 12}]

since we would expect that the first p would be something like
and the second p would therefor be { }.

But this is not so.
This is because a new feature of 3.0 is that a small random offsets  
are given to the sample points. We can look at the actual sample  
points, sp, use as follows

sp = {}; Plot[AppendTo[sp, x]; x, {x, -12, 12}];



The distances between successive sample points are

-Partition[sp, 2, 1, Subtract]


 The reason for this is to avoid *aliasing*
 For example, without it

 Plot[Sin[24 x], {x,0,Pi}]

would be along the x-axis, since Sin would be zero at every sample  

Table[Sin[24 x], {x,0,Pi, Pi/24}]

The same technique seems to be used with ParametricPlot - maybe  
also with other plotting functions.

Allan Hayes
hay at
voice:+44 (0)116 2714198
fax: +44 (0)116 2718642
Leicester, UK

  • Prev by Date: two y-axes in one plot
  • Next by Date: display pixel value with ListDensityPlot
  • Previous by thread: Re: Re: two y-axes in one plot
  • Next by thread: display pixel value with ListDensityPlot