Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!qt.cs.utexas.edu!yale.edu!jvnc.net!darwin.sura.net!haven.umd.edu!socrates!socrates!rockwell
From: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Subject: Re: Eigen in J?
In-Reply-To: qmdbms@gsusgi2.gsu.edu's message of Mon, 2 Mar 1992 13:33:56 GMT
Message-ID: <ROCKWELL.92Mar4011936@socrates.umd.edu>
Sender: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Organization: Traveller
References: <qmdbms.699543236@gsusgi1.gsu.edu>
Date: Wed, 4 Mar 1992 06:19:36 GMT
Lines: 77

Brian Schott:
   Or does anyone want to take on a translation?

Sure, why not.  It's been a while since I've studied linear algebra,
so I don't have a real good feel for this kind of math, but bear with
me... 

       $ z #is eigen a
    [1]   z #is eigvect a
    [2]   z #is z,[1]a eigval z     $  

eigen =. eigvect , (eigval eigvect)             NB. "quicky" translation
eigen =. [ (] , (eigval ])) eigvect             NB. "efficient" translation

       $ l #is a eigval q
    [1]   l #is 1 1 #transpose(#transpose q)+#inner #x a+#inner #x q     $  

dot=. +/ .*
eigval =. (<0 1)&|: @(|: @[   dot   [   dot   ])

       $ y #is eigvect a;n;q;r;i;z;p;eps
    [1]   y #is ident n #is #rho a[1;]
    [2]   eps #is n #x n #x 1E"12 #x+/#magnitude 1 1 #transpose a
    [3]  qr:q #is ident i #is n
    [4]   r #is a
    [5]  again:z #is ident n
    [6]   z[p;p #is(-i)#take #iota n]#is house i #rho r[((n-i)+#iota i);1+n-i]
    [7]   q #is q+#inner #x z
    [8]   r #is z+#inner #x r
    [9]   #goto again #x #iota 1<i #is i-1
    [10]  a #is r+#inner #x q
    [11]  y #is y+#inner #x q
    [12]  #goto qr #x #iota eps<(+/,a*2)-+/(1 1 #transpose a)*2
    [13]  y #is y[;p #is #downgrade 1 1 #transpose a]     $  

t=.0 0$''                                         NB. literal translation
t=.t,  'y=. ident  n=. # {. a=. y.'               NB. try and use same names
t=.t,  ' eps=. n * n * 1e_12 * +/ | (<0 1)|: a'
t=.t,  'qr)  q=. ident  i=. n'
t=.t,  ' r=. a'
t=.t,  'again)  z=. ident n'
t=.t,  ' z=. z (n #.&> {;~ (-i){. i. n) }~ house i $ r {~ {((n-i)+i. i); n-i'
t=.t,  ' q=. q dot z'
t=.t,  ' r=. z dot r'
t=.t,  '$.=. $. ]^:(1< i=.i-1) again'
t=.t,  ' a=. r dot q'
t=.t,  ' y=. y dot q'
t=.t,  '$.=. $. ]^:(eps < (+/,a^2)-+/((<0 1)|: a)^2) qr'
t=.t,  ' y=. y {"1~ \: (<0 1)|: a'
eigvect=. t : ''

       $ z #is house v;i
    [1]   i #is #rho v
    [2]   v #is v-(((+/v*2)*0.5),(i-1)#rho 0)
    [3]   z #is(ident i)-2 #x v #outer #x v%+/v*2     $  

house=. # (ident@[ - 2&*@] */ ] % +/@(^&2)@]) (] - # {. +/&.(^&2))

       $ z #is ident n
    [1]   z #is(n,n)#rho(1,n #rho 0)     $  

ident =. = @i.

I've tried to be as close to the original form as I can tolerate.

As a quick test:

   eigen 2 2 $ 1 2 2 3
0.525731 _0.850651
0.850651  0.525731
 9.43386 0.0292987

That look right?  [Ok, so I'm too sleepy to be thinking about
polynomials...]

-- 
Raul Deluth Miller-Rockwell                   <rockwell@socrates.umd.edu>
