Random offsets in Plot &aliasing

• To: mathgroup at smc.vnet.net
• Subject: [mg8045] Random offsets in Plot &aliasing
• From: Allan Hayes <hay at haystack.demon.co.uk>
• Date: Sat, 2 Aug 1997 22:32:53 -0400
• Sender: owner-wri-mathgroup at wolfram.com

``` Paul Abbott <paul at physics.uwa.edu.au>
in [mg7995] Re: Minima

Gives the following function for finding all roots in an interval

Needs["Utilities`FilterOptions`"]

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
{{-12,-12},.....,{-1,-1},{0,0},{1,1},.....{12,12}}
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}];

sp

{-12.,-11.0264,-9.96459,-8.96738,-8.00836,-6.98754,-6.00491,-4.96049,-3.95426,-2.98622,-1.95638,-0.964744,-0.0112999,1.00395,1.981,3.01985,4.02051,4.98297,6.00724,6.9933,8.04118,9.05085,10.0223,11.0556,12.}

The distances between successive sample points are

-Partition[sp, 2, 1, Subtract]

{0.973607,1.0618,0.997214,0.959017,1.02082,0.982624,1.04443,1.00623,0.968034,1.02984,0.991641,0.953444,1.01525,0.977051,1.03885,1.00066,0.962461,1.02426,0.986068,1.04787,1.00967,0.971478,1.03328,0.944389}

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
point.Compare:

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

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

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/
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