MathGroup Archive 1999

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

Search the Archive

Re: Position of Sign change in long list


Try this :

Timing at Catch@Module[{i,s=0},
s=Sign at First@test;
Scan[(++i,If[Sign at #!=s,Throw at i])&,test]]

Hope this helps,

jmt

On Thu, 15 Jul 1999, Martin Rommel wrote:
> I have a long list of data points and need to find the position where the
> sign changes for the first time.
> My first attempt was
> 
> test=Table[Sin[Pi i/5000. +1],{i,10000}];
> 
> With[{a=Abs[test]},Position[a,Min[a]]]
> 
> which works, but is slow. It turns out that Min is relatively slow and
> avoiding it can save time. The following is almost a factor 4 faster:
> 
> With[{st=Sign[test]},Length[Split[st][[1]]]]
> 
> If you can think of a still faster or more elegant solution please let me
> know!
> 
> Martin


  • Prev by Date: Re: Rudimentary Spell Checker
  • Next by Date: Re: data acquisition system with mathematica 3.0
  • Previous by thread: Position of Sign change in long list
  • Next by thread: Re: Position of Sign change in long list