MathGroup Archive 2002

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

Search the Archive

friendly challenge 3

  • To: mathgroup at
  • Subject: [mg35076] friendly challenge 3
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Mon, 24 Jun 2002 03:21:01 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

While the season for "friendly challenges" lasts, here is something that 
has just come up in my own work. Let's define the signature of a 
symmetric matrix as the number of positive eigenvalues - the number of 
negative ones. I need an efficient function to compute this.
There is the obvious and rather pedestrian one:

sign2[M_?MatrixQ] :=
   Count[Eigenvalues[M], _?(# > 0 &)] - Count[Eigenvalues[M], _?(# < 0 &)]

For example, let's construct a symmetric matrix of random integers (all 
matrices I am considering have integer entries):

m = Table[Random[Integer, {1, 9}], {30}, {30}]; n = m + Transpose[m];

the above sign2 gives:


{3.5 Second,0}

My best function, sign1 gives (on 400 mghz PowerBOok G4)


{1.44 Second,0}

Nearly two and a half times as fast. Can anyone do better?


  • Prev by Date: Problem with entering text into a mathematica notebook by VB or QuicKeys
  • Next by Date: Strange thing with exporting to PDF.
  • Previous by thread: Re: FrameTick Problem
  • Next by thread: Re: friendly challenge 3