Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

[no subject]

  • To: mathgroup at smc.vnet.net
  • From: Dr Bob <drbob at bigfoot.com>
  • Date: Fri, 24 Oct 2003 04:24:44 -0400 (EDT)
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Here's a simple answer (not necessarily the fastest):

overlapping[{a_, b_}, {c_, d_}] := Or[a == c, a < c < b, c < a < d]
Count[Flatten@Outer[overlapping, v1, v2, 1], True]

More efficient algorithms are possible if you can guarantee the bricks in 
each list are non-overlapping and exhaustive.

Bobby

recode procedural algorithm to faster functional module
Subject: [mg44158] [mg44097] [mg44079] [mg44034] recode procedural algorithm to faster functional module
From: "Prince-Wright, Robert G SEPCO" <robert.prince-wright at shell.com>
To: mathgroup at smc.vnet.net

Can someone please help me recode this Module so it is less procedural
and hopefully runs a lot faster. The Lists V1 and V2 represent two time
series with 'bricks' laid out along them. The Bricks have varying length
set by v[[i]][[1]] and v[[i]][[2]] and the idea is to count the number
of times there is an overlap. I can only see the dumb procedural way of
taking each brick and checking if it overlaps in time with another!



Concurrence[v1_List, v2_List,nsim_]:=Module [

{k=1,c=0},
Do[
Do[
Which[
v1[[i]][[1]] == v2[[k]][[1]], c=c+1,
v1[[i]][[1]] < v2[[k]][[1]] && v1[[i]][[2]] > v2[[k]][[1]], c=c+1,
v1[[i]][[1]] > v2[[k]][[1]] && v1[[i]][[1]] < v2[[k]][[2]], c=c+1
];
(*Write[ strm1, {v1[[i]][[1]],v2[[i]][[1]],c}];*)
, {i,1,nsim}
], {k,1,nsim}
];
c
]

I've have a PowerPoint illustration if this is unclear and can e-mail it.

thanks
Robert Prince-Wright


  • Prev by Date: Re: Why is this replacement not performed the first time?
  • Next by Date: Re: Integrating over area of intersection
  • Previous by thread: Re: ProductLog[-Pi/2]
  • Next by thread: errors while picking random numbers under constraint and in loop also