[Date Index]
[Thread Index]
[Author Index]
Re: Number of interval Intersections for a large number of intervals
*To*: mathgroup at smc.vnet.net
*Subject*: [mg81718] Re: [mg81679] Number of interval Intersections for a large number of intervals
*From*: DrMajorBob <drmajorbob at bigfoot.com>
*Date*: Tue, 2 Oct 2007 05:36:10 -0400 (EDT)
*References*: <4236415.1191246194428.JavaMail.root@m35>
*Reply-to*: drmajorbob at bigfoot.com
[WRI: there's a Plot/Piecewise insect (bug?) noted below.]
I'm having to guess a bit, but maybe this is what you mean:
intervals = Sort /@ RandomReal[{-1, 1}, {10^5, 2}];
trans = Transpose@intervals;
{{min, maxLow}, {minHigh, max}} = Through[{Min, Max}@#] & /@ trans;
{low, high} =
Interpolation[Transpose@{Sort@#, -1 + Range@Length@#},
InterpolationOrder -> 0] & /@ trans;
Clear[count]
count[x_] /; x < min = 0;
count[x_] /; x > max = 0;
count[x_] /; x < minHigh := low[x]
count[x_] /; x > maxLow := low[maxLow] - high[x]
count[x_] := low[x] - high[x];
First@Timing@Plot[count@x, {x, -1, 1}]
0.031
or
Clear[count2]
count2[x_] =
Piecewise[{{0, x < min}, {low[x], x < minHigh}, {low[x] - high[x],
x <= maxLow}, {low[maxLow] - high[x], x <= max}}];
First@Timing@Plot[count2@x, {x, -1, 1}]
0.047
INSECT report: If I use a small number of Intervals -- 10, say -- the two
plots are different. The Piecewise version doesn't have "returns" at some
of the discontinuities, even though the following plots the zero function
as expected:
Plot[count2@x - count@x, {x, -1, 1}]
Is this an example of Exclusions->Automatic at work?
If so, why aren't all the returns omitted?
Bobby
On Mon, 01 Oct 2007 03:50:26 -0500, P_ter <peter_van_summeren at yahoo.co.uk>
wrote:
> Hello,
> I have as example on the interval [0.0,12000.0] thousands of smaller
> intervals which overlap. I construct for each interval a UnitStep up and
> one down(a block). I order and sum them and I give it to Reduce with the
> question Reduce[SumOfAllBlocks[x]==<number>,x]. The result gives me the
> overlapping intervals which overlap <number>. From the result I take
> out the length of the overlaps and Tally them. It is safe, but slow.
> Does anyone know something about this type of problems? With better
> algorithms?
>
>
--
DrMajorBob at bigfoot.com
Prev by Date:
**Re: Flat colour in RegionPlot; millions of little triangles**
Next by Date:
**Re: Re: 3D graphics resize unintentionally when rotated**
Previous by thread:
**Re: Number of interval Intersections for a large number of intervals**
Next by thread:
**Re: Re: Number of interval Intersections for a large number of intervals**
| |