Services & Resources / Wolfram Forums
MathGroup Archive
*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

recode procedural algorithm to faster functional module

  • To: mathgroup at
  • Subject: [mg44034] recode procedural algorithm to faster functional module
  • From: "Prince-Wright, Robert G SEPCO" <robert.prince-wright at>
  • Date: Sat, 18 Oct 2003 03:12:35 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

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 [

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}

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

Robert Prince-Wright

  • Prev by Date: Re: Bug in ReplaceAll and ReplaceRepeated?
  • Next by Date: Can someone tell me why NDsolve isn't working here?
  • Previous by thread: Re: two's complement function
  • Next by thread: Re: recode procedural algorithm to faster functional module