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

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

Search the Archive

Position of Sign change in long list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18691] Position of Sign change in long list
  • From: "Martin Rommel" <rommel at semitest.com>
  • Date: Thu, 15 Jul 1999 01:46:07 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

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: Q: EPS fontsize
  • Next by Date: V4.0 Compatibility (Financial Derivatives book)
  • Previous by thread: Q: EPS fontsize
  • Next by thread: Re: Position of Sign change in long list