MathGroup Archive 1999

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

Search the Archive

Re: Position of Sign change in long list

  • To: mathgroup at
  • Subject: [mg18729] Re: Position of Sign change in long list
  • From: "David Keith" <dkeith at>
  • Date: Sat, 17 Jul 1999 02:36:46 -0400
  • Organization: Hevanet Communications
  • References: <7mjvfd$>
  • Sender: owner-wri-mathgroup at

Hi Martin,

Here is one possibility:

Since it uses Sign[], there are 3 flavors of sign: negative, zero, and
positive. That could be fixed by inserting, for example, /.0->1 in the right
spot. It checks a list of signs against such a list displaced by 1 for
inequality, and so returns the first location where an element's sign
disagrees with the sign of the element to its left. If none, it returns an
error and a null list.


PS. Did you have a famous grandfather?

signChangePosition[d_] := Module[{s = Sign /@ d},
          Position[MapThread[#1 == #2 &, {Drop[s, 1], Drop[s, -1]}],
            False]][[1]] + 1]

Martin Rommel wrote in message <7mjvfd$foi at>...
>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}];
>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:
>If you can think of a still faster or more elegant solution please let me

  • Prev by Date: How can I plot the region satisfying an inequality?
  • Next by Date: Re: Rudimentary Spell Checker
  • Previous by thread: Re: Position of Sign change in long list
  • Next by thread: V4.0 Compatibility (Financial Derivatives book)